Changeset View
Changeset View
Standalone View
Standalone View
src/util/strencodings.cpp
Show First 20 Lines • Show All 408 Lines • ▼ Show 20 Lines | while (1) { | ||||
case 7: // we have 3 bits, and keep 0 | case 7: // we have 3 bits, and keep 0 | ||||
vchRet.push_back((left << 5) | dec); | vchRet.push_back((left << 5) | dec); | ||||
mode = 0; | mode = 0; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (pfInvalid) switch (mode) { | if (pfInvalid) { | ||||
switch (mode) { | |||||
case 0: // 8n base32 characters processed: ok | case 0: // 8n base32 characters processed: ok | ||||
break; | break; | ||||
case 1: // 8n+1 base32 characters processed: impossible | case 1: // 8n+1 base32 characters processed: impossible | ||||
case 3: // +3 | case 3: // +3 | ||||
case 6: // +6 | case 6: // +6 | ||||
*pfInvalid = true; | *pfInvalid = true; | ||||
break; | break; | ||||
Show All 22 Lines | if (pfInvalid) { | ||||
case 7: // 8n+7 base32 characters processed: require '=' | case 7: // 8n+7 base32 characters processed: require '=' | ||||
if (left || p[0] != '=' || | if (left || p[0] != '=' || | ||||
decode32_table[(uint8_t)p[1]] != -1) { | decode32_table[(uint8_t)p[1]] != -1) { | ||||
*pfInvalid = true; | *pfInvalid = true; | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
} | |||||
return vchRet; | return vchRet; | ||||
} | } | ||||
std::string DecodeBase32(const std::string &str) { | std::string DecodeBase32(const std::string &str) { | ||||
std::vector<uint8_t> vchRet = DecodeBase32(str.c_str()); | std::vector<uint8_t> vchRet = DecodeBase32(str.c_str()); | ||||
return std::string((const char *)vchRet.data(), vchRet.size()); | return std::string((const char *)vchRet.data(), vchRet.size()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 380 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void Downcase(std::string &str) { | void Downcase(std::string &str) { | ||||
std::transform(str.begin(), str.end(), str.begin(), | std::transform(str.begin(), str.end(), str.begin(), | ||||
[](uint8_t c) { return ToLower(c); }); | [](uint8_t c) { return ToLower(c); }); | ||||
} | } | ||||
std::string Capitalize(std::string str) { | std::string Capitalize(std::string str) { | ||||
if (str.empty()) return str; | if (str.empty()) { | ||||
return str; | |||||
} | |||||
str[0] = ToUpper(str.front()); | str[0] = ToUpper(str.front()); | ||||
return str; | return str; | ||||
} | } |