| 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 #include "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <math.h> | 9 #include <math.h> |
| 10 #include <stdarg.h> | 10 #include <stdarg.h> |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // Portable, keep scanning the rest of the format string. | 93 // Portable, keep scanning the rest of the format string. |
| 94 in_specification = false; | 94 in_specification = false; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace base | |
| 104 | |
| 105 | |
| 106 const std::string& EmptyString() { | 103 const std::string& EmptyString() { |
| 107 return EmptyStrings::GetInstance()->s; | 104 return EmptyStrings::GetInstance()->s; |
| 108 } | 105 } |
| 109 | 106 |
| 110 const std::wstring& EmptyWString() { | 107 const std::wstring& EmptyWString() { |
| 111 return EmptyStrings::GetInstance()->ws; | 108 return EmptyStrings::GetInstance()->ws; |
| 112 } | 109 } |
| 113 | 110 |
| 114 const string16& EmptyString16() { | 111 const string16& EmptyString16() { |
| 115 return EmptyStrings::GetInstance()->s16; | 112 return EmptyStrings::GetInstance()->s16; |
| 116 } | 113 } |
| 117 | 114 |
| 115 } // namespace base |
| 116 |
| 118 template<typename STR> | 117 template<typename STR> |
| 119 bool ReplaceCharsT(const STR& input, | 118 bool ReplaceCharsT(const STR& input, |
| 120 const typename STR::value_type replace_chars[], | 119 const typename STR::value_type replace_chars[], |
| 121 const STR& replace_with, | 120 const STR& replace_with, |
| 122 STR* output) { | 121 STR* output) { |
| 123 bool removed = false; | 122 bool removed = false; |
| 124 size_t replace_length = replace_with.length(); | 123 size_t replace_length = replace_with.length(); |
| 125 | 124 |
| 126 *output = input; | 125 *output = input; |
| 127 | 126 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 break; | 233 break; |
| 235 } | 234 } |
| 236 } | 235 } |
| 237 | 236 |
| 238 if (char_index >= 0 ) | 237 if (char_index >= 0 ) |
| 239 *output = input.substr(0, char_index); | 238 *output = input.substr(0, char_index); |
| 240 else | 239 else |
| 241 output->clear(); | 240 output->clear(); |
| 242 } | 241 } |
| 243 | 242 |
| 244 TrimPositions TrimWhitespace(const string16& input, | 243 TrimPositions TrimWhitespace(const base::string16& input, |
| 245 TrimPositions positions, | 244 TrimPositions positions, |
| 246 string16* output) { | 245 base::string16* output) { |
| 247 return TrimStringT(input, kWhitespaceUTF16, positions, output); | 246 return TrimStringT(input, base::kWhitespaceUTF16, positions, output); |
| 248 } | 247 } |
| 249 | 248 |
| 250 TrimPositions TrimWhitespaceASCII(const std::string& input, | 249 TrimPositions TrimWhitespaceASCII(const std::string& input, |
| 251 TrimPositions positions, | 250 TrimPositions positions, |
| 252 std::string* output) { | 251 std::string* output) { |
| 253 return TrimStringT(input, kWhitespaceASCII, positions, output); | 252 return TrimStringT(input, base::kWhitespaceASCII, positions, output); |
| 254 } | 253 } |
| 255 | 254 |
| 256 // This function is only for backward-compatibility. | 255 // This function is only for backward-compatibility. |
| 257 // To be removed when all callers are updated. | 256 // To be removed when all callers are updated. |
| 258 TrimPositions TrimWhitespace(const std::string& input, | 257 TrimPositions TrimWhitespace(const std::string& input, |
| 259 TrimPositions positions, | 258 TrimPositions positions, |
| 260 std::string* output) { | 259 std::string* output) { |
| 261 return TrimWhitespaceASCII(input, positions, output); | 260 return TrimWhitespaceASCII(input, positions, output); |
| 262 } | 261 } |
| 263 | 262 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 313 } |
| 315 | 314 |
| 316 bool ContainsOnlyWhitespaceASCII(const std::string& str) { | 315 bool ContainsOnlyWhitespaceASCII(const std::string& str) { |
| 317 for (std::string::const_iterator i(str.begin()); i != str.end(); ++i) { | 316 for (std::string::const_iterator i(str.begin()); i != str.end(); ++i) { |
| 318 if (!IsAsciiWhitespace(*i)) | 317 if (!IsAsciiWhitespace(*i)) |
| 319 return false; | 318 return false; |
| 320 } | 319 } |
| 321 return true; | 320 return true; |
| 322 } | 321 } |
| 323 | 322 |
| 324 bool ContainsOnlyWhitespace(const string16& str) { | 323 bool ContainsOnlyWhitespace(const base::string16& str) { |
| 325 return str.find_first_not_of(kWhitespaceUTF16) == string16::npos; | 324 return str.find_first_not_of(base::kWhitespaceUTF16) == string16::npos; |
| 326 } | 325 } |
| 327 | 326 |
| 328 template<typename STR> | 327 template<typename STR> |
| 329 static bool ContainsOnlyCharsT(const STR& input, const STR& characters) { | 328 static bool ContainsOnlyCharsT(const STR& input, const STR& characters) { |
| 330 for (typename STR::const_iterator iter = input.begin(); | 329 for (typename STR::const_iterator iter = input.begin(); |
| 331 iter != input.end(); ++iter) { | 330 iter != input.end(); ++iter) { |
| 332 if (characters.find(*iter) == STR::npos) | 331 if (characters.find(*iter) == STR::npos) |
| 333 return false; | 332 return false; |
| 334 } | 333 } |
| 335 return true; | 334 return true; |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 } | 924 } |
| 926 | 925 |
| 927 } // namespace | 926 } // namespace |
| 928 | 927 |
| 929 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { | 928 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { |
| 930 return lcpyT<char>(dst, src, dst_size); | 929 return lcpyT<char>(dst, src, dst_size); |
| 931 } | 930 } |
| 932 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { | 931 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { |
| 933 return lcpyT<wchar_t>(dst, src, dst_size); | 932 return lcpyT<wchar_t>(dst, src, dst_size); |
| 934 } | 933 } |
| OLD | NEW |