LCOV - code coverage report
Current view: top level - src/util - spanparsing.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 19 26 73.1 %
Date: 2023-11-10 23:46:46 Functions: 2 3 66.7 %
Branches: 21 32 65.6 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2018-2022 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 <algorithm>
      10                 :            : #include <cstddef>
      11                 :            : #include <string>
      12                 :            : 
      13                 :            : namespace spanparsing {
      14                 :            : 
      15                 :          0 : bool Const(const std::string& str, Span<const char>& sp)
      16                 :            : {
      17 [ #  # ][ #  # ]:          0 :     if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
      18                 :          0 :         sp = sp.subspan(str.size());
      19                 :          0 :         return true;
      20                 :            :     }
      21                 :          0 :     return false;
      22                 :          0 : }
      23                 :            : 
      24                 :        106 : bool Func(const std::string& str, Span<const char>& sp)
      25                 :            : {
      26 [ +  - ][ +  + ]:        106 :     if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
         [ +  - ][ +  + ]
      27                 :         11 :         sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
      28                 :         11 :         return true;
      29                 :            :     }
      30                 :         95 :     return false;
      31                 :        106 : }
      32                 :            : 
      33                 :         13 : Span<const char> Expr(Span<const char>& sp)
      34                 :            : {
      35                 :         13 :     int level = 0;
      36                 :         13 :     auto it = sp.begin();
      37         [ +  + ]:       1634 :     while (it != sp.end()) {
      38 [ +  + ][ -  + ]:       1621 :         if (*it == '(' || *it == '{') {
      39                 :         13 :             ++level;
      40 [ +  + ][ +  + ]:       1621 :         } else if (level && (*it == ')' || *it == '}')) {
                 [ -  + ]
      41                 :         13 :             --level;
      42 [ +  + ][ +  - ]:       1608 :         } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
         [ +  - ][ +  - ]
      43                 :          0 :             break;
      44                 :            :         }
      45                 :       1621 :         ++it;
      46                 :            :     }
      47                 :         13 :     Span<const char> ret = sp.first(it - sp.begin());
      48                 :         13 :     sp = sp.subspan(it - sp.begin());
      49                 :         13 :     return ret;
      50                 :            : }
      51                 :            : 
      52                 :            : } // namespace spanparsing

Generated by: LCOV version 1.14