LCOV - code coverage report
Current view: top level - url/impl - scheme.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 75 75
Test Date: 2026-03-02 22:26:03 Functions: 100.0 % 3 3

           TLA  Line data    Source code
       1                 : //
       2                 : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.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_IMPL_SCHEME_HPP
      12                 : #define BOOST_URL_IMPL_SCHEME_HPP
      13                 : 
      14                 : #include <boost/url/detail/config.hpp>
      15                 : 
      16                 : #include <boost/url/grammar/ci_string.hpp>
      17                 : 
      18                 : namespace boost {
      19                 : namespace urls {
      20                 : 
      21                 : BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
      22                 : scheme
      23 HIT       21730 : string_to_scheme(
      24                 :     core::string_view s) noexcept
      25                 : {
      26                 :     using grammar::to_lower;
      27           21730 :     switch(s.size())
      28                 :     {
      29               3 :     case 0: // none
      30               3 :         return scheme::none;
      31                 : 
      32            1803 :     case 2: // ws
      33            2049 :         if( to_lower(s[0]) == 'w' &&
      34             246 :             to_lower(s[1]) == 's')
      35             168 :             return scheme::ws;
      36            1635 :         break;
      37                 : 
      38            1288 :     case 3:
      39            1288 :         switch(to_lower(s[0]))
      40                 :         {
      41              93 :         case 'w': // wss
      42             156 :             if( to_lower(s[1]) == 's' &&
      43              63 :                 to_lower(s[2]) == 's')
      44              61 :                 return scheme::wss;
      45              32 :             break;
      46                 : 
      47             256 :         case 'f': // ftp
      48             435 :             if( to_lower(s[1]) == 't' &&
      49             179 :                 to_lower(s[2]) == 'p')
      50             178 :                 return scheme::ftp;
      51              78 :             break;
      52                 : 
      53             939 :         default:
      54             939 :             break;
      55                 :         }
      56            1049 :         break;
      57                 : 
      58            5519 :     case 4:
      59            5519 :         switch(to_lower(s[0]))
      60                 :         {
      61             415 :         case 'f': // file
      62             788 :             if( to_lower(s[1]) == 'i' &&
      63             788 :                 to_lower(s[2]) == 'l' &&
      64             372 :                 to_lower(s[3]) == 'e')
      65             371 :                 return scheme::file;
      66              44 :             break;
      67                 : 
      68            4338 :         case 'h': // http
      69            8643 :             if( to_lower(s[1]) == 't' &&
      70            8643 :                 to_lower(s[2]) == 't' &&
      71            4300 :                 to_lower(s[3]) == 'p')
      72            4300 :                 return scheme::http;
      73              38 :             break;
      74                 : 
      75             766 :         default:
      76             766 :             break;
      77                 :         }
      78             848 :         break;
      79                 : 
      80            9108 :     case 5: // https
      81           16899 :         if( to_lower(s[0]) == 'h' &&
      82           15569 :             to_lower(s[1]) == 't' &&
      83           15554 :             to_lower(s[2]) == 't' &&
      84           24675 :             to_lower(s[3]) == 'p' &&
      85            7775 :             to_lower(s[4]) == 's')
      86            7768 :             return scheme::https;
      87            1340 :         break;
      88                 : 
      89            4009 :     default:
      90            4009 :         break;
      91                 :     }
      92            8881 :     return scheme::unknown;
      93                 : }
      94                 : 
      95                 : inline
      96                 : core::string_view
      97             192 : to_string(scheme s) noexcept
      98                 : {
      99             192 :     switch(s)
     100                 :     {
     101              14 :     case scheme::ftp:   return "ftp";
     102              23 :     case scheme::file:  return "file";
     103              25 :     case scheme::http:  return "http";
     104              21 :     case scheme::https: return "https";
     105              33 :     case scheme::ws:    return "ws";
     106              23 :     case scheme::wss:   return "wss";
     107               1 :     case scheme::none:  return {};
     108              52 :     default:
     109              52 :         break;
     110                 :     }
     111              52 :     return "<unknown>";
     112                 : }
     113                 : 
     114                 : inline
     115                 : std::uint16_t
     116               8 : default_port(scheme s) noexcept
     117                 : {
     118               8 :     switch(s)
     119                 :     {
     120               1 :     case scheme::ftp:
     121               1 :         return 21;
     122               2 :     case scheme::http:
     123                 :     case scheme::ws:
     124               2 :         return 80;
     125               2 :     case scheme::https:
     126                 :     case scheme::wss:
     127               2 :         return 443;
     128               3 :     default:
     129               3 :         break;
     130                 :     }
     131               3 :     return 0;
     132                 : }
     133                 : 
     134                 : } // urls
     135                 : } // boost
     136                 : 
     137                 : #endif
        

Generated by: LCOV version 2.3