OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 // The original source code is from: | |
6 // http://src.chromium.org/viewvc/chrome/trunk/src/base/strings/string_split.cc?
revision=216633 | |
7 | |
8 #include "string_split.h" | |
9 | |
10 #include <cassert> | |
11 #include <cstddef> | |
12 #include <string> | |
13 #include <vector> | |
14 | |
15 namespace i18n { | |
16 namespace addressinput { | |
17 | |
18 void SplitString(const std::string& str, char s, std::vector<std::string>* r) { | |
19 assert(r != NULL); | |
20 r->clear(); | |
21 size_t last = 0; | |
22 size_t c = str.size(); | |
23 for (size_t i = 0; i <= c; ++i) { | |
24 if (i == c || str[i] == s) { | |
25 std::string tmp(str, last, i - last); | |
26 // Avoid converting an empty or all-whitespace source string into a vector | |
27 // of one empty string. | |
28 if (i != c || !r->empty() || !tmp.empty()) { | |
29 r->push_back(tmp); | |
30 } | |
31 last = i + 1; | |
32 } | |
33 } | |
34 } | |
35 | |
36 } // namespace addressinput | |
37 } // namespace i18n | |
OLD | NEW |