OLD | NEW |
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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 #include "base/strings/string_util_win.h" | 154 #include "base/strings/string_util_win.h" |
155 #elif defined(OS_POSIX) | 155 #elif defined(OS_POSIX) |
156 #include "base/strings/string_util_posix.h" | 156 #include "base/strings/string_util_posix.h" |
157 #else | 157 #else |
158 #error Define string operations appropriately for your platform | 158 #error Define string operations appropriately for your platform |
159 #endif | 159 #endif |
160 | 160 |
161 // Removes characters in |remove_chars| from anywhere in |input|. Returns true | 161 // Removes characters in |remove_chars| from anywhere in |input|. Returns true |
162 // if any characters were removed. |remove_chars| must be null-terminated. | 162 // if any characters were removed. |remove_chars| must be null-terminated. |
163 // NOTE: Safe to use the same variable for both |input| and |output|. | 163 // NOTE: Safe to use the same variable for both |input| and |output|. |
164 BASE_EXPORT bool RemoveChars(const string16& input, | 164 BASE_EXPORT bool RemoveChars(const base::string16& input, |
165 const char16 remove_chars[], | 165 const base::char16 remove_chars[], |
166 string16* output); | 166 base::string16* output); |
167 BASE_EXPORT bool RemoveChars(const std::string& input, | 167 BASE_EXPORT bool RemoveChars(const std::string& input, |
168 const char remove_chars[], | 168 const char remove_chars[], |
169 std::string* output); | 169 std::string* output); |
170 | 170 |
171 // Replaces characters in |replace_chars| from anywhere in |input| with | 171 // Replaces characters in |replace_chars| from anywhere in |input| with |
172 // |replace_with|. Each character in |replace_chars| will be replaced with | 172 // |replace_with|. Each character in |replace_chars| will be replaced with |
173 // the |replace_with| string. Returns true if any characters were replaced. | 173 // the |replace_with| string. Returns true if any characters were replaced. |
174 // |replace_chars| must be null-terminated. | 174 // |replace_chars| must be null-terminated. |
175 // NOTE: Safe to use the same variable for both |input| and |output|. | 175 // NOTE: Safe to use the same variable for both |input| and |output|. |
176 BASE_EXPORT bool ReplaceChars(const string16& input, | 176 BASE_EXPORT bool ReplaceChars(const base::string16& input, |
177 const char16 replace_chars[], | 177 const base::char16 replace_chars[], |
178 const string16& replace_with, | 178 const base::string16& replace_with, |
179 string16* output); | 179 base::string16* output); |
180 BASE_EXPORT bool ReplaceChars(const std::string& input, | 180 BASE_EXPORT bool ReplaceChars(const std::string& input, |
181 const char replace_chars[], | 181 const char replace_chars[], |
182 const std::string& replace_with, | 182 const std::string& replace_with, |
183 std::string* output); | 183 std::string* output); |
184 | 184 |
185 // Removes characters in |trim_chars| from the beginning and end of |input|. | 185 // Removes characters in |trim_chars| from the beginning and end of |input|. |
186 // |trim_chars| must be null-terminated. | 186 // |trim_chars| must be null-terminated. |
187 // NOTE: Safe to use the same variable for both |input| and |output|. | 187 // NOTE: Safe to use the same variable for both |input| and |output|. |
188 BASE_EXPORT bool TrimString(const string16& input, | 188 BASE_EXPORT bool TrimString(const base::string16& input, |
189 const char16 trim_chars[], | 189 const base::char16 trim_chars[], |
190 string16* output); | 190 base::string16* output); |
191 BASE_EXPORT bool TrimString(const std::string& input, | 191 BASE_EXPORT bool TrimString(const std::string& input, |
192 const char trim_chars[], | 192 const char trim_chars[], |
193 std::string* output); | 193 std::string* output); |
194 | 194 |
195 // Truncates a string to the nearest UTF-8 character that will leave | 195 // Truncates a string to the nearest UTF-8 character that will leave |
196 // the string less than or equal to the specified byte size. | 196 // the string less than or equal to the specified byte size. |
197 BASE_EXPORT void TruncateUTF8ToByteSize(const std::string& input, | 197 BASE_EXPORT void TruncateUTF8ToByteSize(const std::string& input, |
198 const size_t byte_size, | 198 const size_t byte_size, |
199 std::string* output); | 199 std::string* output); |
200 | 200 |
201 // Trims any whitespace from either end of the input string. Returns where | 201 // Trims any whitespace from either end of the input string. Returns where |
202 // whitespace was found. | 202 // whitespace was found. |
203 // The non-wide version has two functions: | 203 // The non-wide version has two functions: |
204 // * TrimWhitespaceASCII() | 204 // * TrimWhitespaceASCII() |
205 // This function is for ASCII strings and only looks for ASCII whitespace; | 205 // This function is for ASCII strings and only looks for ASCII whitespace; |
206 // Please choose the best one according to your usage. | 206 // Please choose the best one according to your usage. |
207 // NOTE: Safe to use the same variable for both input and output. | 207 // NOTE: Safe to use the same variable for both input and output. |
208 enum TrimPositions { | 208 enum TrimPositions { |
209 TRIM_NONE = 0, | 209 TRIM_NONE = 0, |
210 TRIM_LEADING = 1 << 0, | 210 TRIM_LEADING = 1 << 0, |
211 TRIM_TRAILING = 1 << 1, | 211 TRIM_TRAILING = 1 << 1, |
212 TRIM_ALL = TRIM_LEADING | TRIM_TRAILING, | 212 TRIM_ALL = TRIM_LEADING | TRIM_TRAILING, |
213 }; | 213 }; |
214 BASE_EXPORT TrimPositions TrimWhitespace(const string16& input, | 214 BASE_EXPORT TrimPositions TrimWhitespace(const base::string16& input, |
215 TrimPositions positions, | 215 TrimPositions positions, |
216 string16* output); | 216 base::string16* output); |
217 BASE_EXPORT TrimPositions TrimWhitespaceASCII(const std::string& input, | 217 BASE_EXPORT TrimPositions TrimWhitespaceASCII(const std::string& input, |
218 TrimPositions positions, | 218 TrimPositions positions, |
219 std::string* output); | 219 std::string* output); |
220 | 220 |
221 // Deprecated. This function is only for backward compatibility and calls | 221 // Deprecated. This function is only for backward compatibility and calls |
222 // TrimWhitespaceASCII(). | 222 // TrimWhitespaceASCII(). |
223 BASE_EXPORT TrimPositions TrimWhitespace(const std::string& input, | 223 BASE_EXPORT TrimPositions TrimWhitespace(const std::string& input, |
224 TrimPositions positions, | 224 TrimPositions positions, |
225 std::string* output); | 225 std::string* output); |
226 | 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 string16 CollapseWhitespace( | 235 BASE_EXPORT base::string16 CollapseWhitespace( |
236 const string16& text, | 236 const base::string16& text, |
237 bool trim_sequences_with_line_breaks); | 237 bool trim_sequences_with_line_breaks); |
238 BASE_EXPORT std::string CollapseWhitespaceASCII( | 238 BASE_EXPORT std::string CollapseWhitespaceASCII( |
239 const std::string& text, | 239 const std::string& text, |
240 bool trim_sequences_with_line_breaks); | 240 bool trim_sequences_with_line_breaks); |
241 | 241 |
242 // Returns true if the passed string is empty or contains only white-space | 242 // Returns true if the passed string is empty or contains only white-space |
243 // characters. | 243 // characters. |
244 BASE_EXPORT bool ContainsOnlyWhitespaceASCII(const std::string& str); | 244 BASE_EXPORT bool ContainsOnlyWhitespaceASCII(const std::string& str); |
245 BASE_EXPORT bool ContainsOnlyWhitespace(const string16& str); | 245 BASE_EXPORT bool ContainsOnlyWhitespace(const base::string16& str); |
246 | 246 |
247 // Returns true if |input| is empty or contains only characters found in | 247 // Returns true if |input| is empty or contains only characters found in |
248 // |characters|. | 248 // |characters|. |
249 BASE_EXPORT bool ContainsOnlyChars(const string16& input, | 249 BASE_EXPORT bool ContainsOnlyChars(const base::string16& input, |
250 const string16& characters); | 250 const base::string16& characters); |
251 BASE_EXPORT bool ContainsOnlyChars(const std::string& input, | 251 BASE_EXPORT bool ContainsOnlyChars(const std::string& input, |
252 const std::string& characters); | 252 const std::string& characters); |
253 | 253 |
254 // Converts to 7-bit ASCII by truncating. The result must be known to be ASCII | 254 // Converts to 7-bit ASCII by truncating. The result must be known to be ASCII |
255 // beforehand. | 255 // beforehand. |
256 BASE_EXPORT std::string WideToASCII(const std::wstring& wide); | 256 BASE_EXPORT std::string WideToASCII(const std::wstring& wide); |
257 BASE_EXPORT std::string UTF16ToASCII(const string16& utf16); | 257 BASE_EXPORT std::string UTF16ToASCII(const base::string16& utf16); |
258 | 258 |
259 // Returns true if the specified string matches the criteria. How can a wide | 259 // Returns true if the specified string matches the criteria. How can a wide |
260 // string be 8-bit or UTF8? It contains only characters that are < 256 (in the | 260 // string be 8-bit or UTF8? It contains only characters that are < 256 (in the |
261 // first case) or characters that use only 8-bits and whose 8-bit | 261 // first case) or characters that use only 8-bits and whose 8-bit |
262 // representation looks like a UTF-8 string (the second case). | 262 // representation looks like a UTF-8 string (the second case). |
263 // | 263 // |
264 // Note that IsStringUTF8 checks not only if the input is structurally | 264 // Note that IsStringUTF8 checks not only if the input is structurally |
265 // valid but also if it doesn't contain any non-character codepoint | 265 // valid but also if it doesn't contain any non-character codepoint |
266 // (e.g. U+FFFE). It's done on purpose because all the existing callers want | 266 // (e.g. U+FFFE). It's done on purpose because all the existing callers want |
267 // to have the maximum 'discriminating' power from other encodings. If | 267 // to have the maximum 'discriminating' power from other encodings. If |
268 // there's a use case for just checking the structural validity, we have to | 268 // there's a use case for just checking the structural validity, we have to |
269 // add a new function for that. | 269 // add a new function for that. |
270 BASE_EXPORT bool IsStringUTF8(const std::string& str); | 270 BASE_EXPORT bool IsStringUTF8(const std::string& str); |
271 BASE_EXPORT bool IsStringASCII(const base::StringPiece& str); | 271 BASE_EXPORT bool IsStringASCII(const base::StringPiece& str); |
272 BASE_EXPORT bool IsStringASCII(const string16& str); | 272 BASE_EXPORT bool IsStringASCII(const base::string16& str); |
273 | 273 |
274 // Converts the elements of the given string. This version uses a pointer to | 274 // Converts the elements of the given string. This version uses a pointer to |
275 // clearly differentiate it from the non-pointer variant. | 275 // clearly differentiate it from the non-pointer variant. |
276 template <class str> inline void StringToLowerASCII(str* s) { | 276 template <class str> inline void StringToLowerASCII(str* s) { |
277 for (typename str::iterator i = s->begin(); i != s->end(); ++i) | 277 for (typename str::iterator i = s->begin(); i != s->end(); ++i) |
278 *i = base::ToLowerASCII(*i); | 278 *i = base::ToLowerASCII(*i); |
279 } | 279 } |
280 | 280 |
281 template <class str> inline str StringToLowerASCII(const str& s) { | 281 template <class str> inline str StringToLowerASCII(const str& s) { |
282 // for std::string and std::wstring | 282 // for std::string and std::wstring |
(...skipping 14 matching lines...) Expand all Loading... |
297 str output(s); | 297 str output(s); |
298 StringToUpperASCII(&output); | 298 StringToUpperASCII(&output); |
299 return output; | 299 return output; |
300 } | 300 } |
301 | 301 |
302 // Compare the lower-case form of the given string against the given ASCII | 302 // Compare the lower-case form of the given string against the given ASCII |
303 // string. This is useful for doing checking if an input string matches some | 303 // string. This is useful for doing checking if an input string matches some |
304 // token, and it is optimized to avoid intermediate string copies. This API is | 304 // token, and it is optimized to avoid intermediate string copies. This API is |
305 // borrowed from the equivalent APIs in Mozilla. | 305 // borrowed from the equivalent APIs in Mozilla. |
306 BASE_EXPORT bool LowerCaseEqualsASCII(const std::string& a, const char* b); | 306 BASE_EXPORT bool LowerCaseEqualsASCII(const std::string& a, const char* b); |
307 BASE_EXPORT bool LowerCaseEqualsASCII(const string16& a, const char* b); | 307 BASE_EXPORT bool LowerCaseEqualsASCII(const base::string16& a, const char* b); |
308 | 308 |
309 // Same thing, but with string iterators instead. | 309 // Same thing, but with string iterators instead. |
310 BASE_EXPORT bool LowerCaseEqualsASCII(std::string::const_iterator a_begin, | 310 BASE_EXPORT bool LowerCaseEqualsASCII(std::string::const_iterator a_begin, |
311 std::string::const_iterator a_end, | 311 std::string::const_iterator a_end, |
312 const char* b); | 312 const char* b); |
313 BASE_EXPORT bool LowerCaseEqualsASCII(string16::const_iterator a_begin, | 313 BASE_EXPORT bool LowerCaseEqualsASCII(base::string16::const_iterator a_begin, |
314 string16::const_iterator a_end, | 314 base::string16::const_iterator a_end, |
315 const char* b); | 315 const char* b); |
316 BASE_EXPORT bool LowerCaseEqualsASCII(const char* a_begin, | 316 BASE_EXPORT bool LowerCaseEqualsASCII(const char* a_begin, |
317 const char* a_end, | 317 const char* a_end, |
318 const char* b); | 318 const char* b); |
319 BASE_EXPORT bool LowerCaseEqualsASCII(const char16* a_begin, | 319 BASE_EXPORT bool LowerCaseEqualsASCII(const base::char16* a_begin, |
320 const char16* a_end, | 320 const base::char16* a_end, |
321 const char* b); | 321 const char* b); |
322 | 322 |
323 // Performs a case-sensitive string compare. The behavior is undefined if both | 323 // Performs a case-sensitive string compare. The behavior is undefined if both |
324 // strings are not ASCII. | 324 // strings are not ASCII. |
325 BASE_EXPORT bool EqualsASCII(const string16& a, const base::StringPiece& b); | 325 BASE_EXPORT bool EqualsASCII(const base::string16& a, const base::StringPiece& b
); |
326 | 326 |
327 // Returns true if str starts with search, or false otherwise. | 327 // Returns true if str starts with search, or false otherwise. |
328 BASE_EXPORT bool StartsWithASCII(const std::string& str, | 328 BASE_EXPORT bool StartsWithASCII(const std::string& str, |
329 const std::string& search, | 329 const std::string& search, |
330 bool case_sensitive); | 330 bool case_sensitive); |
331 BASE_EXPORT bool StartsWith(const string16& str, | 331 BASE_EXPORT bool StartsWith(const base::string16& str, |
332 const string16& search, | 332 const base::string16& search, |
333 bool case_sensitive); | 333 bool case_sensitive); |
334 | 334 |
335 // Returns true if str ends with search, or false otherwise. | 335 // Returns true if str ends with search, or false otherwise. |
336 BASE_EXPORT bool EndsWith(const std::string& str, | 336 BASE_EXPORT bool EndsWith(const std::string& str, |
337 const std::string& search, | 337 const std::string& search, |
338 bool case_sensitive); | 338 bool case_sensitive); |
339 BASE_EXPORT bool EndsWith(const string16& str, | 339 BASE_EXPORT bool EndsWith(const base::string16& str, |
340 const string16& search, | 340 const base::string16& search, |
341 bool case_sensitive); | 341 bool case_sensitive); |
342 | 342 |
343 | 343 |
344 // Determines the type of ASCII character, independent of locale (the C | 344 // Determines the type of ASCII character, independent of locale (the C |
345 // library versions will change based on locale). | 345 // library versions will change based on locale). |
346 template <typename Char> | 346 template <typename Char> |
347 inline bool IsAsciiWhitespace(Char c) { | 347 inline bool IsAsciiWhitespace(Char c) { |
348 return c == ' ' || c == '\r' || c == '\n' || c == '\t'; | 348 return c == ' ' || c == '\r' || c == '\n' || c == '\t'; |
349 } | 349 } |
350 template <typename Char> | 350 template <typename Char> |
(...skipping 26 matching lines...) Expand all Loading... |
377 | 377 |
378 // Returns true if it's a whitespace character. | 378 // Returns true if it's a whitespace character. |
379 inline bool IsWhitespace(wchar_t c) { | 379 inline bool IsWhitespace(wchar_t c) { |
380 return wcschr(base::kWhitespaceWide, c) != NULL; | 380 return wcschr(base::kWhitespaceWide, c) != NULL; |
381 } | 381 } |
382 | 382 |
383 // Return a byte string in human-readable format with a unit suffix. Not | 383 // Return a byte string in human-readable format with a unit suffix. Not |
384 // appropriate for use in any UI; use of FormatBytes and friends in ui/base is | 384 // appropriate for use in any UI; use of FormatBytes and friends in ui/base is |
385 // highly recommended instead. TODO(avi): Figure out how to get callers to use | 385 // highly recommended instead. TODO(avi): Figure out how to get callers to use |
386 // FormatBytes instead; remove this. | 386 // FormatBytes instead; remove this. |
387 BASE_EXPORT string16 FormatBytesUnlocalized(int64 bytes); | 387 BASE_EXPORT base::string16 FormatBytesUnlocalized(int64 bytes); |
388 | 388 |
389 // Starting at |start_offset| (usually 0), replace the first instance of | 389 // Starting at |start_offset| (usually 0), replace the first instance of |
390 // |find_this| with |replace_with|. | 390 // |find_this| with |replace_with|. |
391 BASE_EXPORT void ReplaceFirstSubstringAfterOffset( | 391 BASE_EXPORT void ReplaceFirstSubstringAfterOffset( |
392 string16* str, | 392 base::string16* str, |
393 string16::size_type start_offset, | 393 base::string16::size_type start_offset, |
394 const string16& find_this, | 394 const base::string16& find_this, |
395 const string16& replace_with); | 395 const base::string16& replace_with); |
396 BASE_EXPORT void ReplaceFirstSubstringAfterOffset( | 396 BASE_EXPORT void ReplaceFirstSubstringAfterOffset( |
397 std::string* str, | 397 std::string* str, |
398 std::string::size_type start_offset, | 398 std::string::size_type start_offset, |
399 const std::string& find_this, | 399 const std::string& find_this, |
400 const std::string& replace_with); | 400 const std::string& replace_with); |
401 | 401 |
402 // Starting at |start_offset| (usually 0), look through |str| and replace all | 402 // Starting at |start_offset| (usually 0), look through |str| and replace all |
403 // instances of |find_this| with |replace_with|. | 403 // instances of |find_this| with |replace_with|. |
404 // | 404 // |
405 // This does entire substrings; use std::replace in <algorithm> for single | 405 // This does entire substrings; use std::replace in <algorithm> for single |
406 // characters, for example: | 406 // characters, for example: |
407 // std::replace(str.begin(), str.end(), 'a', 'b'); | 407 // std::replace(str.begin(), str.end(), 'a', 'b'); |
408 BASE_EXPORT void ReplaceSubstringsAfterOffset( | 408 BASE_EXPORT void ReplaceSubstringsAfterOffset( |
409 string16* str, | 409 base::string16* str, |
410 string16::size_type start_offset, | 410 base::string16::size_type start_offset, |
411 const string16& find_this, | 411 const base::string16& find_this, |
412 const string16& replace_with); | 412 const base::string16& replace_with); |
413 BASE_EXPORT void ReplaceSubstringsAfterOffset( | 413 BASE_EXPORT void ReplaceSubstringsAfterOffset( |
414 std::string* str, | 414 std::string* str, |
415 std::string::size_type start_offset, | 415 std::string::size_type start_offset, |
416 const std::string& find_this, | 416 const std::string& find_this, |
417 const std::string& replace_with); | 417 const std::string& replace_with); |
418 | 418 |
419 // Reserves enough memory in |str| to accommodate |length_with_null| characters, | 419 // Reserves enough memory in |str| to accommodate |length_with_null| characters, |
420 // sets the size of |str| to |length_with_null - 1| characters, and returns a | 420 // sets the size of |str| to |length_with_null - 1| characters, and returns a |
421 // pointer to the underlying contiguous array of characters. This is typically | 421 // pointer to the underlying contiguous array of characters. This is typically |
422 // used when calling a function that writes results into a character array, but | 422 // used when calling a function that writes results into a character array, but |
(...skipping 20 matching lines...) Expand all Loading... |
443 str->reserve(length_with_null); | 443 str->reserve(length_with_null); |
444 str->resize(length_with_null - 1); | 444 str->resize(length_with_null - 1); |
445 return &((*str)[0]); | 445 return &((*str)[0]); |
446 } | 446 } |
447 | 447 |
448 //----------------------------------------------------------------------------- | 448 //----------------------------------------------------------------------------- |
449 | 449 |
450 // Splits a string into its fields delimited by any of the characters in | 450 // Splits a string into its fields delimited by any of the characters in |
451 // |delimiters|. Each field is added to the |tokens| vector. Returns the | 451 // |delimiters|. Each field is added to the |tokens| vector. Returns the |
452 // number of tokens found. | 452 // number of tokens found. |
453 BASE_EXPORT size_t Tokenize(const string16& str, | 453 BASE_EXPORT size_t Tokenize(const base::string16& str, |
454 const string16& delimiters, | 454 const base::string16& delimiters, |
455 std::vector<string16>* tokens); | 455 std::vector<base::string16>* tokens); |
456 BASE_EXPORT size_t Tokenize(const std::string& str, | 456 BASE_EXPORT size_t Tokenize(const std::string& str, |
457 const std::string& delimiters, | 457 const std::string& delimiters, |
458 std::vector<std::string>* tokens); | 458 std::vector<std::string>* tokens); |
459 BASE_EXPORT size_t Tokenize(const base::StringPiece& str, | 459 BASE_EXPORT size_t Tokenize(const base::StringPiece& str, |
460 const base::StringPiece& delimiters, | 460 const base::StringPiece& delimiters, |
461 std::vector<base::StringPiece>* tokens); | 461 std::vector<base::StringPiece>* tokens); |
462 | 462 |
463 // Does the opposite of SplitString(). | 463 // Does the opposite of SplitString(). |
464 BASE_EXPORT string16 JoinString(const std::vector<string16>& parts, char16 s); | 464 BASE_EXPORT base::string16 JoinString(const std::vector<base::string16>& parts, |
| 465 base::char16 s); |
465 BASE_EXPORT std::string JoinString( | 466 BASE_EXPORT std::string JoinString( |
466 const std::vector<std::string>& parts, char s); | 467 const std::vector<std::string>& parts, char s); |
467 | 468 |
468 // Join |parts| using |separator|. | 469 // Join |parts| using |separator|. |
469 BASE_EXPORT std::string JoinString( | 470 BASE_EXPORT std::string JoinString( |
470 const std::vector<std::string>& parts, | 471 const std::vector<std::string>& parts, |
471 const std::string& separator); | 472 const std::string& separator); |
472 BASE_EXPORT string16 JoinString( | 473 BASE_EXPORT base::string16 JoinString( |
473 const std::vector<string16>& parts, | 474 const std::vector<base::string16>& parts, |
474 const string16& separator); | 475 const base::string16& separator); |
475 | 476 |
476 // Replace $1-$2-$3..$9 in the format string with |a|-|b|-|c|..|i| respectively. | 477 // Replace $1-$2-$3..$9 in the format string with |a|-|b|-|c|..|i| respectively. |
477 // Additionally, any number of consecutive '$' characters is replaced by that | 478 // Additionally, any number of consecutive '$' characters is replaced by that |
478 // number less one. Eg $$->$, $$$->$$, etc. The offsets parameter here can be | 479 // number less one. Eg $$->$, $$$->$$, etc. The offsets parameter here can be |
479 // NULL. This only allows you to use up to nine replacements. | 480 // NULL. This only allows you to use up to nine replacements. |
480 BASE_EXPORT string16 ReplaceStringPlaceholders( | 481 BASE_EXPORT base::string16 ReplaceStringPlaceholders( |
481 const string16& format_string, | 482 const base::string16& format_string, |
482 const std::vector<string16>& subst, | 483 const std::vector<base::string16>& subst, |
483 std::vector<size_t>* offsets); | 484 std::vector<size_t>* offsets); |
484 | 485 |
485 BASE_EXPORT std::string ReplaceStringPlaceholders( | 486 BASE_EXPORT std::string ReplaceStringPlaceholders( |
486 const base::StringPiece& format_string, | 487 const base::StringPiece& format_string, |
487 const std::vector<std::string>& subst, | 488 const std::vector<std::string>& subst, |
488 std::vector<size_t>* offsets); | 489 std::vector<size_t>* offsets); |
489 | 490 |
490 // Single-string shortcut for ReplaceStringHolders. |offset| may be NULL. | 491 // Single-string shortcut for ReplaceStringHolders. |offset| may be NULL. |
491 BASE_EXPORT string16 ReplaceStringPlaceholders(const string16& format_string, | 492 BASE_EXPORT base::string16 ReplaceStringPlaceholders( |
492 const string16& a, | 493 const base::string16& format_string, |
493 size_t* offset); | 494 const base::string16& a, |
| 495 size_t* offset); |
494 | 496 |
495 // Returns true if the string passed in matches the pattern. The pattern | 497 // Returns true if the string passed in matches the pattern. The pattern |
496 // string can contain wildcards like * and ? | 498 // string can contain wildcards like * and ? |
497 // The backslash character (\) is an escape character for * and ? | 499 // The backslash character (\) is an escape character for * and ? |
498 // We limit the patterns to having a max of 16 * or ? characters. | 500 // We limit the patterns to having a max of 16 * or ? characters. |
499 // ? matches 0 or 1 character, while * matches 0 or more characters. | 501 // ? matches 0 or 1 character, while * matches 0 or more characters. |
500 BASE_EXPORT bool MatchPattern(const base::StringPiece& string, | 502 BASE_EXPORT bool MatchPattern(const base::StringPiece& string, |
501 const base::StringPiece& pattern); | 503 const base::StringPiece& pattern); |
502 BASE_EXPORT bool MatchPattern(const string16& string, const string16& pattern); | 504 BASE_EXPORT bool MatchPattern(const base::string16& string, |
| 505 const base::string16& pattern); |
503 | 506 |
504 // Hack to convert any char-like type to its unsigned counterpart. | 507 // Hack to convert any char-like type to its unsigned counterpart. |
505 // For example, it will convert char, signed char and unsigned char to unsigned | 508 // For example, it will convert char, signed char and unsigned char to unsigned |
506 // char. | 509 // char. |
507 template<typename T> | 510 template<typename T> |
508 struct ToUnsigned { | 511 struct ToUnsigned { |
509 typedef T Unsigned; | 512 typedef T Unsigned; |
510 }; | 513 }; |
511 | 514 |
512 template<> | 515 template<> |
(...skipping 11 matching lines...) Expand all Loading... |
524 #elif defined(WCHAR_T_IS_UTF32) | 527 #elif defined(WCHAR_T_IS_UTF32) |
525 typedef uint32 Unsigned; | 528 typedef uint32 Unsigned; |
526 #endif | 529 #endif |
527 }; | 530 }; |
528 template<> | 531 template<> |
529 struct ToUnsigned<short> { | 532 struct ToUnsigned<short> { |
530 typedef unsigned short Unsigned; | 533 typedef unsigned short Unsigned; |
531 }; | 534 }; |
532 | 535 |
533 #endif // BASE_STRINGS_STRING_UTIL_H_ | 536 #endif // BASE_STRINGS_STRING_UTIL_H_ |
OLD | NEW |