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: 2024-08-19 20:08:54 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         4968 : string_to_scheme(
      20              :     core::string_view s) noexcept
      21              : {
      22              :     using grammar::to_lower;
      23         4968 :     switch(s.size())
      24              :     {
      25            2 :     case 0: // none
      26            2 :         return scheme::none;
      27              : 
      28          311 :     case 2: // ws
      29          452 :         if( to_lower(s[0]) == 'w' &&
      30          141 :             to_lower(s[1]) == 's')
      31          139 :             return scheme::ws;
      32          172 :         break;
      33              : 
      34          178 :     case 3:
      35          178 :         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           49 :         default:
      50           49 :             break;
      51              :         }
      52           99 :         break;
      53              : 
      54         2291 :     case 4:
      55         2291 :         switch(to_lower(s[0]))
      56              :         {
      57          359 :         case 'f': // file
      58          706 :             if( to_lower(s[1]) == 'i' &&
      59          706 :                 to_lower(s[2]) == 'l' &&
      60          346 :                 to_lower(s[3]) == 'e')
      61          345 :                 return scheme::file;
      62           14 :             break;
      63              : 
      64         1788 :         case 'h': // http
      65         3574 :             if( to_lower(s[1]) == 't' &&
      66         3574 :                 to_lower(s[2]) == 't' &&
      67         1785 :                 to_lower(s[3]) == 'p')
      68         1785 :                 return scheme::http;
      69            3 :             break;
      70              : 
      71          144 :         default:
      72          144 :             break;
      73              :         }
      74          161 :         break;
      75              : 
      76         1209 :     case 5: // https
      77         1511 :         if( to_lower(s[0]) == 'h' &&
      78          603 :             to_lower(s[1]) == 't' &&
      79          601 :             to_lower(s[2]) == 't' &&
      80         1811 :             to_lower(s[3]) == 'p' &&
      81          299 :             to_lower(s[4]) == 's')
      82          292 :             return scheme::https;
      83          917 :         break;
      84              : 
      85          977 :     default:
      86          977 :         break;
      87              :     }
      88         2326 :     return scheme::unknown;
      89              : }
      90              : 
      91              : core::string_view
      92           51 : to_string(scheme s) noexcept
      93              : {
      94           51 :     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            3 :     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.1