1 // Copyright 2017 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #include "string_piece_util.h"
22 vector<StringPiece> SplitStringPiece(StringPiece input, char sep) {
23 vector<StringPiece> elems;
24 elems.reserve(count(input.begin(), input.end(), sep) + 1);
26 StringPiece::const_iterator pos = input.begin();
29 const char* next_pos = find(pos, input.end(), sep);
30 if (next_pos == input.end()) {
31 elems.push_back(StringPiece(pos, input.end() - pos));
34 elems.push_back(StringPiece(pos, next_pos - pos));
41 string JoinStringPiece(const vector<StringPiece>& list, char sep) {
49 size_t cap = list.size() - 1;
50 for (size_t i = 0; i < list.size(); ++i) {
56 for (size_t i = 0; i < list.size(); ++i) {
60 ret.append(list[i].str_, list[i].len_);
66 bool EqualsCaseInsensitiveASCII(StringPiece a, StringPiece b) {
67 if (a.len_ != b.len_) {
71 for (size_t i = 0; i < a.len_; ++i) {
72 if (ToLowerASCII(a.str_[i]) != ToLowerASCII(b.str_[i])) {