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