LCOV - code coverage report
Current view: top level - src/test/util - str.h (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 20 20 100.0 %
Date: 2022-04-21 14:51:19 Functions: 9 9 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 102 108 94.4 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2019 The Bitcoin Core developers
#       2                 :            : // Distributed under the MIT software license, see the accompanying
#       3                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#       4                 :            : 
#       5                 :            : #ifndef BITCOIN_TEST_UTIL_STR_H
#       6                 :            : #define BITCOIN_TEST_UTIL_STR_H
#       7                 :            : 
#       8                 :            : #include <string>
#       9                 :            : 
#      10                 :            : bool CaseInsensitiveEqual(const std::string& s1, const std::string& s2);
#      11                 :            : 
#      12                 :            : /**
#      13                 :            :  * Increment a string. Useful to enumerate all fixed length strings with
#      14                 :            :  * characters in [min_char, max_char].
#      15                 :            :  */
#      16                 :            : template <typename CharType, size_t StringLength>
#      17                 :            : bool NextString(CharType (&string)[StringLength], CharType min_char, CharType max_char)
#      18                 :       5708 : {
#      19 [ +  + ][ +  + ]:       7008 :     for (CharType& elem : string) {
#                 [ +  + ]
#      20                 :       7008 :         bool has_next = elem != max_char;
#      21 [ +  + ][ +  + ]:       7008 :         elem = elem < min_char || elem >= max_char ? min_char : CharType(elem + 1);
#         [ +  + ][ +  + ]
#         [ +  + ][ +  + ]
#      22 [ +  + ][ +  + ]:       7008 :         if (has_next) return true;
#                 [ +  + ]
#      23                 :       7008 :     }
#      24                 :        108 :     return false;
#      25                 :       5708 : }
#      26                 :            : 
#      27                 :            : /**
#      28                 :            :  * Iterate over string values and call function for each string without
#      29                 :            :  * successive duplicate characters.
#      30                 :            :  */
#      31                 :            : template <typename CharType, size_t StringLength, typename Fn>
#      32                 :        108 : void ForEachNoDup(CharType (&string)[StringLength], CharType min_char, CharType max_char, Fn&& fn) {
#      33 [ +  + ][ +  + ]:       5816 :     for (bool has_next = true; has_next; has_next = NextString(string, min_char, max_char)) {
#         [ +  + ][ +  + ]
#         [ +  + ][ +  + ]
#      34                 :       5708 :         int prev = -1;
#      35                 :       5708 :         bool skip_string = false;
#      36 [ +  + ][ +  + ]:      13012 :         for (CharType c : string) {
#         [ +  + ][ +  + ]
#         [ +  + ][ +  + ]
#      37 [ +  + ][ +  + ]:      13012 :             if (c == prev) skip_string = true;
#         [ +  + ][ +  + ]
#         [ +  + ][ +  + ]
#      38 [ +  + ][ +  + ]:      13012 :             if (skip_string || c < min_char || c > max_char) break;
#         [ +  + ][ +  + ]
#         [ +  + ][ +  + ]
#         [ +  + ][ +  + ]
#         [ +  + ][ +  + ]
#         [ +  + ][ +  + ]
#         [ -  + ][ -  + ]
#         [ -  + ][ -  + ]
#         [ -  + ][ -  + ]
#      39                 :      10600 :             prev = c;
#      40                 :      10600 :         }
#      41 [ +  + ][ +  + ]:       5708 :         if (!skip_string) fn();
#         [ +  + ][ +  + ]
#         [ +  + ][ +  + ]
#      42                 :       5708 :     }
#      43                 :        108 : }
#      44                 :            : 
#      45                 :            : #endif // BITCOIN_TEST_UTIL_STR_H

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a