OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 9 #pragma once |
10 | 10 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 bool ContainsOnlyWhitespaceASCII(const std::string& str); | 220 bool ContainsOnlyWhitespaceASCII(const std::string& str); |
221 bool ContainsOnlyWhitespace(const string16& str); | 221 bool ContainsOnlyWhitespace(const string16& str); |
222 | 222 |
223 // Returns true if |input| is empty or contains only characters found in | 223 // Returns true if |input| is empty or contains only characters found in |
224 // |characters|. | 224 // |characters|. |
225 bool ContainsOnlyChars(const std::wstring& input, | 225 bool ContainsOnlyChars(const std::wstring& input, |
226 const std::wstring& characters); | 226 const std::wstring& characters); |
227 bool ContainsOnlyChars(const string16& input, const string16& characters); | 227 bool ContainsOnlyChars(const string16& input, const string16& characters); |
228 bool ContainsOnlyChars(const std::string& input, const std::string& characters); | 228 bool ContainsOnlyChars(const std::string& input, const std::string& characters); |
229 | 229 |
230 // These convert between ASCII (7-bit) and Wide/UTF16 strings. | 230 // Converts to 7-bit ASCII by truncating. The result must be known to be ASCII |
| 231 // beforehand. |
231 std::string WideToASCII(const std::wstring& wide); | 232 std::string WideToASCII(const std::wstring& wide); |
232 std::wstring ASCIIToWide(const base::StringPiece& ascii); | |
233 std::string UTF16ToASCII(const string16& utf16); | 233 std::string UTF16ToASCII(const string16& utf16); |
234 string16 ASCIIToUTF16(const base::StringPiece& ascii); | 234 |
| 235 // Forward-declares for functions in utf_string_conversions.h. They used to |
| 236 // be here and they were moved. We keep these here so the entire project |
| 237 // doesn't need to be switched at once. |
| 238 // TODO(brettw) delete these when everybody includes utf_string_conversions.h |
| 239 // instead. |
| 240 std::wstring ASCIIToWide(const char* ascii); |
| 241 std::wstring ASCIIToWide(const std::string& ascii); |
| 242 string16 ASCIIToUTF16(const char* ascii); |
| 243 string16 ASCIIToUTF16(const std::string& ascii); |
235 | 244 |
236 // Converts the given wide string to the corresponding Latin1. This will fail | 245 // Converts the given wide string to the corresponding Latin1. This will fail |
237 // (return false) if any characters are more than 255. | 246 // (return false) if any characters are more than 255. |
238 bool WideToLatin1(const std::wstring& wide, std::string* latin1); | 247 bool WideToLatin1(const std::wstring& wide, std::string* latin1); |
239 | 248 |
240 // Returns true if the specified string matches the criteria. How can a wide | 249 // Returns true if the specified string matches the criteria. How can a wide |
241 // string be 8-bit or UTF8? It contains only characters that are < 256 (in the | 250 // string be 8-bit or UTF8? It contains only characters that are < 256 (in the |
242 // first case) or characters that use only 8-bits and whose 8-bit | 251 // first case) or characters that use only 8-bits and whose 8-bit |
243 // representation looks like a UTF-8 string (the second case). | 252 // representation looks like a UTF-8 string (the second case). |
244 // | 253 // |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 #elif defined(WCHAR_T_IS_UTF32) | 705 #elif defined(WCHAR_T_IS_UTF32) |
697 typedef uint32 Unsigned; | 706 typedef uint32 Unsigned; |
698 #endif | 707 #endif |
699 }; | 708 }; |
700 template<> | 709 template<> |
701 struct ToUnsigned<short> { | 710 struct ToUnsigned<short> { |
702 typedef unsigned short Unsigned; | 711 typedef unsigned short Unsigned; |
703 }; | 712 }; |
704 | 713 |
705 #endif // BASE_STRING_UTIL_H_ | 714 #endif // BASE_STRING_UTIL_H_ |
OLD | NEW |