summaryrefslogtreecommitdiffstats
path: root/base/utf_string_conversions.h
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-07 01:34:53 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-07 01:34:53 +0000
commitce85f60cd9d399109dab39fe5a9613879ab9a8f7 (patch)
tree0e9e0072d2e5eadfeec08eef0f06a43c56dc1751 /base/utf_string_conversions.h
parentd90684d0cf0aa16389c9202153c97d373829b7f3 (diff)
downloadchromium_src-ce85f60cd9d399109dab39fe5a9613879ab9a8f7.zip
chromium_src-ce85f60cd9d399109dab39fe5a9613879ab9a8f7.tar.gz
chromium_src-ce85f60cd9d399109dab39fe5a9613879ab9a8f7.tar.bz2
Fix various problems with inline autocomplete and URLs that change length during fixup:
* URLs with http auth info, which gets stripped * URLs with IDN hosts * URLs with escaped values that get unescaped In cases like these, we'd inline autocomplete from the wrong locations, highlight the wrong portions of the URL as matches, and sometimes DCHECK() in debug mode. The fix is to track how fixup affects the offsets into the URL we care about. Plumbing this required an enormous number of additions :( There is also a fix here to the URL Fixer Upper, which was obviously modified at some point in the past to use the Parsed components, but without updating the comments or some of the functionality to match. Since this isn't supposed to "fix up" things that aren't simple typos, I removed some code to "fix" bogus ports, which was causing bizarre effects when typing HTTP auth URLs ("http://foo:bar" would be fixed to "http://foo" and then matched for inline autocompletion, which was clearly wrong). This is tested incidentally by one of the new History URL Provider tests (which is how I discovered it). BUG=4010 TEST=Covered by unittests Review URL: http://codereview.chromium.org/372017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31352 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/utf_string_conversions.h')
-rw-r--r--base/utf_string_conversions.h68
1 files changed, 59 insertions, 9 deletions
diff --git a/base/utf_string_conversions.h b/base/utf_string_conversions.h
index 89846ed..323233b 100644
--- a/base/utf_string_conversions.h
+++ b/base/utf_string_conversions.h
@@ -10,6 +10,37 @@
#include "base/string16.h"
#include "base/string_piece.h"
+// Like the conversions below, but also takes an offset into the source string,
+// which will be adjusted to point at the same logical place in the result
+// string. If this isn't possible because it points past the end of the source
+// string or into the middle of a multibyte sequence, it will be set to
+// std::wstring::npos. |offset_for_adjustment| may be NULL.
+bool WideToUTF8AndAdjustOffset(const wchar_t* src,
+ size_t src_len,
+ std::string* output,
+ size_t* offset_for_adjustment);
+std::string WideToUTF8AndAdjustOffset(const std::wstring& wide,
+ size_t* offset_for_adjustment);
+bool UTF8ToWideAndAdjustOffset(const char* src,
+ size_t src_len,
+ std::wstring* output,
+ size_t* offset_for_adjustment);
+std::wstring UTF8ToWideAndAdjustOffset(const base::StringPiece& utf8,
+ size_t* offset_for_adjustment);
+
+bool WideToUTF16AndAdjustOffset(const wchar_t* src,
+ size_t src_len,
+ string16* output,
+ size_t* offset_for_adjustment);
+string16 WideToUTF16AndAdjustOffset(const std::wstring& wide,
+ size_t* offset_for_adjustment);
+bool UTF16ToWideAndAdjustOffset(const char16* src,
+ size_t src_len,
+ std::wstring* output,
+ size_t* offset_for_adjustment);
+std::wstring UTF16ToWideAndAdjustOffset(const string16& utf16,
+ size_t* offset_for_adjustment);
+
// These convert between UTF-8, -16, and -32 strings. They are potentially slow,
// so avoid unnecessary conversions. The low-level versions return a boolean
// indicating whether the conversion was 100% valid. In this case, it will still
@@ -23,15 +54,34 @@
// the Unicode replacement character or adding |replacement_char| parameter.
// Currently, it's skipped in the ouput, which could be problematic in
// some situations.
-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 base::StringPiece& utf8);
-
-bool WideToUTF16(const wchar_t* src, size_t src_len, string16* output);
-string16 WideToUTF16(const std::wstring& wide);
-bool UTF16ToWide(const char16* src, size_t src_len, std::wstring* output);
-std::wstring UTF16ToWide(const string16& utf16);
+inline bool WideToUTF8(const wchar_t* src,
+ size_t src_len,
+ std::string* output) {
+ return WideToUTF8AndAdjustOffset(src, src_len, output, NULL);
+}
+inline std::string WideToUTF8(const std::wstring& wide) {
+ return WideToUTF8AndAdjustOffset(wide, NULL);
+}
+inline bool UTF8ToWide(const char* src, size_t src_len, std::wstring* output) {
+ return UTF8ToWideAndAdjustOffset(src, src_len, output, NULL);
+}
+inline std::wstring UTF8ToWide(const base::StringPiece& utf8) {
+ return UTF8ToWideAndAdjustOffset(utf8, NULL);
+}
+
+inline bool WideToUTF16(const wchar_t* src, size_t src_len, string16* output) {
+ return WideToUTF16AndAdjustOffset(src, src_len, output, NULL);
+}
+inline string16 WideToUTF16(const std::wstring& wide) {
+ return WideToUTF16AndAdjustOffset(wide, NULL);
+}
+inline bool UTF16ToWide(const char16* src, size_t src_len,
+ std::wstring* output) {
+ return UTF16ToWideAndAdjustOffset(src, src_len, output, NULL);
+}
+inline std::wstring UTF16ToWide(const string16& utf16) {
+ return UTF16ToWideAndAdjustOffset(utf16, NULL);
+}
bool UTF8ToUTF16(const char* src, size_t src_len, string16* output);
string16 UTF8ToUTF16(const std::string& utf8);