OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/http2/hpack/tools/hpack_example.h" | |
6 | |
7 #include <ctype.h> | |
8 | |
9 #include "base/logging.h" | |
10 #include "net/spdy/spdy_test_utils.h" | |
11 | |
12 using base::StringPiece; | |
13 using std::string; | |
14 | |
15 namespace net { | |
16 namespace test { | |
17 namespace { | |
18 | |
19 void HpackExampleToStringOrDie(StringPiece example, string* output) { | |
20 while (!example.empty()) { | |
21 const char c0 = example[0]; | |
22 if (isxdigit(c0)) { | |
23 CHECK_GT(example.size(), 1u) << "Truncated hex byte?"; | |
24 const char c1 = example[1]; | |
25 CHECK(isxdigit(c1)) << "Found half a byte?"; | |
26 *output += a2b_hex(example.substr(0, 2).as_string().c_str()); | |
27 example.remove_prefix(2); | |
28 continue; | |
29 } | |
30 if (isspace(c0)) { | |
31 example.remove_prefix(1); | |
32 continue; | |
33 } | |
34 if (example.starts_with("|")) { | |
35 // Start of a comment. Skip to end of line or of input. | |
36 auto pos = example.find('\n'); | |
37 if (pos == StringPiece::npos) { | |
38 // End of input. | |
39 break; | |
40 } | |
41 example.remove_prefix(pos + 1); | |
42 continue; | |
43 } | |
44 CHECK(false) << "Can't parse byte " << static_cast<int>(c0) << " (0x" | |
45 << std::hex << c0 << ")" | |
46 << "\nExample: " << example; | |
47 } | |
48 CHECK_LT(0u, output->size()) << "Example is empty."; | |
49 return; | |
50 } | |
51 | |
52 } // namespace | |
53 | |
54 string HpackExampleToStringOrDie(StringPiece example) { | |
55 string output; | |
56 HpackExampleToStringOrDie(example, &output); | |
57 return output; | |
58 } | |
59 | |
60 } // namespace test | |
61 } // namespace net | |
OLD | NEW |