Skip to content

Commit 3619e7d

Browse files
authored
Fix split to absl::StrSplit. (#98)
Fix split to absl::StrSplit.
1 parent ff41eb3 commit 3619e7d

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/include/grpc_transcoding/path_matcher.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "http_template.h"
2626
#include "path_matcher_node.h"
2727
#include "percent_encoding.h"
28+
#include "absl/strings/str_split.h"
2829

2930
namespace google {
3031
namespace grpc {
@@ -172,16 +173,6 @@ class PathMatcherBuilder {
172173

173174
namespace {
174175

175-
std::vector<std::string>& split(const std::string& s, char delim,
176-
std::vector<std::string>& elems) {
177-
std::stringstream ss(s);
178-
std::string item;
179-
while (std::getline(ss, item, delim)) {
180-
elems.push_back(item);
181-
}
182-
return elems;
183-
}
184-
185176
template <class VariableBinding>
186177
void ExtractBindingsFromPath(const std::vector<HttpTemplate::Variable>& vars,
187178
const std::vector<std::string>& parts,
@@ -229,8 +220,7 @@ void ExtractBindingsFromQueryParameters(
229220
// Query parameters may also contain system parameters such as `api_key`.
230221
// We'll need to ignore these. Example:
231222
// book.id=123&book.author=Neal%20Stephenson&api_key=AIzaSyAz7fhBkC35D2M
232-
std::vector<std::string> params;
233-
split(query_params, '&', params);
223+
std::vector<std::string> params = absl::StrSplit(query_params, '&');
234224
for (const auto& param : params) {
235225
size_t pos = param.find('=');
236226
if (pos != 0 && pos != std::string::npos) {
@@ -242,7 +232,7 @@ void ExtractBindingsFromQueryParameters(
242232
// sequence of field names that identify the (potentially deep) field
243233
// in the request, e.g. `book.author.name`.
244234
VariableBinding binding;
245-
split(name, '.', binding.field_path);
235+
binding.field_path = absl::StrSplit(name, '.');
246236
binding.value = UrlUnescapeString(param.substr(pos + 1),
247237
UrlUnescapeSpec::kAllCharacters,
248238
query_param_unescape_plus);
@@ -286,7 +276,7 @@ std::vector<std::string> ExtractRequestParts(
286276

287277
std::vector<std::string> result;
288278
if (path.size() > 0) {
289-
split(path.substr(1), '/', result);
279+
result = absl::StrSplit(path.substr(1), '/');
290280
}
291281
// Removes all trailing empty parts caused by extra "/".
292282
while (!result.empty() && (*(--result.end())).empty()) {

0 commit comments

Comments
 (0)