LCOV - code coverage report
Current view: top level - http_proto/impl - method.ipp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 178 181 98.3 %
Date: 2023-01-15 07:18:31 Functions: 2 2 100.0 %

          Line data    Source code
       1             : //
       2             : // Copyright (c) 2021 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/CPPAlliance/http_proto
       8             : //
       9             : 
      10             : #ifndef BOOST_HTTP_PROTO_IMPL_METHOD_IPP
      11             : #define BOOST_HTTP_PROTO_IMPL_METHOD_IPP
      12             : 
      13             : #include <boost/http_proto/method.hpp>
      14             : #include <boost/http_proto/detail/sv.hpp>
      15             : #include <boost/throw_exception.hpp>
      16             : #include <stdexcept>
      17             : 
      18             : namespace boost {
      19             : namespace http_proto {
      20             : 
      21             : string_view
      22          69 : to_string(method v)
      23             : {
      24             :     using namespace detail::string_literals;
      25          69 :     switch(v)
      26             :     {
      27           3 :     case method::delete_:       return "DELETE"_sv;
      28          32 :     case method::get:           return "GET"_sv;
      29           1 :     case method::head:          return "HEAD"_sv;
      30           1 :     case method::post:          return "POST"_sv;
      31           1 :     case method::put:           return "PUT"_sv;
      32           2 :     case method::connect:       return "CONNECT"_sv;
      33           1 :     case method::options:       return "OPTIONS"_sv;
      34           1 :     case method::trace:         return "TRACE"_sv;
      35             : 
      36           1 :     case method::copy:          return "COPY"_sv;
      37           1 :     case method::lock:          return "LOCK"_sv;
      38           1 :     case method::mkcol:         return "MKCOL"_sv;
      39           1 :     case method::move:          return "MOVE"_sv;
      40           1 :     case method::propfind:      return "PROPFIND"_sv;
      41           1 :     case method::proppatch:     return "PROPPATCH"_sv;
      42           1 :     case method::search:        return "SEARCH"_sv;
      43           1 :     case method::unlock:        return "UNLOCK"_sv;
      44           1 :     case method::bind:          return "BIND"_sv;
      45           1 :     case method::rebind:        return "REBIND"_sv;
      46           1 :     case method::unbind:        return "UNBIND"_sv;
      47           1 :     case method::acl:           return "ACL"_sv;
      48             : 
      49           1 :     case method::report:        return "REPORT"_sv;
      50           1 :     case method::mkactivity:    return "MKACTIVITY"_sv;
      51           1 :     case method::checkout:      return "CHECKOUT"_sv;
      52           1 :     case method::merge:         return "MERGE"_sv;
      53             : 
      54           1 :     case method::msearch:       return "M-SEARCH"_sv;
      55           1 :     case method::notify:        return "NOTIFY"_sv;
      56           1 :     case method::subscribe:     return "SUBSCRIBE"_sv;
      57           1 :     case method::unsubscribe:   return "UNSUBSCRIBE"_sv;
      58             : 
      59           1 :     case method::patch:         return "PATCH"_sv;
      60           1 :     case method::purge:         return "PURGE"_sv;
      61             : 
      62           1 :     case method::mkcalendar:    return "MKCALENDAR"_sv;
      63             : 
      64           1 :     case method::link:          return "LINK"_sv;
      65           1 :     case method::unlink:        return "UNLINK"_sv;
      66             : 
      67           1 :     case method::unknown:
      68           1 :         return "<unknown>"_sv;
      69             :     }
      70             : 
      71           2 :     BOOST_THROW_EXCEPTION(
      72             :         std::invalid_argument("unknown method"));
      73             : }
      74             : 
      75             : method
      76        1141 : string_to_method(string_view v)
      77             : {
      78             : /*
      79             :     ACL
      80             :     BIND
      81             :     CHECKOUT
      82             :     CONNECT
      83             :     COPY
      84             :     DELETE
      85             :     GET
      86             :     HEAD
      87             :     LINK
      88             :     LOCK
      89             :     M-SEARCH
      90             :     MERGE
      91             :     MKACTIVITY
      92             :     MKCALENDAR
      93             :     MKCOL
      94             :     MOVE
      95             :     NOTIFY
      96             :     OPTIONS
      97             :     PATCH
      98             :     POST
      99             :     PROPFIND
     100             :     PROPPATCH
     101             :     PURGE
     102             :     PUT
     103             :     REBIND
     104             :     REPORT
     105             :     SEARCH
     106             :     SUBSCRIBE
     107             :     TRACE
     108             :     UNBIND
     109             :     UNLINK
     110             :     UNLOCK
     111             :     UNSUBSCRIBE
     112             : */
     113             :     using namespace detail::string_literals;
     114        1141 :     if(v.size() < 3)
     115           0 :         return method::unknown;
     116        1141 :     auto c = v[0];
     117        1141 :     v.remove_prefix(1);
     118        1141 :     switch(c)
     119             :     {
     120           2 :     case 'A':
     121           2 :         if(v == "CL"_sv)
     122           1 :             return method::acl;
     123           1 :         break;
     124             : 
     125           5 :     case 'B':
     126           5 :         if(v == "IND"_sv)
     127           1 :             return method::bind;
     128           4 :         break;
     129             : 
     130           8 :     case 'C':
     131           8 :         c = v[0];
     132           8 :         v.remove_prefix(1);
     133           8 :         switch(c)
     134             :         {
     135           2 :         case 'H':
     136           2 :             if(v == "ECKOUT"_sv)
     137           1 :                 return method::checkout;
     138           1 :             break;
     139             : 
     140           6 :         case 'O':
     141           6 :             if(v == "NNECT"_sv)
     142           3 :                 return method::connect;
     143           3 :             if(v == "PY"_sv)
     144           1 :                 return method::copy;
     145             :             BOOST_FALLTHROUGH;
     146             : 
     147             :         default:
     148           2 :             break;
     149             :         }
     150           3 :         break;
     151             : 
     152           4 :     case 'D':
     153           4 :         if(v == "ELETE"_sv)
     154           3 :             return method::delete_;
     155           1 :         break;
     156             : 
     157         997 :     case 'G':
     158         997 :         if(v == "ET"_sv)
     159         996 :             return method::get;
     160           1 :         break;
     161             : 
     162           2 :     case 'H':
     163           2 :         if(v == "EAD"_sv)
     164           1 :             return method::head;
     165           1 :         break;
     166             : 
     167           4 :     case 'L':
     168           4 :         if(v == "INK"_sv)
     169           1 :             return method::link;
     170           3 :         if(v == "OCK"_sv)
     171           1 :             return method::lock;
     172           2 :         break;
     173             : 
     174          12 :     case 'M':
     175          12 :         c = v[0];
     176          12 :         v.remove_prefix(1);
     177          12 :         switch(c)
     178             :         {
     179           2 :         case '-':
     180           2 :             if(v == "SEARCH"_sv)
     181           1 :                 return method::msearch;
     182           1 :             break;
     183             : 
     184           2 :         case 'E':
     185           2 :             if(v == "RGE"_sv)
     186           1 :                 return method::merge;
     187           1 :             break;
     188             : 
     189           6 :         case 'K':
     190           6 :             if(v == "ACTIVITY"_sv)
     191           1 :                 return method::mkactivity;
     192           5 :             if(v[0] == 'C')
     193             :             {
     194           4 :                 v.remove_prefix(1);
     195           4 :                 if(v == "ALENDAR"_sv)
     196           1 :                     return method::mkcalendar;
     197           3 :                 if(v == "OL"_sv)
     198           1 :                     return method::mkcol;
     199           2 :                 break;
     200             :             }
     201           1 :             break;
     202             : 
     203           2 :         case 'O':
     204           2 :             if(v == "VE"_sv)
     205           1 :                 return method::move;
     206             :             BOOST_FALLTHROUGH;
     207             : 
     208             :         default:
     209           1 :             break;
     210             :         }
     211           6 :         break;
     212             : 
     213           2 :     case 'N':
     214           2 :         if(v == "OTIFY"_sv)
     215           1 :             return method::notify;
     216           1 :         break;
     217             : 
     218           2 :     case 'O':
     219           2 :         if(v == "PTIONS"_sv)
     220           1 :             return method::options;
     221           1 :         break;
     222             : 
     223          84 :     case 'P':
     224          84 :         c = v[0];
     225          84 :         v.remove_prefix(1);
     226          84 :         switch(c)
     227             :         {
     228           2 :         case 'A':
     229           2 :             if(v == "TCH"_sv)
     230           1 :                 return method::patch;
     231           1 :             break;
     232             : 
     233          74 :         case 'O':
     234          74 :             if(v == "ST"_sv)
     235          73 :                 return method::post;
     236           1 :             break;
     237             : 
     238           4 :         case 'R':
     239           4 :             if(v == "OPFIND"_sv)
     240           1 :                 return method::propfind;
     241           3 :             if(v == "OPPATCH"_sv)
     242           1 :                 return method::proppatch;
     243           2 :             break;
     244             : 
     245           4 :         case 'U':
     246           4 :             if(v == "RGE"_sv)
     247           1 :                 return method::purge;
     248           3 :             if(v == "T"_sv)
     249           1 :                 return method::put;
     250             :             BOOST_FALLTHROUGH;
     251             : 
     252             :         default:
     253           2 :             break;
     254             :         }
     255           6 :         break;
     256             : 
     257           4 :     case 'R':
     258           4 :         if(v[0] != 'E')
     259           0 :             break;
     260           4 :         v.remove_prefix(1);
     261           4 :         if(v == "BIND"_sv)
     262           1 :             return method::rebind;
     263           3 :         if(v == "PORT"_sv)
     264           1 :             return method::report;
     265           2 :         break;
     266             : 
     267           4 :     case 'S':
     268           4 :         if(v == "EARCH"_sv)
     269           1 :             return method::search;
     270           3 :         if(v == "UBSCRIBE"_sv)
     271           1 :             return method::subscribe;
     272           2 :         break;
     273             : 
     274           2 :     case 'T':
     275           2 :         if(v == "RACE"_sv)
     276           1 :             return method::trace;
     277           1 :         break;
     278             : 
     279           8 :     case 'U':
     280           8 :         if(v[0] != 'N')
     281           0 :             break;
     282           8 :         v.remove_prefix(1);
     283           8 :         if(v == "BIND"_sv)
     284           1 :             return method::unbind;
     285           7 :         if(v == "LINK"_sv)
     286           1 :             return method::unlink;
     287           6 :         if(v == "LOCK"_sv)
     288           1 :             return method::unlock;
     289           5 :         if(v == "SUBSCRIBE"_sv)
     290           1 :             return method::unsubscribe;
     291           4 :         break;
     292             : 
     293           1 :     default:
     294           1 :         break;
     295             :     }
     296             : 
     297          37 :     return method::unknown;
     298             : }
     299             : 
     300             : } // http_proto
     301             : } // boost
     302             : 
     303             : #endif

Generated by: LCOV version 1.15