summaryrefslogtreecommitdiffstats
path: root/base/strings/utf_offset_string_conversions.h
diff options
context:
space:
mode:
authormpearson@chromium.org <mpearson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-28 19:37:23 +0000
committermpearson@chromium.org <mpearson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-28 19:37:23 +0000
commit529d4b5e6a4769eec4ebde8c48231fae3ab3c8aa (patch)
tree51c0ee355cf7b949c2ee228edbf5958ea9bcc13d /base/strings/utf_offset_string_conversions.h
parent2f5a9fe7f845446a115d896433fe88698cba7eea (diff)
downloadchromium_src-529d4b5e6a4769eec4ebde8c48231fae3ab3c8aa.zip
chromium_src-529d4b5e6a4769eec4ebde8c48231fae3ab3c8aa.tar.gz
chromium_src-529d4b5e6a4769eec4ebde8c48231fae3ab3c8aa.tar.bz2
Omnibox: Highlight Matches in URLs Properly
Previously we'd match the omnibox input against a cleaned-up version of the URL. Precisely, we'd remove the escaping and interpret as UTF8 (and lower-case it) so non-Latin characters can be matched correctly. This is all well and good, but then we'd take the offsets of those matches and use them to highlight segments of the original URL (properly escaped). Oops. At best this caused bad highlighting; at middle, it caused weirdness as we attempted to highlight the middle of a multi-string character; at worst, it'd cause crashes because our offsets calculation would put us in no-man's-land. This fixes all that. :-) Precisely, we keep track of the adjustments made during cleaning. We take the offsets where terms matched and apply them through the transformation in reverse. TBR=sky (as usual for history and bookmarks stuff that just change internals relative to how they behave with the omnibox) BUG=252630,359270 Review URL: https://codereview.chromium.org/255423002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266630 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/strings/utf_offset_string_conversions.h')
-rw-r--r--base/strings/utf_offset_string_conversions.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/base/strings/utf_offset_string_conversions.h b/base/strings/utf_offset_string_conversions.h
index 463772d..d449489 100644
--- a/base/strings/utf_offset_string_conversions.h
+++ b/base/strings/utf_offset_string_conversions.h
@@ -49,6 +49,20 @@ class BASE_EXPORT OffsetAdjuster {
static void AdjustOffset(const Adjustments& adjustments,
size_t* offset);
+ // Adjusts all offsets in |offsets_for_unadjustment| to reflect the reverse
+ // of the adjustments recorded in |adjustments|. In other words, the offsets
+ // provided represent offsets into an adjusted string and the caller wants
+ // to know the offsets they correspond to in the original string. If an
+ // offset cannot be successfully unadjusted (e.g., because it points into
+ // the middle of a multibyte sequence), it will be set to string16::npos.
+ static void UnadjustOffsets(const Adjustments& adjustments,
+ std::vector<size_t>* offsets_for_unadjustment);
+
+ // Adjusts the single |offset| to reflect the reverse of the adjustments
+ // recorded in |adjustments|.
+ static void UnadjustOffset(const Adjustments& adjustments,
+ size_t* offset);
+
// Combines two sequential sets of adjustments, storing the combined revised
// adjustments in |adjustments_on_adjusted_string|. That is, suppose a
// string was altered in some way, with the alterations recorded as