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

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

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « net/tools/balsa/split.h ('k') | net/tools/balsa/string_piece_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "net/tools/balsa/split.h"
6
7 #include <string.h>
8
9 #include <vector>
10
11 #include "base/strings/string_piece.h"
12
13 namespace net {
14
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;
24
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));
32 }
33 s = e;
34 ++s;
35 }
36 }
37 if (s != e) {
38 --e;
39 if (e != s || !omit_empty_strings) {
40 vec->push_back(base::StringPiece(s, e - s));
41 }
42 }
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;
52 }
53 }
54 if (one_matched) {
55 if (e != s || !omit_empty_strings) {
56 vec->push_back(base::StringPiece(s, e - s));
57 }
58 s = e;
59 ++s;
60 }
61 }
62 if (s != e) {
63 --e;
64 if (e != s || !omit_empty_strings) {
65 vec->push_back(base::StringPiece(s, e - s));
66 }
67 }
68 }
69 }
70
71 } // namespace net
72
OLDNEW
« no previous file with comments | « net/tools/balsa/split.h ('k') | net/tools/balsa/string_piece_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698