Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: net/tools/balsa/balsa_headers_token_utils.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/tools/balsa/balsa_headers_token_utils.h" 5 #include "net/tools/balsa/balsa_headers_token_utils.h"
6 #include "net/tools/balsa/string_piece_utils.h" 6 #include "net/tools/balsa/string_piece_utils.h"
7 7
8 namespace net { 8 namespace net {
9 9
10 inline void BalsaHeadersTokenUtils::TokenizeHeaderLine( 10 inline void BalsaHeadersTokenUtils::TokenizeHeaderLine(
11 const BalsaHeaders& headers, 11 const BalsaHeaders& headers,
12 const BalsaHeaders::HeaderLineDescription& header_line, 12 const BalsaHeaders::HeaderLineDescription& header_line,
13 BalsaHeaders::HeaderTokenList* tokens) { 13 BalsaHeaders::HeaderTokenList* tokens) {
14 CHECK(tokens); 14 CHECK(tokens);
15 15
16 // Find where this line is stored 16 // Find where this line is stored
17 const char* stream_begin = headers.GetPtr(header_line.buffer_base_idx); 17 const char* stream_begin = headers.GetPtr(header_line.buffer_base_idx);
18 18
19 // Determine the boundaries of the value 19 // Determine the boundaries of the value
20 const char* value_begin = stream_begin + header_line.value_begin_idx; 20 const char* value_begin = stream_begin + header_line.value_begin_idx;
21 const char* line_end = stream_begin + header_line.last_char_idx; 21 const char* line_end = stream_begin + header_line.last_char_idx;
22 22
23 // Tokenize 23 // Tokenize
24 ParseTokenList(value_begin, line_end, tokens); 24 ParseTokenList(value_begin, line_end, tokens);
25 } 25 }
26 26
27 void BalsaHeadersTokenUtils::RemoveLastTokenFromHeaderValue( 27 void BalsaHeadersTokenUtils::RemoveLastTokenFromHeaderValue(
28 const base::StringPiece& key, BalsaHeaders* headers) { 28 const base::StringPiece& key,
29 BalsaHeaders* headers) {
29 BalsaHeaders::HeaderLines::iterator it = 30 BalsaHeaders::HeaderLines::iterator it =
30 headers->GetHeaderLinesIterator(key, headers->header_lines_.begin()); 31 headers->GetHeaderLinesIterator(key, headers->header_lines_.begin());
31 if (it == headers->header_lines_.end()) { 32 if (it == headers->header_lines_.end()) {
32 DLOG(WARNING) << "Attempting to remove last token from a non-existent " 33 DLOG(WARNING) << "Attempting to remove last token from a non-existent "
33 << "header \"" << key << "\""; 34 << "header \"" << key << "\"";
34 return; 35 return;
35 } 36 }
36 37
37 // Find the last line with that key. 38 // Find the last line with that key.
38 BalsaHeaders::HeaderLines::iterator header_line; 39 BalsaHeaders::HeaderLines::iterator header_line;
39 do { 40 do {
40 header_line = it; 41 header_line = it;
41 it = headers->GetHeaderLinesIterator(key, it + 1); 42 it = headers->GetHeaderLinesIterator(key, it + 1);
42 } 43 } while (it != headers->header_lines_.end());
43 while (it != headers->header_lines_.end());
44 44
45 // Tokenize just that line. 45 // Tokenize just that line.
46 BalsaHeaders::HeaderTokenList tokens; 46 BalsaHeaders::HeaderTokenList tokens;
47 TokenizeHeaderLine(*headers, *header_line, &tokens); 47 TokenizeHeaderLine(*headers, *header_line, &tokens);
48 48
49 if (tokens.empty()) { 49 if (tokens.empty()) {
50 DLOG(WARNING) << "Attempting to remove a token from an empty header value " 50 DLOG(WARNING) << "Attempting to remove a token from an empty header value "
51 << "for header \"" << key << "\""; 51 << "for header \"" << key << "\"";
52 header_line->skip = true; // remove the whole line 52 header_line->skip = true; // remove the whole line
53 } else if (tokens.size() == 1) { 53 } else if (tokens.size() == 1) {
(...skipping 16 matching lines...) Expand all
70 BalsaHeaders::const_header_lines_key_iterator it = 70 BalsaHeaders::const_header_lines_key_iterator it =
71 headers.GetIteratorForKey(key); 71 headers.GetIteratorForKey(key);
72 if (it == headers.header_lines_key_end()) 72 if (it == headers.header_lines_key_end())
73 return false; 73 return false;
74 74
75 // Find the last line 75 // Find the last line
76 BalsaHeaders::const_header_lines_key_iterator header_line = it; 76 BalsaHeaders::const_header_lines_key_iterator header_line = it;
77 do { 77 do {
78 header_line = it; 78 header_line = it;
79 ++it; 79 ++it;
80 } 80 } while (it != headers.header_lines_key_end());
81 while (it != headers.header_lines_key_end());
82 81
83 // Tokenize just that line 82 // Tokenize just that line
84 BalsaHeaders::HeaderTokenList tokens; 83 BalsaHeaders::HeaderTokenList tokens;
85 ParseTokenList(header_line->second.begin(), header_line->second.end(), 84 ParseTokenList(
86 &tokens); 85 header_line->second.begin(), header_line->second.end(), &tokens);
87 86
88 return !tokens.empty() && 87 return !tokens.empty() &&
89 StringPieceUtils::StartsWithIgnoreCase(tokens.back(), token); 88 StringPieceUtils::StartsWithIgnoreCase(tokens.back(), token);
90 } 89 }
91 90
92 void BalsaHeadersTokenUtils::TokenizeHeaderValue( 91 void BalsaHeadersTokenUtils::TokenizeHeaderValue(
93 const BalsaHeaders& headers, 92 const BalsaHeaders& headers,
94 const base::StringPiece& key, 93 const base::StringPiece& key,
95 BalsaHeaders::HeaderTokenList* tokens) { 94 BalsaHeaders::HeaderTokenList* tokens) {
96 CHECK(tokens); 95 CHECK(tokens);
97 tokens->clear(); 96 tokens->clear();
98 97
99 // We may have more then 1 line with the same header key. Tokenize them all 98 // We may have more then 1 line with the same header key. Tokenize them all
100 // and stick all the tokens into the same list. 99 // and stick all the tokens into the same list.
101 for (BalsaHeaders::const_header_lines_key_iterator header_line = 100 for (BalsaHeaders::const_header_lines_key_iterator header_line =
102 headers.GetIteratorForKey(key); 101 headers.GetIteratorForKey(key);
103 header_line != headers.header_lines_key_end(); ++header_line) { 102 header_line != headers.header_lines_key_end();
104 ParseTokenList(header_line->second.begin(), header_line->second.end(), 103 ++header_line) {
105 tokens); 104 ParseTokenList(
105 header_line->second.begin(), header_line->second.end(), tokens);
106 } 106 }
107 } 107 }
108 108
109 void BalsaHeadersTokenUtils::ParseTokenList( 109 void BalsaHeadersTokenUtils::ParseTokenList(
110 const char* start, 110 const char* start,
111 const char* end, 111 const char* end,
112 BalsaHeaders::HeaderTokenList* tokens) { 112 BalsaHeaders::HeaderTokenList* tokens) {
113 if (start == end) { 113 if (start == end) {
114 return; 114 return;
115 } 115 }
(...skipping 16 matching lines...) Expand all
132 tokens->push_back(base::StringPiece(nws, start - nws)); 132 tokens->push_back(base::StringPiece(nws, start - nws));
133 } 133 }
134 return; 134 return;
135 } 135 }
136 } 136 }
137 tokens->push_back(base::StringPiece(nws, start - nws)); 137 tokens->push_back(base::StringPiece(nws, start - nws));
138 } 138 }
139 } 139 }
140 140
141 } // namespace net 141 } // namespace net
142
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698