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 | |
54 // Converts between UTF-16 strings and the encoding specified. If the | 43 // Converts between UTF-16 strings and the encoding specified. If the |
55 // encoding doesn't exist or the encoding fails (when on_error is FAIL), | 44 // encoding doesn't exist or the encoding fails (when on_error is FAIL), |
56 // returns false. | 45 // returns false. |
57 bool UTF16ToCodepage(const string16& utf16, | 46 bool UTF16ToCodepage(const string16& utf16, |
58 const char* codepage_name, | 47 const char* codepage_name, |
59 OnStringConversionError::Type on_error, | 48 OnStringConversionError::Type on_error, |
60 std::string* encoded); | 49 std::string* encoded); |
61 inline bool CodepageToUTF16(const std::string& encoded, | 50 bool CodepageToUTF16(const std::string& encoded, |
62 const char* codepage_name, | 51 const char* codepage_name, |
63 OnStringConversionError::Type on_error, | 52 OnStringConversionError::Type on_error, |
64 string16* utf16) { | 53 string16* utf16); |
65 return CodepageToUTF16AndAdjustOffset(encoded, codepage_name, on_error, utf16, | |
66 NULL); | |
67 } | |
68 | |
69 // Like CodepageToWide() (see below), but also takes an offset into |encoded|, | |
70 // which will be adjusted to point at the same logical place in |wide|. If | |
71 // this isn't possible because it points past the end of |encoded| or into the | |
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); | |
79 | 54 |
80 // Converts between wide strings and the encoding specified. If the | 55 // Converts between wide strings and the encoding specified. If the |
81 // encoding doesn't exist or the encoding fails (when on_error is FAIL), | 56 // encoding doesn't exist or the encoding fails (when on_error is FAIL), |
82 // returns false. | 57 // returns false. |
83 bool WideToCodepage(const std::wstring& wide, | 58 bool WideToCodepage(const std::wstring& wide, |
84 const char* codepage_name, | 59 const char* codepage_name, |
85 OnStringConversionError::Type on_error, | 60 OnStringConversionError::Type on_error, |
86 std::string* encoded); | 61 std::string* encoded); |
87 inline bool CodepageToWide(const std::string& encoded, | 62 bool CodepageToWide(const std::string& encoded, |
88 const char* codepage_name, | 63 const char* codepage_name, |
89 OnStringConversionError::Type on_error, | 64 OnStringConversionError::Type on_error, |
90 std::wstring* wide) { | 65 std::wstring* wide); |
91 return CodepageToWideAndAdjustOffset(encoded, codepage_name, on_error, wide, | |
92 NULL); | |
93 } | |
94 | 66 |
95 } // namespace base | 67 } // namespace base |
96 | 68 |
97 #endif // BASE_I18N_ICU_STRING_CONVERSIONS_H_ | 69 #endif // BASE_I18N_ICU_STRING_CONVERSIONS_H_ |
OLD | NEW |