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

Side by Side Diff: base/strings/string_util.h

Issue 183853011: Move TrimWhitespace to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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/process/process_metrics_linux.cc ('k') | base/strings/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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_STRINGS_STRING_UTIL_H_ 7 #ifndef BASE_STRINGS_STRING_UTIL_H_
8 #define BASE_STRINGS_STRING_UTIL_H_ 8 #define BASE_STRINGS_STRING_UTIL_H_
9 9
10 #include <ctype.h> 10 #include <ctype.h>
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 BASE_EXPORT bool TrimString(const std::string& input, 181 BASE_EXPORT bool TrimString(const std::string& input,
182 const char trim_chars[], 182 const char trim_chars[],
183 std::string* output); 183 std::string* output);
184 184
185 // Truncates a string to the nearest UTF-8 character that will leave 185 // Truncates a string to the nearest UTF-8 character that will leave
186 // the string less than or equal to the specified byte size. 186 // the string less than or equal to the specified byte size.
187 BASE_EXPORT void TruncateUTF8ToByteSize(const std::string& input, 187 BASE_EXPORT void TruncateUTF8ToByteSize(const std::string& input,
188 const size_t byte_size, 188 const size_t byte_size,
189 std::string* output); 189 std::string* output);
190 190
191 } // namespace base
192
193 #if defined(OS_WIN)
194 #include "base/strings/string_util_win.h"
195 #elif defined(OS_POSIX)
196 #include "base/strings/string_util_posix.h"
197 #else
198 #error Define string operations appropriately for your platform
199 #endif
200
201 // Trims any whitespace from either end of the input string. Returns where 191 // Trims any whitespace from either end of the input string. Returns where
202 // whitespace was found. 192 // whitespace was found.
203 // The non-wide version has two functions: 193 // The non-wide version has two functions:
204 // * TrimWhitespaceASCII() 194 // * TrimWhitespaceASCII()
205 // This function is for ASCII strings and only looks for ASCII whitespace; 195 // This function is for ASCII strings and only looks for ASCII whitespace;
206 // Please choose the best one according to your usage. 196 // Please choose the best one according to your usage.
207 // NOTE: Safe to use the same variable for both input and output. 197 // NOTE: Safe to use the same variable for both input and output.
208 enum TrimPositions { 198 enum TrimPositions {
209 TRIM_NONE = 0, 199 TRIM_NONE = 0,
210 TRIM_LEADING = 1 << 0, 200 TRIM_LEADING = 1 << 0,
211 TRIM_TRAILING = 1 << 1, 201 TRIM_TRAILING = 1 << 1,
212 TRIM_ALL = TRIM_LEADING | TRIM_TRAILING, 202 TRIM_ALL = TRIM_LEADING | TRIM_TRAILING,
213 }; 203 };
214 BASE_EXPORT TrimPositions TrimWhitespace(const base::string16& input, 204 BASE_EXPORT TrimPositions TrimWhitespace(const string16& input,
215 TrimPositions positions, 205 TrimPositions positions,
216 base::string16* output); 206 base::string16* output);
217 BASE_EXPORT TrimPositions TrimWhitespaceASCII(const std::string& input, 207 BASE_EXPORT TrimPositions TrimWhitespaceASCII(const std::string& input,
218 TrimPositions positions, 208 TrimPositions positions,
219 std::string* output); 209 std::string* output);
220 210
221 // Deprecated. This function is only for backward compatibility and calls 211 // Deprecated. This function is only for backward compatibility and calls
222 // TrimWhitespaceASCII(). 212 // TrimWhitespaceASCII().
223 BASE_EXPORT TrimPositions TrimWhitespace(const std::string& input, 213 BASE_EXPORT TrimPositions TrimWhitespace(const std::string& input,
224 TrimPositions positions, 214 TrimPositions positions,
225 std::string* output); 215 std::string* output);
226 216
217 } // namespace base
218
219 #if defined(OS_WIN)
220 #include "base/strings/string_util_win.h"
221 #elif defined(OS_POSIX)
222 #include "base/strings/string_util_posix.h"
223 #else
224 #error Define string operations appropriately for your platform
225 #endif
226
227 // Searches for CR or LF characters. Removes all contiguous whitespace 227 // Searches for CR or LF characters. Removes all contiguous whitespace
228 // strings that contain them. This is useful when trying to deal with text 228 // strings that contain them. This is useful when trying to deal with text
229 // copied from terminals. 229 // copied from terminals.
230 // Returns |text|, with the following three transformations: 230 // Returns |text|, with the following three transformations:
231 // (1) Leading and trailing whitespace is trimmed. 231 // (1) Leading and trailing whitespace is trimmed.
232 // (2) If |trim_sequences_with_line_breaks| is true, any other whitespace 232 // (2) If |trim_sequences_with_line_breaks| is true, any other whitespace
233 // sequences containing a CR or LF are trimmed. 233 // sequences containing a CR or LF are trimmed.
234 // (3) All other whitespace sequences are converted to single spaces. 234 // (3) All other whitespace sequences are converted to single spaces.
235 BASE_EXPORT base::string16 CollapseWhitespace( 235 BASE_EXPORT base::string16 CollapseWhitespace(
236 const base::string16& text, 236 const base::string16& text,
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 #elif defined(WCHAR_T_IS_UTF32) 527 #elif defined(WCHAR_T_IS_UTF32)
528 typedef uint32 Unsigned; 528 typedef uint32 Unsigned;
529 #endif 529 #endif
530 }; 530 };
531 template<> 531 template<>
532 struct ToUnsigned<short> { 532 struct ToUnsigned<short> {
533 typedef unsigned short Unsigned; 533 typedef unsigned short Unsigned;
534 }; 534 };
535 535
536 #endif // BASE_STRINGS_STRING_UTIL_H_ 536 #endif // BASE_STRINGS_STRING_UTIL_H_
OLDNEW
« no previous file with comments | « base/process/process_metrics_linux.cc ('k') | base/strings/string_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698