Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / tools / balsa / split.cc
blob20be430d7310f260b01ccc249d672a069774dc7b
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
3 // found in the LICENSE file.
5 #include "net/tools/balsa/split.h"
7 #include <string.h>
9 #include <vector>
11 #include "base/strings/string_piece.h"
13 namespace net {
15 // Yea, this could be done with less code duplication using
16 // template magic, I know.
17 void SplitStringPieceToVector(const base::StringPiece& full,
18 const char* delim,
19 std::vector<base::StringPiece>* vec,
20 bool omit_empty_strings) {
21 vec->clear();
22 if (full.empty() || delim[0] == '\0')
23 return;
25 if (delim[1] == '\0') {
26 base::StringPiece::const_iterator s = full.begin();
27 base::StringPiece::const_iterator e = s;
28 for (;e != full.end(); ++e) {
29 if (*e == delim[0]) {
30 if (e != s || !omit_empty_strings) {
31 vec->push_back(base::StringPiece(s, e - s));
33 s = e;
34 ++s;
37 if (s != e) {
38 --e;
39 if (e != s || !omit_empty_strings) {
40 vec->push_back(base::StringPiece(s, e - s));
43 } else {
44 base::StringPiece::const_iterator s = full.begin();
45 base::StringPiece::const_iterator e = s;
46 for (;e != full.end(); ++e) {
47 bool one_matched = false;
48 for (const char *d = delim; *d != '\0'; ++d) {
49 if (*d == *e) {
50 one_matched = true;
51 break;
54 if (one_matched) {
55 if (e != s || !omit_empty_strings) {
56 vec->push_back(base::StringPiece(s, e - s));
58 s = e;
59 ++s;
62 if (s != e) {
63 --e;
64 if (e != s || !omit_empty_strings) {
65 vec->push_back(base::StringPiece(s, e - s));
71 } // namespace net