MCPcopy Create free account
hub / github.com/ElementsProject/elements / CheckCharacters

Function CheckCharacters

src/bech32.cpp:284–306  ·  view source on GitHub ↗

Return indices of invalid characters in a Bech32 string. */

Source from the content-addressed store, hash-verified

282
283/** Return indices of invalid characters in a Bech32 string. */
284bool CheckCharacters(const std::string& str, std::vector<int>& errors)
285{
286 bool lower = false, upper = false;
287 for (size_t i = 0; i < str.size(); ++i) {
288 unsigned char c{(unsigned char)(str[i])};
289 if (c >= 'a' && c <= 'z') {
290 if (upper) {
291 errors.push_back(i);
292 } else {
293 lower = true;
294 }
295 } else if (c >= 'A' && c <= 'Z') {
296 if (lower) {
297 errors.push_back(i);
298 } else {
299 upper = true;
300 }
301 } else if (c < 33 || c > 126) {
302 errors.push_back(i);
303 }
304 }
305 return errors.empty();
306}
307
308/** Expand a HRP for use in checksum computation. */
309data ExpandHRP(const std::string& hrp)

Callers 2

DecodeFunction · 0.85
LocateErrorsFunction · 0.85

Calls 3

sizeMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected