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-03-01 04:48:12 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.15