LCOV - code coverage report
Current view: top level - src/script - parsing.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 100.0 % 21 21
Test Date: 2024-08-28 04:44:32 Functions: 100.0 % 3 3
Branches: 100.0 % 24 24

             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                 :      188418 : bool Const(const std::string& str, Span<const char>& sp)
      16                 :             : {
      17   [ +  +  +  + ]:      188418 :     if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
      18                 :       13587 :         sp = sp.subspan(str.size());
      19                 :       13587 :         return true;
      20                 :             :     }
      21                 :             :     return false;
      22                 :             : }
      23                 :             : 
      24                 :        8410 : bool Func(const std::string& str, Span<const char>& sp)
      25                 :             : {
      26   [ +  +  +  +  :        8410 :     if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
             +  +  +  + ]
      27                 :         739 :         sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
      28                 :         739 :         return true;
      29                 :             :     }
      30                 :             :     return false;
      31                 :             : }
      32                 :             : 
      33                 :        1315 : Span<const char> Expr(Span<const char>& sp)
      34                 :             : {
      35                 :        1315 :     int level = 0;
      36                 :        1315 :     auto it = sp.begin();
      37         [ +  + ]:      185565 :     while (it != sp.end()) {
      38         [ +  + ]:      184600 :         if (*it == '(' || *it == '{') {
      39                 :        1831 :             ++level;
      40   [ +  +  +  + ]:      182769 :         } else if (level && (*it == ')' || *it == '}')) {
      41                 :        1635 :             --level;
      42   [ +  +  +  + ]:       35515 :         } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
      43                 :             :             break;
      44                 :             :         }
      45                 :      184250 :         ++it;
      46                 :             :     }
      47                 :        1315 :     Span<const char> ret = sp.first(it - sp.begin());
      48                 :        1315 :     sp = sp.subspan(it - sp.begin());
      49                 :        1315 :     return ret;
      50                 :             : }
      51                 :             : 
      52                 :             : } // namespace script
        

Generated by: LCOV version 2.0-1