LCOV - code coverage report
Current view: top level - src/util - spanparsing.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 45 45 100.0 %
Date: 2022-04-21 14:51:19 Functions: 4 4 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: 35 36 97.2 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2018-2021 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                 :            : #include <util/spanparsing.h>
#       6                 :            : 
#       7                 :            : #include <span.h>
#       8                 :            : 
#       9                 :            : #include <string>
#      10                 :            : #include <vector>
#      11                 :            : 
#      12                 :            : namespace spanparsing {
#      13                 :            : 
#      14                 :            : bool Const(const std::string& str, Span<const char>& sp)
#      15                 :      30538 : {
#      16 [ +  + ][ +  + ]:      30538 :     if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
#      17                 :      23650 :         sp = sp.subspan(str.size());
#      18                 :      23650 :         return true;
#      19                 :      23650 :     }
#      20                 :       6888 :     return false;
#      21                 :      30538 : }
#      22                 :            : 
#      23                 :            : bool Func(const std::string& str, Span<const char>& sp)
#      24                 :      62934 : {
#      25 [ +  + ][ +  + ]:      62934 :     if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
#         [ +  - ][ +  + ]
#      26                 :       6422 :         sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
#      27                 :       6422 :         return true;
#      28                 :       6422 :     }
#      29                 :      56512 :     return false;
#      30                 :      62934 : }
#      31                 :            : 
#      32                 :            : Span<const char> Expr(Span<const char>& sp)
#      33                 :      29956 : {
#      34                 :      29956 :     int level = 0;
#      35                 :      29956 :     auto it = sp.begin();
#      36         [ +  + ]:    6629242 :     while (it != sp.end()) {
#      37 [ +  + ][ +  + ]:    6621568 :         if (*it == '(' || *it == '{') {
#      38                 :       9717 :             ++level;
#      39 [ +  + ][ +  + ]:    6611851 :         } else if (level && (*it == ')' || *it == '}')) {
#                 [ +  + ]
#      40                 :       9717 :             --level;
#      41 [ +  + ][ +  + ]:    6602134 :         } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
#         [ +  + ][ +  + ]
#      42                 :      22282 :             break;
#      43                 :      22282 :         }
#      44                 :    6599286 :         ++it;
#      45                 :    6599286 :     }
#      46                 :      29956 :     Span<const char> ret = sp.first(it - sp.begin());
#      47                 :      29956 :     sp = sp.subspan(it - sp.begin());
#      48                 :      29956 :     return ret;
#      49                 :      29956 : }
#      50                 :            : 
#      51                 :            : std::vector<Span<const char>> Split(const Span<const char>& sp, char sep)
#      52                 :      60992 : {
#      53                 :      60992 :     std::vector<Span<const char>> ret;
#      54                 :      60992 :     auto it = sp.begin();
#      55                 :      60992 :     auto start = it;
#      56         [ +  + ]:    6272764 :     while (it != sp.end()) {
#      57         [ +  + ]:    6211772 :         if (*it == sep) {
#      58                 :      23542 :             ret.emplace_back(start, it);
#      59                 :      23542 :             start = it + 1;
#      60                 :      23542 :         }
#      61                 :    6211772 :         ++it;
#      62                 :    6211772 :     }
#      63                 :      60992 :     ret.emplace_back(start, it);
#      64                 :      60992 :     return ret;
#      65                 :      60992 : }
#      66                 :            : 
#      67                 :            : } // namespace spanparsing

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