LCOV - code coverage report
Current view: top level - url/grammar/impl - dec_octet_rule.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 30 30
Test Date: 2026-02-13 15:53:22 Functions: 100.0 % 1 1

            Line data    Source code
       1              : //
       2              : // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
       3              : // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
       4              : //
       5              : // Distributed under the Boost Software License, Version 1.0. (See accompanying
       6              : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
       7              : //
       8              : // Official repository: https://github.com/boostorg/url
       9              : //
      10              : 
      11              : #ifndef BOOST_URL_GRAMMAR_IMPL_DEC_OCTET_RULE_HPP
      12              : #define BOOST_URL_GRAMMAR_IMPL_DEC_OCTET_RULE_HPP
      13              : 
      14              : #include <boost/url/detail/config.hpp>
      15              : #include <boost/url/grammar/charset.hpp>
      16              : #include <boost/url/grammar/digit_chars.hpp>
      17              : #include <boost/url/grammar/error.hpp>
      18              : 
      19              : namespace boost {
      20              : namespace urls {
      21              : namespace grammar {
      22              : namespace implementation_defined {
      23              : 
      24              : inline BOOST_URL_CXX20_CONSTEXPR
      25              : auto
      26         2477 : dec_octet_rule_t::
      27              : parse(
      28              :     char const*& it,
      29              :     char const* const end
      30              :         ) const noexcept ->
      31              :     system::result<value_type>
      32              : {
      33         2477 :     if(it == end)
      34              :     {
      35           14 :         BOOST_URL_CONSTEXPR_RETURN_EC(
      36              :             error::mismatch);
      37              :     }
      38         2463 :     if(! digit_chars(*it))
      39              :     {
      40         1817 :         BOOST_URL_CONSTEXPR_RETURN_EC(
      41              :             error::mismatch);
      42              :     }
      43          646 :     unsigned v = *it - '0';
      44          646 :     ++it;
      45         1223 :     if( it == end ||
      46          577 :         ! digit_chars(*it))
      47              :     {
      48          433 :         return static_cast<
      49          433 :             value_type>(v);
      50              :     }
      51          213 :     if(v == 0)
      52              :     {
      53           11 :         BOOST_URL_CONSTEXPR_RETURN_EC(
      54              :             error::invalid);
      55              :     }
      56          202 :     v = (10 * v) + *it - '0';
      57          202 :     ++it;
      58          400 :     if( it == end ||
      59          198 :         ! digit_chars(*it))
      60              :     {
      61           23 :         return static_cast<
      62           23 :             value_type>(v);
      63              :     }
      64          179 :     if(v > 25)
      65              :     {
      66           13 :         BOOST_URL_CONSTEXPR_RETURN_EC(
      67              :             error::invalid);
      68              :     }
      69          166 :     v = (10 * v) + *it - '0';
      70          166 :     if(v > 255)
      71              :     {
      72           17 :         BOOST_URL_CONSTEXPR_RETURN_EC(
      73              :             error::invalid);
      74              :     }
      75          149 :     ++it;
      76          286 :     if( it != end &&
      77          137 :         digit_chars(*it))
      78              :     {
      79            7 :         BOOST_URL_CONSTEXPR_RETURN_EC(
      80              :             error::invalid);
      81              :     }
      82          142 :     return static_cast<
      83          142 :         value_type>(v);
      84              : }
      85              : 
      86              : } // implementation_defined
      87              : } // grammar
      88              : } // urls
      89              : } // boost
      90              : 
      91              : #endif
        

Generated by: LCOV version 2.3