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

Side by Side Diff: base/string_util.h

Issue 275019: Re-attempt r28993... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | « no previous file | base/string_util.cc » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // This file defines utility functions for working with strings. 5 // This file defines utility functions for working with strings.
6 6
7 #ifndef BASE_STRING_UTIL_H_ 7 #ifndef BASE_STRING_UTIL_H_
8 #define BASE_STRING_UTIL_H_ 8 #define BASE_STRING_UTIL_H_
9 9
10 #include <stdarg.h> // va_list 10 #include <stdarg.h> // va_list
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 // Returns a reference to a globally unique empty string that functions can 114 // Returns a reference to a globally unique empty string that functions can
115 // return. Use this to avoid static construction of strings, not to replace 115 // return. Use this to avoid static construction of strings, not to replace
116 // any and all uses of "std::string()" as nicer-looking sugar. 116 // any and all uses of "std::string()" as nicer-looking sugar.
117 // These functions are threadsafe. 117 // These functions are threadsafe.
118 const std::string& EmptyString(); 118 const std::string& EmptyString();
119 const std::wstring& EmptyWString(); 119 const std::wstring& EmptyWString();
120 const string16& EmptyString16(); 120 const string16& EmptyString16();
121 121
122 extern const wchar_t kWhitespaceWide[]; 122 extern const wchar_t kWhitespaceWide[];
123 extern const char16 kWhitespaceUTF16[];
123 extern const char kWhitespaceASCII[]; 124 extern const char kWhitespaceASCII[];
124 125
125 // Removes characters in trim_chars from the beginning and end of input. 126 // Removes characters in trim_chars from the beginning and end of input.
126 // NOTE: Safe to use the same variable for both input and output. 127 // NOTE: Safe to use the same variable for both input and output.
127 bool TrimString(const std::wstring& input, 128 bool TrimString(const std::wstring& input,
128 const wchar_t trim_chars[], 129 const wchar_t trim_chars[],
129 std::wstring* output); 130 std::wstring* output);
131 bool TrimString(const string16& input,
132 const char16 trim_chars[],
133 string16* output);
130 bool TrimString(const std::string& input, 134 bool TrimString(const std::string& input,
131 const char trim_chars[], 135 const char trim_chars[],
132 std::string* output); 136 std::string* output);
133 137
134 // Trims any whitespace from either end of the input string. Returns where 138 // Trims any whitespace from either end of the input string. Returns where
135 // whitespace was found. 139 // whitespace was found.
136 // The non-wide version has two functions: 140 // The non-wide version has two functions:
137 // * TrimWhitespaceASCII() 141 // * TrimWhitespaceASCII()
138 // This function is for ASCII strings and only looks for ASCII whitespace; 142 // This function is for ASCII strings and only looks for ASCII whitespace;
139 // Please choose the best one according to your usage. 143 // Please choose the best one according to your usage.
140 // NOTE: Safe to use the same variable for both input and output. 144 // NOTE: Safe to use the same variable for both input and output.
141 enum TrimPositions { 145 enum TrimPositions {
142 TRIM_NONE = 0, 146 TRIM_NONE = 0,
143 TRIM_LEADING = 1 << 0, 147 TRIM_LEADING = 1 << 0,
144 TRIM_TRAILING = 1 << 1, 148 TRIM_TRAILING = 1 << 1,
145 TRIM_ALL = TRIM_LEADING | TRIM_TRAILING, 149 TRIM_ALL = TRIM_LEADING | TRIM_TRAILING,
146 }; 150 };
147 TrimPositions TrimWhitespace(const std::wstring& input, 151 TrimPositions TrimWhitespace(const std::wstring& input,
148 TrimPositions positions, 152 TrimPositions positions,
149 std::wstring* output); 153 std::wstring* output);
154 TrimPositions TrimWhitespace(const string16& input,
155 TrimPositions positions,
156 string16* output);
150 TrimPositions TrimWhitespaceASCII(const std::string& input, 157 TrimPositions TrimWhitespaceASCII(const std::string& input,
151 TrimPositions positions, 158 TrimPositions positions,
152 std::string* output); 159 std::string* output);
153 160
154 // Deprecated. This function is only for backward compatibility and calls 161 // Deprecated. This function is only for backward compatibility and calls
155 // TrimWhitespaceASCII(). 162 // TrimWhitespaceASCII().
156 TrimPositions TrimWhitespace(const std::string& input, 163 TrimPositions TrimWhitespace(const std::string& input,
157 TrimPositions positions, 164 TrimPositions positions,
158 std::string* output); 165 std::string* output);
159 166
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 #elif defined(WCHAR_T_IS_UTF32) 581 #elif defined(WCHAR_T_IS_UTF32)
575 typedef uint32 Unsigned; 582 typedef uint32 Unsigned;
576 #endif 583 #endif
577 }; 584 };
578 template<> 585 template<>
579 struct ToUnsigned<short> { 586 struct ToUnsigned<short> {
580 typedef unsigned short Unsigned; 587 typedef unsigned short Unsigned;
581 }; 588 };
582 589
583 #endif // BASE_STRING_UTIL_H_ 590 #endif // BASE_STRING_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/string_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698