OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_STRING_SPLIT_H_ | 5 #ifndef BASE_STRING_SPLIT_H_ |
6 #define BASE_STRING_SPLIT_H_ | 6 #define BASE_STRING_SPLIT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 | 14 |
| 15 // TODO(tfarina): Move the following functions into the namespace and update the |
| 16 // callers. |
| 17 //----------------------------------------------------------------------------- |
| 18 |
| 19 // Splits |str| into a vector of strings delimited by |s|. Append the results |
| 20 // into |r| as they appear. If several instances of |s| are contiguous, or if |
| 21 // |str| begins with or ends with |s|, then an empty string is inserted. |
| 22 // |
| 23 // Every substring is trimmed of any leading or trailing white space. |
| 24 // Where wchar_t is char16 (i.e. Windows), |c| must be in BMP |
| 25 // (Basic Multilingual Plane). Elsewhere (Linux/Mac), wchar_t |
| 26 // should be a valid Unicode code point (32-bit). |
| 27 void SplitString(const std::wstring& str, |
| 28 wchar_t c, |
| 29 std::vector<std::wstring>* r); |
| 30 // NOTE: |c| must be in BMP (Basic Multilingual Plane) |
| 31 void SplitString(const string16& str, |
| 32 char16 c, |
| 33 std::vector<string16>* r); |
| 34 // |str| should not be in a multi-byte encoding like Shift-JIS or GBK in which |
| 35 // the trailing byte of a multi-byte character can be in the ASCII range. |
| 36 // UTF-8, and other single/multi-byte ASCII-compatible encodings are OK. |
| 37 // Note: |c| must be in the ASCII range. |
| 38 void SplitString(const std::string& str, |
| 39 char c, |
| 40 std::vector<std::string>* r); |
| 41 |
15 namespace base { | 42 namespace base { |
16 | 43 |
17 bool SplitStringIntoKeyValues( | 44 bool SplitStringIntoKeyValues( |
18 const std::string& line, | 45 const std::string& line, |
19 char key_value_delimiter, | 46 char key_value_delimiter, |
20 std::string* key, std::vector<std::string>* values); | 47 std::string* key, std::vector<std::string>* values); |
21 | 48 |
22 bool SplitStringIntoKeyValuePairs( | 49 bool SplitStringIntoKeyValuePairs( |
23 const std::string& line, | 50 const std::string& line, |
24 char key_value_delimiter, | 51 char key_value_delimiter, |
(...skipping 23 matching lines...) Expand all Loading... |
48 // the trailing byte of a multi-byte character can be in the ASCII range. | 75 // the trailing byte of a multi-byte character can be in the ASCII range. |
49 // UTF-8, and other single/multi-byte ASCII-compatible encodings are OK. | 76 // UTF-8, and other single/multi-byte ASCII-compatible encodings are OK. |
50 // Note: |c| must be in the ASCII range. | 77 // Note: |c| must be in the ASCII range. |
51 void SplitStringDontTrim(const std::string& str, | 78 void SplitStringDontTrim(const std::string& str, |
52 char c, | 79 char c, |
53 std::vector<std::string>* r); | 80 std::vector<std::string>* r); |
54 | 81 |
55 } // namespace base | 82 } // namespace base |
56 | 83 |
57 #endif // BASE_STRING_SPLIT_H | 84 #endif // BASE_STRING_SPLIT_H |
OLD | NEW |