LCOV - code coverage report
Current view: top level - libs/url/src/grammar - literal_rule.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 16 16 100.0 %
Date: 2024-03-13 19:32:03 Functions: 1 1 100.0 %

          Line data    Source code
       1             : 
       2             : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
       3             : //
       4             : // Distributed under the Boost Software License, Version 1.0. (See accompanying
       5             : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
       6             : //
       7             : // Official repository: https://github.com/boostorg/url
       8             : //
       9             : 
      10             : 
      11             : #include <boost/url/detail/config.hpp>
      12             : #include <boost/url/grammar/error.hpp>
      13             : #include <boost/url/grammar/literal_rule.hpp>
      14             : #include <boost/assert.hpp>
      15             : #include <cstring>
      16             : 
      17             : namespace boost {
      18             : namespace urls {
      19             : namespace grammar {
      20             : 
      21             : auto
      22          10 : literal_rule::
      23             : parse(
      24             :     char const*& it,
      25             :     char const* end) const noexcept ->
      26             :         system::result<value_type>
      27             : {
      28             :     // Can't have a literal
      29             :     // with an empty string!
      30          10 :     BOOST_ASSERT(n_ > 0);
      31             : 
      32          10 :     std::size_t n = end - it;
      33          10 :     if(n >= n_)
      34             :     {
      35           4 :         if(std::memcmp(
      36           4 :             it, s_, n_) != 0)
      37             :         {
      38             :             // non-match
      39           1 :             BOOST_URL_RETURN_EC(
      40             :                 error::mismatch);
      41             :         }
      42           3 :         it += n_;
      43           3 :         return core::string_view(
      44           3 :             it - n_, it);
      45             :     }
      46           6 :     if(n > 0)
      47             :     {
      48             :         // short input
      49           5 :         if(std::memcmp(
      50           5 :             it, s_, n) != 0)
      51             :         {
      52             :             // non-match
      53           2 :             BOOST_URL_RETURN_EC(
      54             :                 error::mismatch);
      55             :         }
      56             :         // prefix matches
      57           3 :         BOOST_URL_RETURN_EC(
      58             :             error::need_more);
      59             :     }
      60             :     // end
      61           1 :     BOOST_URL_RETURN_EC(
      62             :         error::need_more);
      63             : }
      64             : 
      65             : } // grammar
      66             : } // urls
      67             : } // boost
      68             : 

Generated by: LCOV version 1.15