GCC Code Coverage Report


Directory: ./
File: src/deserializers/content_deserializer.cpp
Date: 2024-07-09 12:21:25
Exec Total Coverage
Lines: 26 32 81.2%
Functions: 2 2 100.0%
Branches: 17 41 41.5%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2024 Muhammad Nawaz
3 * Licensed under the MIT License. See LICENSE file for more information.
4 */
5 // [ END OF LICENSE c6bd0f49d040fca8d8a9cb05868e66aa63f0e2e0 ]
6
7 #include "deserializers/content_deserializer.hpp"
8
9 46 ContentDeserializer::ContentDeserializer(const std::string& param_name, char start, bool skip_name)
10 46 : BaseDeserializer(param_name, start, skip_name)
11 {
12 46 }
13
14 11 std::string ContentDeserializer::Deserialize(const char* beg, const char* const end)
15 {
16 11 const char* cursor = beg;
17
18
1/2
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
11 CheckNSkipStart(cursor);
19
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 4 times.
11 if (skip_name_) {
20
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 CheckNSkipName(cursor, end);
21
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 1 times.
7 CheckNSkipChar(cursor, end, '=');
22 }
23
24 10 std::string ret;
25
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 ret.reserve(static_cast<std::string::size_type>(end - cursor));
26
27
2/2
✓ Branch 0 taken 438 times.
✓ Branch 1 taken 10 times.
448 while (cursor < end) {
28 438 char c = *cursor++;
29
2/3
✓ Branch 0 taken 166 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 272 times.
438 switch (c) {
30 166 case '%': {
31
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 166 times.
166 if (cursor + 1 >= end) {
32 throw DeserializationException("Incomplete percent encoding for '" + param_name_ + "'");
33 }
34 166 const char dec1 = kHexLookupTable[static_cast<unsigned char>(*cursor++)];
35 166 const char dec2 = kHexLookupTable[static_cast<unsigned char>(*cursor++)];
36
2/4
✓ Branch 0 taken 166 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 166 times.
166 if (dec1 < 0 || dec2 < 0) {
37 throw DeserializationException("Invalid HEX character for '" + param_name_ + "'");
38 }
39
1/2
✓ Branch 1 taken 166 times.
✗ Branch 2 not taken.
166 ret.push_back(static_cast<char>((dec1 << 4) | dec2));
40 166 } break;
41
42 case '+':
43 ret += ' ';
44 break;
45
46 272 default:
47
1/2
✓ Branch 1 taken 272 times.
✗ Branch 2 not taken.
272 ret += c;
48 272 break;
49 }
50 }
51
52
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 CheckEnd(cursor, end);
53 20 return ret;
54 }
55