LCOV - code coverage report
Current view: top level - libs/url/src - scheme.cpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 75 75
Test Date: 2026-01-27 15:41:35 Functions: 100.0 % 3 3

            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/scheme.hpp>
      13              : #include <boost/url/grammar/ci_string.hpp>
      14              : 
      15              : namespace boost {
      16              : namespace urls {
      17              : 
      18              : scheme
      19         5295 : string_to_scheme(
      20              :     core::string_view s) noexcept
      21              : {
      22              :     using grammar::to_lower;
      23         5295 :     switch(s.size())
      24              :     {
      25            2 :     case 0: // none
      26            2 :         return scheme::none;
      27              : 
      28          312 :     case 2: // ws
      29          453 :         if( to_lower(s[0]) == 'w' &&
      30          141 :             to_lower(s[1]) == 's')
      31          139 :             return scheme::ws;
      32          173 :         break;
      33              : 
      34          180 :     case 3:
      35          180 :         switch(to_lower(s[0]))
      36              :         {
      37           51 :         case 'w': // wss
      38           96 :             if( to_lower(s[1]) == 's' &&
      39           45 :                 to_lower(s[2]) == 's')
      40           43 :                 return scheme::wss;
      41            8 :             break;
      42              : 
      43           78 :         case 'f': // ftp
      44          115 :             if( to_lower(s[1]) == 't' &&
      45           37 :                 to_lower(s[2]) == 'p')
      46           36 :                 return scheme::ftp;
      47           42 :             break;
      48              : 
      49           51 :         default:
      50           51 :             break;
      51              :         }
      52          101 :         break;
      53              : 
      54         2355 :     case 4:
      55         2355 :         switch(to_lower(s[0]))
      56              :         {
      57          361 :         case 'f': // file
      58          710 :             if( to_lower(s[1]) == 'i' &&
      59          710 :                 to_lower(s[2]) == 'l' &&
      60          348 :                 to_lower(s[3]) == 'e')
      61          347 :                 return scheme::file;
      62           14 :             break;
      63              : 
      64         1846 :         case 'h': // http
      65         3690 :             if( to_lower(s[1]) == 't' &&
      66         3690 :                 to_lower(s[2]) == 't' &&
      67         1843 :                 to_lower(s[3]) == 'p')
      68         1843 :                 return scheme::http;
      69            3 :             break;
      70              : 
      71          148 :         default:
      72          148 :             break;
      73              :         }
      74          165 :         break;
      75              : 
      76         1455 :     case 5: // https
      77         2003 :         if( to_lower(s[0]) == 'h' &&
      78         1095 :             to_lower(s[1]) == 't' &&
      79         1093 :             to_lower(s[2]) == 't' &&
      80         2549 :             to_lower(s[3]) == 'p' &&
      81          545 :             to_lower(s[4]) == 's')
      82          538 :             return scheme::https;
      83          917 :         break;
      84              : 
      85          991 :     default:
      86          991 :         break;
      87              :     }
      88         2347 :     return scheme::unknown;
      89              : }
      90              : 
      91              : core::string_view
      92           53 : to_string(scheme s) noexcept
      93              : {
      94           53 :     switch(s)
      95              :     {
      96            4 :     case scheme::ftp:   return "ftp";
      97            3 :     case scheme::file:  return "file";
      98            3 :     case scheme::http:  return "http";
      99            5 :     case scheme::https: return "https";
     100           11 :     case scheme::ws:    return "ws";
     101            5 :     case scheme::wss:   return "wss";
     102            1 :     case scheme::none:  return {};
     103           21 :     default:
     104           21 :         break;
     105              :     }
     106           21 :     return "<unknown>";
     107              : }
     108              : 
     109              : std::uint16_t
     110            8 : default_port(scheme s) noexcept
     111              : {
     112            8 :     switch(s)
     113              :     {
     114            1 :     case scheme::ftp:
     115            1 :         return 21;
     116            2 :     case scheme::http:
     117              :     case scheme::ws:
     118            2 :         return 80;
     119            2 :     case scheme::https:
     120              :     case scheme::wss:
     121            2 :         return 443;
     122            3 :     default:
     123            3 :         break;
     124              :     }
     125            3 :     return 0;
     126              : }
     127              : 
     128              : } // urls
     129              : } // boost
     130              : 
        

Generated by: LCOV version 2.3