LCOV - code coverage report
Current view: top level - libs/url/src/grammar - dec_octet_rule.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 30 30 100.0 %
Date: 2024-02-29 20:02:55 Functions: 1 1 100.0 %

          Line data    Source code
       1             : //
       2             : // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot 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             : #ifndef BOOST_URL_IMPL_GRAMMAR_DEC_OCTET_RULE_IPP
      11             : #define BOOST_URL_IMPL_GRAMMAR_DEC_OCTET_RULE_IPP
      12             : 
      13             : #include <boost/url/detail/config.hpp>
      14             : #include <boost/url/grammar/charset.hpp>
      15             : #include <boost/url/grammar/dec_octet_rule.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             : 
      23             : auto
      24        2276 : dec_octet_rule_t::
      25             : parse(
      26             :     char const*& it,
      27             :     char const* const end
      28             :         ) const noexcept ->
      29             :     system::result<value_type>
      30             : {
      31        2276 :     if(it == end)
      32             :     {
      33             :         // end
      34          14 :         BOOST_URL_RETURN_EC(
      35             :             error::mismatch);
      36             :     }
      37        2262 :     if(! digit_chars(*it))
      38             :     {
      39             :         // expected DIGIT
      40        1632 :         BOOST_URL_RETURN_EC(
      41             :             error::mismatch);
      42             :     }
      43         630 :     unsigned v = *it - '0';
      44         630 :     ++it;
      45        1194 :     if( it == end ||
      46         564 :         ! digit_chars(*it))
      47             :     {
      48         424 :         return static_cast<
      49         424 :             value_type>(v);
      50             :     }
      51         206 :     if(v == 0)
      52             :     {
      53             :         // leading '0'
      54          11 :         BOOST_URL_RETURN_EC(
      55             :             error::invalid);
      56             :     }
      57         195 :     v = (10 * v) + *it - '0';
      58         195 :     ++it;
      59         386 :     if( it == end ||
      60         191 :         ! digit_chars(*it))
      61             :     {
      62          23 :         return static_cast<
      63          23 :             value_type>(v);
      64             :     }
      65         172 :     if(v > 25)
      66             :     {
      67             :         // integer overflow
      68          13 :         BOOST_URL_RETURN_EC(
      69             :             error::invalid);
      70             :     }
      71         159 :     v = (10 * v) + *it - '0';
      72         159 :     if(v > 255)
      73             :     {
      74             :         // integer overflow
      75          17 :         BOOST_URL_RETURN_EC(
      76             :             error::invalid);
      77             :     }
      78         142 :     ++it;
      79         272 :     if( it != end &&
      80         130 :         digit_chars(*it))
      81             :     {
      82             :         // integer overflow
      83           7 :         BOOST_URL_RETURN_EC(
      84             :             error::invalid);
      85             :     }
      86         135 :     return static_cast<
      87         135 :         value_type>(v);
      88             : }
      89             : 
      90             : } // grammar
      91             : } // urls
      92             : } // boost
      93             : 
      94             : #endif

Generated by: LCOV version 1.15