Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / native_client_sdk / src / libraries / sdk_util / string_util.h
blob816e9651e4b9bf86c67eee98f62170f6a0df1f46
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 #ifndef LIBRARIES_SDK_UTIL_STRING_UTIL_H_
6 #define LIBRARIES_SDK_UTIL_STRING_UTIL_H_
8 #include <string>
9 #include <vector>
11 namespace sdk_util {
13 // Splits |str| into a vector of strings delimited by |c|, placing the results
14 // in |r|. If several instances of |c| are contiguous, or if |str| begins with
15 // or ends with |c|, then an empty string is inserted. If |str| is empty, then
16 // no strings are inserted.
18 // NOTE: Unlike Chrome's base::SplitString, this DOES NOT trim white space.
19 inline void SplitString(const std::string& str,
20 char c,
21 std::vector<std::string>* r) {
22 r->clear();
23 size_t last = 0;
24 size_t size = str.size();
25 for (size_t i = 0; i <= size; ++i) {
26 if (i == size || str[i] == c) {
27 std::string tmp(str, last, i - last);
28 // Avoid converting an empty source string into a vector of one empty
29 // string.
30 if (i != size || !r->empty() || !tmp.empty())
31 r->push_back(tmp);
32 last = i + 1;
37 } // namespace sdk_util
39 #endif // LIBRARIES_SDK_UTIL_STRING_UTIL_H_