include/boost/url/impl/scheme.hpp
100.0% Lines (52/52)
100.0% Functions (1/1)
98.3% Branches (57/58)
include/boost/url/impl/scheme.hpp
| Line | Branch | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com) | ||
| 4 | // | ||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/boostorg/url | ||
| 9 | // | ||
| 10 | |||
| 11 | #ifndef BOOST_URL_IMPL_SCHEME_HPP | ||
| 12 | #define BOOST_URL_IMPL_SCHEME_HPP | ||
| 13 | |||
| 14 | #include <boost/url/detail/config.hpp> | ||
| 15 | |||
| 16 | #include <boost/url/grammar/ci_string.hpp> | ||
| 17 | |||
| 18 | namespace boost { | ||
| 19 | namespace urls { | ||
| 20 | |||
| 21 | inline BOOST_URL_CXX20_CONSTEXPR | ||
| 22 | scheme | ||
| 23 | 5317 | string_to_scheme( | |
| 24 | core::string_view s) noexcept | ||
| 25 | { | ||
| 26 | using grammar::to_lower; | ||
| 27 |
6/6✓ Branch 1 taken 2 times.
✓ Branch 2 taken 312 times.
✓ Branch 3 taken 180 times.
✓ Branch 4 taken 2361 times.
✓ Branch 5 taken 1465 times.
✓ Branch 6 taken 997 times.
|
5317 | switch(s.size()) |
| 28 | { | ||
| 29 | 2 | case 0: // none | |
| 30 | 2 | return scheme::none; | |
| 31 | |||
| 32 | 312 | case 2: // ws | |
| 33 |
6/6✓ Branch 2 taken 141 times.
✓ Branch 3 taken 171 times.
✓ Branch 4 taken 139 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 139 times.
✓ Branch 7 taken 173 times.
|
453 | if( to_lower(s[0]) == 'w' && |
| 34 | 141 | to_lower(s[1]) == 's') | |
| 35 | 139 | return scheme::ws; | |
| 36 | 173 | break; | |
| 37 | |||
| 38 | 180 | case 3: | |
| 39 |
3/3✓ Branch 2 taken 51 times.
✓ Branch 3 taken 78 times.
✓ Branch 4 taken 51 times.
|
180 | switch(to_lower(s[0])) |
| 40 | { | ||
| 41 | 51 | case 'w': // wss | |
| 42 |
6/6✓ Branch 2 taken 45 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 43 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 43 times.
✓ Branch 7 taken 8 times.
|
96 | if( to_lower(s[1]) == 's' && |
| 43 | 45 | to_lower(s[2]) == 's') | |
| 44 | 43 | return scheme::wss; | |
| 45 | 8 | break; | |
| 46 | |||
| 47 | 78 | case 'f': // ftp | |
| 48 |
6/6✓ Branch 2 taken 37 times.
✓ Branch 3 taken 41 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 36 times.
✓ Branch 7 taken 42 times.
|
115 | if( to_lower(s[1]) == 't' && |
| 49 | 37 | to_lower(s[2]) == 'p') | |
| 50 | 36 | return scheme::ftp; | |
| 51 | 42 | break; | |
| 52 | |||
| 53 | 51 | default: | |
| 54 | 51 | break; | |
| 55 | } | ||
| 56 | 101 | break; | |
| 57 | |||
| 58 | 2361 | case 4: | |
| 59 |
3/3✓ Branch 2 taken 361 times.
✓ Branch 3 taken 1852 times.
✓ Branch 4 taken 148 times.
|
2361 | switch(to_lower(s[0])) |
| 60 | { | ||
| 61 | 361 | case 'f': // file | |
| 62 |
2/2✓ Branch 2 taken 348 times.
✓ Branch 3 taken 1 time.
|
710 | if( to_lower(s[1]) == 'i' && |
| 63 |
6/6✓ Branch 0 taken 349 times.
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 347 times.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 347 times.
✓ Branch 7 taken 14 times.
|
710 | to_lower(s[2]) == 'l' && |
| 64 | 348 | to_lower(s[3]) == 'e') | |
| 65 | 347 | return scheme::file; | |
| 66 | 14 | break; | |
| 67 | |||
| 68 | 1852 | case 'h': // http | |
| 69 |
2/2✓ Branch 2 taken 1849 times.
✓ Branch 3 taken 1 time.
|
3702 | if( to_lower(s[1]) == 't' && |
| 70 |
5/6✓ Branch 0 taken 1850 times.
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 1849 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1849 times.
✓ Branch 7 taken 3 times.
|
3702 | to_lower(s[2]) == 't' && |
| 71 | 1849 | to_lower(s[3]) == 'p') | |
| 72 | 1849 | return scheme::http; | |
| 73 | 3 | break; | |
| 74 | |||
| 75 | 148 | default: | |
| 76 | 148 | break; | |
| 77 | } | ||
| 78 | 165 | break; | |
| 79 | |||
| 80 | 1465 | case 5: // https | |
| 81 |
2/2✓ Branch 2 taken 557 times.
✓ Branch 3 taken 1 time.
|
2023 | if( to_lower(s[0]) == 'h' && |
| 82 |
2/2✓ Branch 2 taken 556 times.
✓ Branch 3 taken 1 time.
|
1115 | to_lower(s[1]) == 't' && |
| 83 |
2/2✓ Branch 2 taken 555 times.
✓ Branch 3 taken 1 time.
|
1113 | to_lower(s[2]) == 't' && |
| 84 |
6/6✓ Branch 0 taken 558 times.
✓ Branch 1 taken 907 times.
✓ Branch 4 taken 548 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 548 times.
✓ Branch 7 taken 917 times.
|
2579 | to_lower(s[3]) == 'p' && |
| 85 | 555 | to_lower(s[4]) == 's') | |
| 86 | 548 | return scheme::https; | |
| 87 | 917 | break; | |
| 88 | |||
| 89 | 997 | default: | |
| 90 | 997 | break; | |
| 91 | } | ||
| 92 | 2353 | return scheme::unknown; | |
| 93 | } | ||
| 94 | |||
| 95 | } // urls | ||
| 96 | } // boost | ||
| 97 | |||
| 98 | #endif | ||
| 99 |