OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_STRINGS_STRING_SPLIT_H_ | 5 #ifndef BASE_STRINGS_STRING_SPLIT_H_ |
6 #define BASE_STRINGS_STRING_SPLIT_H_ | 6 #define BASE_STRINGS_STRING_SPLIT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 // Splits |str| into a vector of strings delimited by |c|, placing the results | 17 // Splits |str| into a vector of strings delimited by |c|, placing the results |
18 // in |r|. If several instances of |c| are contiguous, or if |str| begins with | 18 // in |r|. If several instances of |c| are contiguous, or if |str| begins with |
19 // or ends with |c|, then an empty string is inserted. | 19 // or ends with |c|, then an empty string is inserted. |
20 // | 20 // |
21 // Every substring is trimmed of any leading or trailing white space. | 21 // Every substring is trimmed of any leading or trailing white space. |
22 // NOTE: |c| must be in BMP (Basic Multilingual Plane) | 22 // NOTE: |c| must be in BMP (Basic Multilingual Plane) |
23 BASE_EXPORT void SplitString(const string16& str, | 23 BASE_EXPORT void SplitString(const string16& str, |
24 char16 c, | 24 char16 c, |
25 std::vector<string16>* r); | 25 std::vector<string16>* r); |
26 | |
26 // |str| should not be in a multi-byte encoding like Shift-JIS or GBK in which | 27 // |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 // 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 // UTF-8, and other single/multi-byte ASCII-compatible encodings are OK. |
29 // Note: |c| must be in the ASCII range. | 30 // Note: |c| must be in the ASCII range. |
30 BASE_EXPORT void SplitString(const std::string& str, | 31 BASE_EXPORT void SplitString(const std::string& str, |
31 char c, | 32 char c, |
32 std::vector<std::string>* r); | 33 std::vector<std::string>* r); |
33 | 34 |
34 BASE_EXPORT bool SplitStringIntoKeyValues(const std::string& line, | 35 typedef std::vector<std::pair<std::string, std::string> > StringPairs; |
Mark Mentovai
2014/03/06 17:55:51
The CL description should say that this is going a
pneubeck (no reviews)
2014/03/07 17:12:11
Done.
| |
35 char key_value_delimiter, | |
36 std::string* key, | |
37 std::vector<std::string>* values); | |
38 | 36 |
39 typedef std::vector<std::pair<std::string, std::string> > StringPairs;; | 37 // Splits |line| into key value pairs according to the given delimiters and |
40 | 38 // removes whitespace leading each key and trailing each value. Returns true |
41 BASE_EXPORT bool SplitStringIntoKeyValuePairs( | 39 // only if each pair has a non-empty key and value. |key_value_pairs| will |
42 const std::string& line, | 40 // include ("","") pairs for entries without |key_value_delimiter|. |
43 char key_value_delimiter, | 41 BASE_EXPORT bool SplitStringIntoKeyValuePairs(const std::string& line, |
44 char key_value_pair_delimiter, | 42 char key_value_delimiter, |
45 StringPairs* key_value_pairs); | 43 char key_value_pair_delimiter, |
44 StringPairs* key_value_pairs); | |
46 | 45 |
47 // The same as SplitString, but use a substring delimiter instead of a char. | 46 // The same as SplitString, but use a substring delimiter instead of a char. |
48 BASE_EXPORT void SplitStringUsingSubstr(const string16& str, | 47 BASE_EXPORT void SplitStringUsingSubstr(const string16& str, |
49 const string16& s, | 48 const string16& s, |
50 std::vector<string16>* r); | 49 std::vector<string16>* r); |
51 BASE_EXPORT void SplitStringUsingSubstr(const std::string& str, | 50 BASE_EXPORT void SplitStringUsingSubstr(const std::string& str, |
52 const std::string& s, | 51 const std::string& s, |
53 std::vector<std::string>* r); | 52 std::vector<std::string>* r); |
54 | 53 |
55 // The same as SplitString, but don't trim white space. | 54 // The same as SplitString, but don't trim white space. |
(...skipping 18 matching lines...) Expand all Loading... | |
74 // characters defined by HTML 5). Each contiguous block of non-whitespace | 73 // characters defined by HTML 5). Each contiguous block of non-whitespace |
75 // characters is added to result. | 74 // characters is added to result. |
76 BASE_EXPORT void SplitStringAlongWhitespace(const string16& str, | 75 BASE_EXPORT void SplitStringAlongWhitespace(const string16& str, |
77 std::vector<string16>* result); | 76 std::vector<string16>* result); |
78 BASE_EXPORT void SplitStringAlongWhitespace(const std::string& str, | 77 BASE_EXPORT void SplitStringAlongWhitespace(const std::string& str, |
79 std::vector<std::string>* result); | 78 std::vector<std::string>* result); |
80 | 79 |
81 } // namespace base | 80 } // namespace base |
82 | 81 |
83 #endif // BASE_STRINGS_STRING_SPLIT_H_ | 82 #endif // BASE_STRINGS_STRING_SPLIT_H_ |
OLD | NEW |