1 // Copyright (c) 2012 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 BASE_STRING_SPLIT_H_
6 #define BASE_STRING_SPLIT_H_
12 #include "base/base_export.h"
13 #include "base/string16.h"
17 // Splits |str| into a vector of strings delimited by |s|, placing the results
18 // in |r|. If several instances of |s| are contiguous, or if |str| begins with
19 // or ends with |s|, then an empty string is inserted.
21 // Every substring is trimmed of any leading or trailing white space.
22 // NOTE: |c| must be in BMP (Basic Multilingual Plane)
23 BASE_EXPORT
void SplitString(const string16
& str
,
25 std::vector
<string16
>* r
);
26 // |str| should not be in a multi-byte encoding like Shift-JIS or GBK in which
27 // the trailing byte of a multi-byte character can be in the ASCII range.
28 // UTF-8, and other single/multi-byte ASCII-compatible encodings are OK.
29 // Note: |c| must be in the ASCII range.
30 BASE_EXPORT
void SplitString(const std::string
& str
,
32 std::vector
<std::string
>* r
);
34 BASE_EXPORT
bool SplitStringIntoKeyValues(
35 const std::string
& line
,
36 char key_value_delimiter
,
37 std::string
* key
, std::vector
<std::string
>* values
);
39 BASE_EXPORT
bool SplitStringIntoKeyValuePairs(
40 const std::string
& line
,
41 char key_value_delimiter
,
42 char key_value_pair_delimiter
,
43 std::vector
<std::pair
<std::string
, std::string
> >* kv_pairs
);
45 // The same as SplitString, but use a substring delimiter instead of a char.
46 BASE_EXPORT
void SplitStringUsingSubstr(const string16
& str
,
48 std::vector
<string16
>* r
);
49 BASE_EXPORT
void SplitStringUsingSubstr(const std::string
& str
,
51 std::vector
<std::string
>* r
);
53 // The same as SplitString, but don't trim white space.
54 // NOTE: |c| must be in BMP (Basic Multilingual Plane)
55 BASE_EXPORT
void SplitStringDontTrim(const string16
& str
,
57 std::vector
<string16
>* r
);
58 // |str| should not be in a multi-byte encoding like Shift-JIS or GBK in which
59 // the trailing byte of a multi-byte character can be in the ASCII range.
60 // UTF-8, and other single/multi-byte ASCII-compatible encodings are OK.
61 // Note: |c| must be in the ASCII range.
62 BASE_EXPORT
void SplitStringDontTrim(const std::string
& str
,
64 std::vector
<std::string
>* r
);
66 // WARNING: this uses whitespace as defined by the HTML5 spec. If you need
67 // a function similar to this but want to trim all types of whitespace, then
68 // factor this out into a function that takes a string containing the characters
69 // that are treated as whitespace.
71 // Splits the string along whitespace (where whitespace is the five space
72 // characters defined by HTML 5). Each contiguous block of non-whitespace
73 // characters is added to result.
74 BASE_EXPORT
void SplitStringAlongWhitespace(const string16
& str
,
75 std::vector
<string16
>* result
);
76 BASE_EXPORT
void SplitStringAlongWhitespace(const std::string
& str
,
77 std::vector
<std::string
>* result
);
81 #endif // BASE_STRING_SPLIT_H