Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: base/string_split.h

Issue 6729002: Base: A few more files using BASE_API (for base.dll) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/sha2.h ('k') | base/sys_string_conversions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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/base_api.h"
13 #include "base/string16.h" 14 #include "base/string16.h"
14 15
15 namespace base { 16 namespace base {
16 17
17 // Splits |str| into a vector of strings delimited by |s|. Append the results 18 // Splits |str| into a vector of strings delimited by |s|. Append the results
18 // into |r| as they appear. If several instances of |s| are contiguous, or if 19 // into |r| as they appear. If several instances of |s| are contiguous, or if
19 // |str| begins with or ends with |s|, then an empty string is inserted. 20 // |str| begins with or ends with |s|, then an empty string is inserted.
20 // 21 //
21 // Every substring is trimmed of any leading or trailing white space. 22 // Every substring is trimmed of any leading or trailing white space.
22 // Where wchar_t is char16 (i.e. Windows), |c| must be in BMP 23 // Where wchar_t is char16 (i.e. Windows), |c| must be in BMP
23 // (Basic Multilingual Plane). Elsewhere (Linux/Mac), wchar_t 24 // (Basic Multilingual Plane). Elsewhere (Linux/Mac), wchar_t
24 // should be a valid Unicode code point (32-bit). 25 // should be a valid Unicode code point (32-bit).
25 void SplitString(const std::wstring& str, 26 BASE_API void SplitString(const std::wstring& str,
26 wchar_t c, 27 wchar_t c,
27 std::vector<std::wstring>* r); 28 std::vector<std::wstring>* r);
28 // NOTE: |c| must be in BMP (Basic Multilingual Plane) 29 // NOTE: |c| must be in BMP (Basic Multilingual Plane)
29 void SplitString(const string16& str, 30 BASE_API void SplitString(const string16& str,
30 char16 c, 31 char16 c,
31 std::vector<string16>* r); 32 std::vector<string16>* r);
32 // |str| should not be in a multi-byte encoding like Shift-JIS or GBK in which 33 // |str| should not be in a multi-byte encoding like Shift-JIS or GBK in which
33 // the trailing byte of a multi-byte character can be in the ASCII range. 34 // the trailing byte of a multi-byte character can be in the ASCII range.
34 // UTF-8, and other single/multi-byte ASCII-compatible encodings are OK. 35 // UTF-8, and other single/multi-byte ASCII-compatible encodings are OK.
35 // Note: |c| must be in the ASCII range. 36 // Note: |c| must be in the ASCII range.
36 void SplitString(const std::string& str, 37 BASE_API void SplitString(const std::string& str,
37 char c, 38 char c,
38 std::vector<std::string>* r); 39 std::vector<std::string>* r);
39 40
40 bool SplitStringIntoKeyValues( 41 BASE_API bool SplitStringIntoKeyValues(
41 const std::string& line, 42 const std::string& line,
42 char key_value_delimiter, 43 char key_value_delimiter,
43 std::string* key, std::vector<std::string>* values); 44 std::string* key, std::vector<std::string>* values);
44 45
45 bool SplitStringIntoKeyValuePairs( 46 BASE_API bool SplitStringIntoKeyValuePairs(
46 const std::string& line, 47 const std::string& line,
47 char key_value_delimiter, 48 char key_value_delimiter,
48 char key_value_pair_delimiter, 49 char key_value_pair_delimiter,
49 std::vector<std::pair<std::string, std::string> >* kv_pairs); 50 std::vector<std::pair<std::string, std::string> >* kv_pairs);
50 51
51 // The same as SplitString, but use a substring delimiter instead of a char. 52 // The same as SplitString, but use a substring delimiter instead of a char.
52 void SplitStringUsingSubstr(const string16& str, 53 BASE_API void SplitStringUsingSubstr(const string16& str,
53 const string16& s, 54 const string16& s,
54 std::vector<string16>* r); 55 std::vector<string16>* r);
55 void SplitStringUsingSubstr(const std::string& str, 56 BASE_API void SplitStringUsingSubstr(const std::string& str,
56 const std::string& s, 57 const std::string& s,
57 std::vector<std::string>* r); 58 std::vector<std::string>* r);
58 59
59 // The same as SplitString, but don't trim white space. 60 // The same as SplitString, but don't trim white space.
60 // NOTE: |c| must be in BMP (Basic Multilingual Plane) 61 // NOTE: |c| must be in BMP (Basic Multilingual Plane)
61 void SplitStringDontTrim(const string16& str, 62 BASE_API void SplitStringDontTrim(const string16& str,
62 char16 c, 63 char16 c,
63 std::vector<string16>* r); 64 std::vector<string16>* r);
64 // |str| should not be in a multi-byte encoding like Shift-JIS or GBK in which 65 // |str| should not be in a multi-byte encoding like Shift-JIS or GBK in which
65 // the trailing byte of a multi-byte character can be in the ASCII range. 66 // the trailing byte of a multi-byte character can be in the ASCII range.
66 // UTF-8, and other single/multi-byte ASCII-compatible encodings are OK. 67 // UTF-8, and other single/multi-byte ASCII-compatible encodings are OK.
67 // Note: |c| must be in the ASCII range. 68 // Note: |c| must be in the ASCII range.
68 void SplitStringDontTrim(const std::string& str, 69 BASE_API void SplitStringDontTrim(const std::string& str,
69 char c, 70 char c,
70 std::vector<std::string>* r); 71 std::vector<std::string>* r);
71 72
72 // WARNING: this uses whitespace as defined by the HTML5 spec. If you need 73 // WARNING: this uses whitespace as defined by the HTML5 spec. If you need
73 // a function similar to this but want to trim all types of whitespace, then 74 // a function similar to this but want to trim all types of whitespace, then
74 // factor this out into a function that takes a string containing the characters 75 // factor this out into a function that takes a string containing the characters
75 // that are treated as whitespace. 76 // that are treated as whitespace.
76 // 77 //
77 // Splits the string along whitespace (where whitespace is the five space 78 // Splits the string along whitespace (where whitespace is the five space
78 // characters defined by HTML 5). Each contiguous block of non-whitespace 79 // characters defined by HTML 5). Each contiguous block of non-whitespace
79 // characters is added to result. 80 // characters is added to result.
80 void SplitStringAlongWhitespace(const std::wstring& str, 81 BASE_API void SplitStringAlongWhitespace(const std::wstring& str,
81 std::vector<std::wstring>* result); 82 std::vector<std::wstring>* result);
82 void SplitStringAlongWhitespace(const string16& str, 83 BASE_API void SplitStringAlongWhitespace(const string16& str,
83 std::vector<string16>* result); 84 std::vector<string16>* result);
84 void SplitStringAlongWhitespace(const std::string& str, 85 BASE_API void SplitStringAlongWhitespace(const std::string& str,
85 std::vector<std::string>* result); 86 std::vector<std::string>* result);
86 87
87 } // namespace base 88 } // namespace base
88 89
89 #endif // BASE_STRING_SPLIT_H 90 #endif // BASE_STRING_SPLIT_H
OLDNEW
« no previous file with comments | « base/sha2.h ('k') | base/sys_string_conversions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698