LCOV - code coverage report
Current view: top level - src/script - parsing.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 26 26
Test Date: 2024-09-01 05:20:30 Functions: 100.0 % 3 3
Branches: 100.0 % 32 32

             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 <script/parsing.h>
       6                 :             : 
       7                 :             : #include <span.h>
       8                 :             : 
       9                 :             : #include <algorithm>
      10                 :             : #include <cstddef>
      11                 :             : #include <string>
      12                 :             : 
      13                 :             : namespace script {
      14                 :             : 
      15                 :    11456867 : bool Const(const std::string& str, Span<const char>& sp)
      16                 :             : {
      17   [ +  +  +  + ]:    11456867 :     if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
      18                 :     1447198 :         sp = sp.subspan(str.size());
      19                 :     1447198 :         return true;
      20                 :             :     }
      21                 :    10009669 :     return false;
      22                 :    11456867 : }
      23                 :             : 
      24                 :      809337 : bool Func(const std::string& str, Span<const char>& sp)
      25                 :             : {
      26   [ +  +  +  +  :      809337 :     if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
             +  +  +  + ]
      27                 :       60949 :         sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
      28                 :       60949 :         return true;
      29                 :             :     }
      30                 :      748388 :     return false;
      31                 :      809337 : }
      32                 :             : 
      33                 :      248100 : Span<const char> Expr(Span<const char>& sp)
      34                 :             : {
      35                 :      248100 :     int level = 0;
      36                 :      248100 :     auto it = sp.begin();
      37         [ +  + ]:   164307822 :     while (it != sp.end()) {
      38   [ +  +  +  + ]:   164225842 :         if (*it == '(' || *it == '{') {
      39                 :     1117075 :             ++level;
      40   [ +  +  +  +  :   164225842 :         } else if (level && (*it == ')' || *it == '}')) {
                   +  + ]
      41                 :      498546 :             --level;
      42   [ +  +  +  +  :   163108767 :         } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
             +  +  +  + ]
      43                 :      166120 :             break;
      44                 :             :         }
      45                 :   164059722 :         ++it;
      46                 :             :     }
      47                 :      248100 :     Span<const char> ret = sp.first(it - sp.begin());
      48                 :      248100 :     sp = sp.subspan(it - sp.begin());
      49                 :             :     return ret;
      50                 :      248100 : }
      51                 :             : 
      52                 :             : } // namespace script
        

Generated by: LCOV version 2.0-1