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_
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
,
21 std::vector
<std::string
>* r
) {
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
30 if (i
!= size
|| !r
->empty() || !tmp
.empty())
37 } // namespace sdk_util
39 #endif // LIBRARIES_SDK_UTIL_STRING_UTIL_H_