Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Unified Diff: base/string_util.h

Issue 151065: Fix the local file listing and FTP file listing. For the former, use the OS f... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/string_util_icu.cc » ('j') | base/string_util_icu.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/string_util.h
===================================================================
--- base/string_util.h (revision 20014)
+++ base/string_util.h (working copy)
@@ -221,7 +221,8 @@
# define UTF16ToWideHack UTF16ToWide
#endif
-// Defines the error handling modes of WideToCodepage and CodepageToWide.
+// Defines the error handling modes of UTF16ToCodepage, CodepageToUTF16,
+// WideToCodepage and CodepageToWide.
class OnStringUtilConversionError {
public:
enum Type {
@@ -231,15 +232,48 @@
// The offending characters are skipped and the conversion will proceed as
// if they did not exist.
SKIP,
+
+ // When converting to Unicode, the offending byte sequences are substituted
+ // by Unicode replacement character (U+FFFD). When converting from Unicode,
+ // this is the same as SKIP.
+ SUBSTITUTE,
};
private:
OnStringUtilConversionError();
};
+// Converts between UTF-16 strings and the encoding specified. If the
+// encoding doesn't exist or the encoding fails (when on_error is FAIL),
+// returns false.
+bool UTF16ToCodepage(const string16& utf16,
+ const char* codepage_name,
+ OnStringUtilConversionError::Type on_error,
+ std::string* encoded);
+
+bool CodepageToUTF16(const std::string& encoded,
+ const char* codepage_name,
+ OnStringUtilConversionError::Type on_error,
+ string16* utf16);
+
// Converts between wide strings and the encoding specified. If the
// encoding doesn't exist or the encoding fails (when on_error is FAIL),
// returns false.
+#if defined(WCHAR_T_IS_UTF16)
+inline bool WideToCodepage(const std::wstring& wide,
brettw 2009/07/07 19:59:48 I think I would prefer just to have these defined
+ const char* codepage_name,
+ OnStringUtilConversionError::Type on_error,
+ std::string* encoded) {
+ return UTF16ToCodepage(wide, codepage_name, on_error, encoded);
+}
+
+inline bool CodepageToWide(const std::string& encoded,
+ const char* codepage_name,
+ OnStringUtilConversionError::Type on_error,
+ std::wstring* wide) {
+ return CodepageToUTF16(encoded, codepage_name, on_error, wide);
+}
+#elif defined(WCHAR_T_IS_UTF32)
bool WideToCodepage(const std::wstring& wide,
const char* codepage_name,
OnStringUtilConversionError::Type on_error,
@@ -248,6 +282,9 @@
const char* codepage_name,
OnStringUtilConversionError::Type on_error,
std::wstring* wide);
+#else
+#error wchar_t should be either UTF-16 or UTF-32
+#endif
// Converts the given wide string to the corresponding Latin1. This will fail
// (return false) if any characters are more than 255.
« no previous file with comments | « no previous file | base/string_util_icu.cc » ('j') | base/string_util_icu.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698