diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-01 00:13:10 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-01 00:13:10 +0000 |
commit | 656e3b3857e315a4a6386944fb140ef202580f77 (patch) | |
tree | 37fc49db14f3b43a03da33ef58dddfff9b58be2f /base/string_util.h | |
parent | 660efb2db208d7a64e04eebad1e0e1dd7b54f3b0 (diff) | |
download | chromium_src-656e3b3857e315a4a6386944fb140ef202580f77.zip chromium_src-656e3b3857e315a4a6386944fb140ef202580f77.tar.gz chromium_src-656e3b3857e315a4a6386944fb140ef202580f77.tar.bz2 |
Write our own utf8<->wide conversion functions. This gives us more control over error handling instead of getting a blank string for invalid encodings. It also allows us to decrease the amount of platform-specific code.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util.h')
-rw-r--r-- | base/string_util.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/base/string_util.h b/base/string_util.h index e5fd147..340a7eb 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -155,9 +155,15 @@ std::wstring CollapseWhitespace(const std::wstring& text, std::string WideToASCII(const std::wstring& wide); std::wstring ASCIIToWide(const std::string& ascii); -// These convert between UTF8 and UTF16 strings. They are potentially slow, -// so avoid unnecessary conversions. Most things should be in UTF16. +// These convert between UTF8 and UTF16 strings. They are potentially slow, so +// avoid unnecessary conversions. Most things should be in wide. The low-level +// versions return a boolean indicating whether the conversion was 100% valid. +// In this case, it will still do the best it can and put the result in the +// output buffer. The versions that return strings ignore this error and just +// return the best conversion possible. +bool WideToUTF8(const wchar_t* src, size_t src_len, std::string* output); std::string WideToUTF8(const std::wstring& wide); +bool UTF8ToWide(const char* src, size_t src_len, std::wstring* output); std::wstring UTF8ToWide(const std::string& utf8); // Converts between wide strings and whatever the native multibyte encoding |