@@ -33,14 +33,14 @@ namespace {
33
33
// - what are the constraints on LITERAL and IDENT?
34
34
// - what is the character set for the grammar?
35
35
//
36
- // Template = "/" Segments [ Verb ] ;
36
+ // Template = "/" | "/" Segments [ Verb ] ;
37
37
// Segments = Segment { "/" Segment } ;
38
38
// Segment = "*" | "**" | LITERAL | Variable ;
39
39
// Variable = "{" FieldPath [ "=" Segments ] "}" ;
40
40
// FieldPath = IDENT { "." IDENT } ;
41
41
// Verb = ":" LITERAL ;
42
42
class Parser {
43
- public:
43
+ public:
44
44
Parser (const std::string &input)
45
45
: input_(input), tb_(0 ), te_(0 ), in_variable_(false ) {}
46
46
@@ -73,7 +73,7 @@ class Parser {
73
73
return true ;
74
74
}
75
75
76
- private:
76
+ private:
77
77
// Template = "/" Segments [ Verb ] ;
78
78
bool ParseTemplate () {
79
79
if (!Consume (' /' )) {
@@ -99,7 +99,8 @@ class Parser {
99
99
}
100
100
101
101
for (;;) {
102
- if (!Consume (' /' )) break ;
102
+ if (!Consume (' /' ))
103
+ break ;
103
104
if (!ParseSegment ()) {
104
105
return false ;
105
106
}
@@ -114,25 +115,25 @@ class Parser {
114
115
return false ;
115
116
}
116
117
switch (current_char ()) {
117
- case ' *' : {
118
- Consume (' *' );
119
- if (Consume (' *' )) {
120
- // **
121
- segments_.push_back (" **" );
122
- if (in_variable_) {
123
- return MarkVariableHasWildCardPath ();
124
- }
125
- return true ;
126
- } else {
127
- segments_.push_back (" *" );
128
- return true ;
118
+ case ' *' : {
119
+ Consume (' *' );
120
+ if (Consume (' *' )) {
121
+ // **
122
+ segments_.push_back (" **" );
123
+ if (in_variable_) {
124
+ return MarkVariableHasWildCardPath ();
129
125
}
126
+ return true ;
127
+ } else {
128
+ segments_.push_back (" *" );
129
+ return true ;
130
130
}
131
+ }
131
132
132
- case ' {' :
133
- return ParseVariable ();
134
- default :
135
- return ParseLiteralSegment ();
133
+ case ' {' :
134
+ return ParseVariable ();
135
+ default :
136
+ return ParseLiteralSegment ();
136
137
}
137
138
}
138
139
@@ -188,8 +189,10 @@ class Parser {
188
189
189
190
// Verb = ":" LITERAL ;
190
191
bool ParseVerb () {
191
- if (!Consume (' :' )) return false ;
192
- if (!ParseLiteral (&verb_)) return false ;
192
+ if (!Consume (' :' ))
193
+ return false ;
194
+ if (!ParseLiteral (&verb_))
195
+ return false ;
193
196
return true ;
194
197
}
195
198
@@ -202,14 +205,14 @@ class Parser {
202
205
while (NextChar ()) {
203
206
char c;
204
207
switch (c = current_char ()) {
205
- case ' .' :
206
- case ' }' :
207
- case ' =' :
208
- return result && AddFieldIdentifier (std::move (idf));
209
- default :
210
- Consume (c);
211
- idf.push_back (c);
212
- break ;
208
+ case ' .' :
209
+ case ' }' :
210
+ case ' =' :
211
+ return result && AddFieldIdentifier (std::move (idf));
212
+ default :
213
+ Consume (c);
214
+ idf.push_back (c);
215
+ break ;
213
216
}
214
217
result = true ;
215
218
}
@@ -227,14 +230,14 @@ class Parser {
227
230
for (;;) {
228
231
char c;
229
232
switch (c = current_char ()) {
230
- case ' /' :
231
- case ' :' :
232
- case ' }' :
233
- return result;
234
- default :
235
- Consume (c);
236
- lit->push_back (c);
237
- break ;
233
+ case ' /' :
234
+ case ' :' :
235
+ case ' }' :
236
+ return result;
237
+ default :
238
+ Consume (c);
239
+ lit->push_back (c);
240
+ break ;
238
241
}
239
242
240
243
result = true ;
@@ -359,7 +362,7 @@ class Parser {
359
362
std::vector<HttpTemplate::Variable> variables_;
360
363
};
361
364
362
- } // namespace
365
+ } // namespace
363
366
364
367
const char HttpTemplate::kSingleParameterKey [] = " /." ;
365
368
@@ -368,6 +371,10 @@ const char HttpTemplate::kWildCardPathPartKey[] = "*";
368
371
const char HttpTemplate::kWildCardPathKey [] = " **" ;
369
372
370
373
std::unique_ptr<HttpTemplate> HttpTemplate::Parse (const std::string &ht) {
374
+ if (ht == " /" ) {
375
+ return std::unique_ptr<HttpTemplate>(new HttpTemplate ({}, {}, {}));
376
+ }
377
+
371
378
Parser p (ht);
372
379
if (!p.Parse () || !p.ValidateParts ()) {
373
380
return nullptr ;
@@ -377,6 +384,6 @@ std::unique_ptr<HttpTemplate> HttpTemplate::Parse(const std::string &ht) {
377
384
std::move (p.segments ()), std::move (p.verb ()), std::move (p.variables ())));
378
385
}
379
386
380
- } // namespace transcoding
381
- } // namespace grpc
382
- } // namespace google
387
+ } // namespace transcoding
388
+ } // namespace grpc
389
+ } // namespace google
0 commit comments