summaryrefslogtreecommitdiffstats
path: root/net/tools/flip_server/split.cc
diff options
context:
space:
mode:
authormbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-13 23:09:16 +0000
committermbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-13 23:09:16 +0000
commit8be62535d5dc911d6594b55c3c9fbfe27bacb142 (patch)
treeedb872299ed250a2f54427b20f1ea1eb236eeffa /net/tools/flip_server/split.cc
parent59f9bfeec0da4208c39f52f0eb356094d89008a3 (diff)
downloadchromium_src-8be62535d5dc911d6594b55c3c9fbfe27bacb142.zip
chromium_src-8be62535d5dc911d6594b55c3c9fbfe27bacb142.tar.gz
chromium_src-8be62535d5dc911d6594b55c3c9fbfe27bacb142.tar.bz2
More changes intended to make flip_in_mem_edsm_server.cc compile and run
in the chrome tree. Checkin for Roberto Peon (fenix@google.com) BUG=none TEST=none Review URL: http://codereview.chromium.org/543029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36187 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools/flip_server/split.cc')
-rw-r--r--net/tools/flip_server/split.cc70
1 files changed, 70 insertions, 0 deletions
diff --git a/net/tools/flip_server/split.cc b/net/tools/flip_server/split.cc
new file mode 100644
index 0000000..7e3329a
--- /dev/null
+++ b/net/tools/flip_server/split.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string.h>
+
+#include <vector>
+
+#include "base/string_piece.h"
+
+namespace net {
+
+// Yea, this could be done with less code duplication using
+// template magic, I know.
+void SplitStringPieceToVector(const base::StringPiece& full,
+ const char* delim,
+ std::vector<base::StringPiece>* vec,
+ bool omit_empty_strings) {
+ vec->clear();
+ if (full.size() == 0 || delim[0] == '\0')
+ return;
+
+ if (delim[1] == '\0') {
+ base::StringPiece::const_iterator s = full.begin();
+ base::StringPiece::const_iterator e = s;
+ for (;e != full.end(); ++e) {
+ if (*e == delim[0]) {
+ if (e != s || !omit_empty_strings) {
+ vec->push_back(base::StringPiece(s, e - s));
+ }
+ s = e;
+ ++s;
+ }
+ }
+ if (s != e) {
+ --e;
+ if (e != s || !omit_empty_strings) {
+ vec->push_back(base::StringPiece(s, e - s));
+ }
+ }
+ } else {
+ base::StringPiece::const_iterator s = full.begin();
+ base::StringPiece::const_iterator e = s;
+ for (;e != full.end(); ++e) {
+ bool one_matched = false;
+ for (const char *d = delim; *d != '\0'; ++d) {
+ if (*d == *e) {
+ one_matched = true;
+ break;
+ }
+ }
+ if (one_matched) {
+ if (e != s || !omit_empty_strings) {
+ vec->push_back(base::StringPiece(s, e - s));
+ }
+ s = e;
+ ++s;
+ }
+ }
+ if (s != e) {
+ --e;
+ if (e != s || !omit_empty_strings) {
+ vec->push_back(base::StringPiece(s, e - s));
+ }
+ }
+ }
+}
+
+} // namespace net
+