LCOV - code coverage report
Current view: top level - libs/url/src - scheme.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 75 75 100.0 %
Date: 2024-02-29 20:02:55 Functions: 3 3 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             : #ifndef BOOST_URL_IMPL_SCHEME_IPP
      11             : #define BOOST_URL_IMPL_SCHEME_IPP
      12             : 
      13             : #include <boost/url/detail/config.hpp>
      14             : #include <boost/url/scheme.hpp>
      15             : #include <boost/url/grammar/ci_string.hpp>
      16             : 
      17             : namespace boost {
      18             : namespace urls {
      19             : 
      20             : scheme
      21        4928 : string_to_scheme(
      22             :     core::string_view s) noexcept
      23             : {
      24             :     using grammar::to_lower;
      25        4928 :     switch(s.size())
      26             :     {
      27           2 :     case 0: // none
      28           2 :         return scheme::none;
      29             : 
      30         311 :     case 2: // ws
      31         452 :         if( to_lower(s[0]) == 'w' &&
      32         141 :             to_lower(s[1]) == 's')
      33         139 :             return scheme::ws;
      34         172 :         break;
      35             : 
      36         178 :     case 3:
      37         178 :         switch(to_lower(s[0]))
      38             :         {
      39          51 :         case 'w': // wss
      40          96 :             if( to_lower(s[1]) == 's' &&
      41          45 :                 to_lower(s[2]) == 's')
      42          43 :                 return scheme::wss;
      43           8 :             break;
      44             : 
      45          78 :         case 'f': // ftp
      46         115 :             if( to_lower(s[1]) == 't' &&
      47          37 :                 to_lower(s[2]) == 'p')
      48          36 :                 return scheme::ftp;
      49          42 :             break;
      50             : 
      51          49 :         default:
      52          49 :             break;
      53             :         }
      54          99 :         break;
      55             : 
      56        2251 :     case 4:
      57        2251 :         switch(to_lower(s[0]))
      58             :         {
      59         359 :         case 'f': // file
      60         706 :             if( to_lower(s[1]) == 'i' &&
      61         706 :                 to_lower(s[2]) == 'l' &&
      62         346 :                 to_lower(s[3]) == 'e')
      63         345 :                 return scheme::file;
      64          14 :             break;
      65             : 
      66        1748 :         case 'h': // http
      67        3494 :             if( to_lower(s[1]) == 't' &&
      68        3494 :                 to_lower(s[2]) == 't' &&
      69        1745 :                 to_lower(s[3]) == 'p')
      70        1745 :                 return scheme::http;
      71           3 :             break;
      72             : 
      73         144 :         default:
      74         144 :             break;
      75             :         }
      76         161 :         break;
      77             : 
      78        1209 :     case 5: // https
      79        1511 :         if( to_lower(s[0]) == 'h' &&
      80         603 :             to_lower(s[1]) == 't' &&
      81         601 :             to_lower(s[2]) == 't' &&
      82        1811 :             to_lower(s[3]) == 'p' &&
      83         299 :             to_lower(s[4]) == 's')
      84         292 :             return scheme::https;
      85         917 :         break;
      86             : 
      87         977 :     default:
      88         977 :         break;
      89             :     }
      90        2326 :     return scheme::unknown;
      91             : }
      92             : 
      93             : core::string_view
      94          51 : to_string(scheme s) noexcept
      95             : {
      96          51 :     switch(s)
      97             :     {
      98           4 :     case scheme::ftp:   return "ftp";
      99           3 :     case scheme::file:  return "file";
     100           3 :     case scheme::http:  return "http";
     101           3 :     case scheme::https: return "https";
     102          11 :     case scheme::ws:    return "ws";
     103           5 :     case scheme::wss:   return "wss";
     104           1 :     case scheme::none:  return {};
     105          21 :     default:
     106          21 :         break;
     107             :     }
     108          21 :     return "<unknown>";
     109             : }
     110             : 
     111             : std::uint16_t
     112           8 : default_port(scheme s) noexcept
     113             : {
     114           8 :     switch(s)
     115             :     {
     116           1 :     case scheme::ftp:
     117           1 :         return 21;
     118           2 :     case scheme::http:
     119             :     case scheme::ws:
     120           2 :         return 80;
     121           2 :     case scheme::https:
     122             :     case scheme::wss:
     123           2 :         return 443;
     124           3 :     default:
     125           3 :         break;
     126             :     }
     127           3 :     return 0;
     128             : }
     129             : 
     130             : } // urls
     131             : } // boost
     132             : 
     133             : #endif

Generated by: LCOV version 1.15