Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2019-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_TEST_UTIL_STR_H6#define BITCOIN_TEST_UTIL_STR_H8#include <string>10/**11* Increment a string. Useful to enumerate all fixed length strings with12* characters in [min_char, max_char].13*/14template <typename CharType, size_t StringLength>15bool NextString(CharType (&string)[StringLength], CharType min_char, CharType max_char)16{17for (CharType& elem : string) {18bool has_next = elem != max_char;19elem = elem < min_char || elem >= max_char ? min_char : CharType(elem + 1);20if (has_next) return true;21}22return false;23}25/**26* Iterate over string values and call function for each string without27* successive duplicate characters.28*/29template <typename CharType, size_t StringLength, typename Fn>30void ForEachNoDup(CharType (&string)[StringLength], CharType min_char, CharType max_char, Fn&& fn) {31for (bool has_next = true; has_next; has_next = NextString(string, min_char, max_char)) {32int prev = -1;33bool skip_string = false;34for (CharType c : string) {35if (c == prev) skip_string = true;36if (skip_string || c < min_char || c > max_char) break;37prev = c;38}39if (!skip_string) fn();40}41}43#endif // BITCOIN_TEST_UTIL_STR_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.