OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef BASE_I18N_ICU_STRING_CONVERSIONS_H_ | 5 #ifndef BASE_I18N_ICU_STRING_CONVERSIONS_H_ |
6 #define BASE_I18N_ICU_STRING_CONVERSIONS_H_ | 6 #define BASE_I18N_ICU_STRING_CONVERSIONS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 private: | 33 private: |
34 OnStringConversionError(); | 34 OnStringConversionError(); |
35 }; | 35 }; |
36 | 36 |
37 // Names of codepages (charsets) understood by icu. | 37 // Names of codepages (charsets) understood by icu. |
38 extern const char kCodepageLatin1[]; // a.k.a. ISO 8859-1 | 38 extern const char kCodepageLatin1[]; // a.k.a. ISO 8859-1 |
39 extern const char kCodepageUTF8[]; | 39 extern const char kCodepageUTF8[]; |
40 extern const char kCodepageUTF16BE[]; | 40 extern const char kCodepageUTF16BE[]; |
41 extern const char kCodepageUTF16LE[]; | 41 extern const char kCodepageUTF16LE[]; |
42 | 42 |
| 43 // Like CodepageToUTF16() (see below), but also takes an offset into |encoded|, |
| 44 // which will be adjusted to point at the same logical place in |utf16|. If |
| 45 // this isn't possible because it points past the end of |encoded| or into the |
| 46 // middle of a multibyte sequence, it will be set to std::string16::npos. |
| 47 // |offset_for_adjustment| may be NULL. |
| 48 bool CodepageToUTF16AndAdjustOffset(const std::string& encoded, |
| 49 const char* codepage_name, |
| 50 OnStringConversionError::Type on_error, |
| 51 string16* utf16, |
| 52 size_t* offset_for_adjustment); |
| 53 |
43 // Converts between UTF-16 strings and the encoding specified. If the | 54 // Converts between UTF-16 strings and the encoding specified. If the |
44 // encoding doesn't exist or the encoding fails (when on_error is FAIL), | 55 // encoding doesn't exist or the encoding fails (when on_error is FAIL), |
45 // returns false. | 56 // returns false. |
46 bool UTF16ToCodepage(const string16& utf16, | 57 bool UTF16ToCodepage(const string16& utf16, |
47 const char* codepage_name, | 58 const char* codepage_name, |
48 OnStringConversionError::Type on_error, | 59 OnStringConversionError::Type on_error, |
49 std::string* encoded); | 60 std::string* encoded); |
| 61 inline bool CodepageToUTF16(const std::string& encoded, |
| 62 const char* codepage_name, |
| 63 OnStringConversionError::Type on_error, |
| 64 string16* utf16) { |
| 65 return CodepageToUTF16AndAdjustOffset(encoded, codepage_name, on_error, utf16, |
| 66 NULL); |
| 67 } |
50 | 68 |
51 bool CodepageToUTF16(const std::string& encoded, | 69 // Like CodepageToWide() (see below), but also takes an offset into |encoded|, |
52 const char* codepage_name, | 70 // which will be adjusted to point at the same logical place in |wide|. If |
53 OnStringConversionError::Type on_error, | 71 // this isn't possible because it points past the end of |encoded| or into the |
54 string16* utf16); | 72 // middle of a multibyte sequence, it will be set to std::wstring::npos. |
| 73 // |offset_for_adjustment| may be NULL. |
| 74 bool CodepageToWideAndAdjustOffset(const std::string& encoded, |
| 75 const char* codepage_name, |
| 76 OnStringConversionError::Type on_error, |
| 77 std::wstring* wide, |
| 78 size_t* offset_for_adjustment); |
55 | 79 |
56 // Converts between wide strings and the encoding specified. If the | 80 // Converts between wide strings and the encoding specified. If the |
57 // encoding doesn't exist or the encoding fails (when on_error is FAIL), | 81 // encoding doesn't exist or the encoding fails (when on_error is FAIL), |
58 // returns false. | 82 // returns false. |
59 bool WideToCodepage(const std::wstring& wide, | 83 bool WideToCodepage(const std::wstring& wide, |
60 const char* codepage_name, | 84 const char* codepage_name, |
61 OnStringConversionError::Type on_error, | 85 OnStringConversionError::Type on_error, |
62 std::string* encoded); | 86 std::string* encoded); |
63 bool CodepageToWide(const std::string& encoded, | 87 inline bool CodepageToWide(const std::string& encoded, |
64 const char* codepage_name, | 88 const char* codepage_name, |
65 OnStringConversionError::Type on_error, | 89 OnStringConversionError::Type on_error, |
66 std::wstring* wide); | 90 std::wstring* wide) { |
| 91 return CodepageToWideAndAdjustOffset(encoded, codepage_name, on_error, wide, |
| 92 NULL); |
| 93 } |
67 | 94 |
68 } // namespace base | 95 } // namespace base |
69 | 96 |
70 #endif // BASE_I18N_ICU_STRING_CONVERSIONS_H_ | 97 #endif // BASE_I18N_ICU_STRING_CONVERSIONS_H_ |
OLD | NEW |