diff options
author | Samuel Dobson <dobsonsa68@gmail.com> | 2021-11-23 17:33:46 +1300 |
---|---|---|
committer | Samuel Dobson <dobsonsa68@gmail.com> | 2021-12-01 11:01:20 +1300 |
commit | 2fa4fd196176160a5ad0a25da173ff93252b8103 (patch) | |
tree | 0cac8aff9473c95e375c66d72050c5076f262965 /src | |
parent | 405c96fc9fd909ccc461f10d55dfdd822b76f5bf (diff) | |
download | bitcoin-2fa4fd196176160a5ad0a25da173ff93252b8103.tar.xz |
Use std::iota instead of manually pushing range
Diffstat (limited to 'src')
-rw-r--r-- | src/bech32.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/bech32.cpp b/src/bech32.cpp index 484586cfa5..119be74b57 100644 --- a/src/bech32.cpp +++ b/src/bech32.cpp @@ -6,9 +6,10 @@ #include <bech32.h> #include <util/vector.h> +#include <array> #include <assert.h> +#include <numeric> #include <optional> -#include <array> namespace bech32 { @@ -282,13 +283,6 @@ inline unsigned char LowerCase(unsigned char c) return (c >= 'A' && c <= 'Z') ? (c - 'A') + 'a' : c; } -void push_range(int from, int to, std::vector<int>& vec) -{ - for (int i = from; i < to; i++) { - vec.push_back(i); - } -} - /** Return indices of invalid characters in a Bech32 string. */ bool CheckCharacters(const std::string& str, std::vector<int>& errors) { bool lower = false, upper = false; @@ -404,7 +398,8 @@ DecodeResult Decode(const std::string& str) { /** Find index of an incorrect character in a Bech32 string. */ std::string LocateErrors(const std::string& str, std::vector<int>& error_locations) { if (str.size() > 90) { - push_range(90, str.size(), error_locations); + error_locations.resize(str.size() - 90); + std::iota(error_locations.begin(), error_locations.end(), 90); return "Bech32 string too long"; } if (!CheckCharacters(str, error_locations)){ |