summaryrefslogtreecommitdiffstats
path: root/net/base/escape.h
diff options
context:
space:
mode:
authormpearson@chromium.org <mpearson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-18 20:54:44 +0000
committermpearson@chromium.org <mpearson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-18 20:54:44 +0000
commita97376ebdf3182f4ccceaa8019deb26829db3688 (patch)
tree2ab4bc3736d98877dbcb352b1e34d6906b4e8b5c /net/base/escape.h
parent9cdbb8cbd23103d00b1f67af2a892b4ac9899b74 (diff)
downloadchromium_src-a97376ebdf3182f4ccceaa8019deb26829db3688.zip
chromium_src-a97376ebdf3182f4ccceaa8019deb26829db3688.tar.gz
chromium_src-a97376ebdf3182f4ccceaa8019deb26829db3688.tar.bz2
Make FormatUrl Keep Track of Full Transformation
The omnibox providers usually search for matches in the formatted text (i.e., the escaped characters in the URL are unescaped before searching). This makes it difficult to highlight matches in URL because the location of the matched positions does not match the location of the matched text in the original URL spec. The code to adjust offsets doesn't help here because it adjusts offsets that with respect to the original URL spec, not offsets with respect to the formatted URL. In effect, we need to be able to reverse the transformation that FormatUrl() does in order to get the original offsets back (if possible) from the transformed offsets we have. The easiest and most efficient way to compute this reverse mapping is to keep track of the full original mapping, then reverse it later and apply the reversed mapping to the match offsets we have where the offsets are with respect to the formatted string. This change include the necessary parts to keep track of the full transformation. In a follow-up change, I will make HistoryQuick provider use the transformation information. In the process of that change, I will remove the "WithOffsets" function from net_util. BUG=252630 Review URL: https://codereview.chromium.org/196103008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/escape.h')
-rw-r--r--net/base/escape.h34
1 files changed, 7 insertions, 27 deletions
diff --git a/net/base/escape.h b/net/base/escape.h
index 69eb2a5..1915d24 100644
--- a/net/base/escape.h
+++ b/net/base/escape.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/strings/string16.h"
+#include "base/strings/utf_offset_string_conversions.h"
#include "net/base/net_export.h"
namespace net {
@@ -114,42 +115,21 @@ NET_EXPORT base::string16 UnescapeURLComponent(
// Unescapes the given substring as a URL, and then tries to interpret the
// result as being encoded as UTF-8. If the result is convertable into UTF-8, it
// will be returned as converted. If it is not, the original escaped string will
-// be converted into a base::string16 and returned. (|offset[s]_for_adjustment|)
-// specifies one or more offsets into the source strings; each offset will be
-// adjusted to point at the same logical place in the result strings during
-// decoding. If this isn't possible because an offset points past the end of
-// the source strings or into the middle of a multibyte sequence, the offending
-// offset will be set to string16::npos. |offset[s]_for_adjustment| may be NULL.
+// be converted into a base::string16 and returned. |adjustments| provides
+// information on how the original string was adjusted to get the string
+// returned.
NET_EXPORT base::string16 UnescapeAndDecodeUTF8URLComponent(
const std::string& text,
- UnescapeRule::Type rules,
- size_t* offset_for_adjustment);
-NET_EXPORT base::string16 UnescapeAndDecodeUTF8URLComponentWithOffsets(
+ UnescapeRule::Type rules);
+NET_EXPORT base::string16 UnescapeAndDecodeUTF8URLComponentWithAdjustments(
const std::string& text,
UnescapeRule::Type rules,
- std::vector<size_t>* offsets_for_adjustment);
+ base::OffsetAdjuster::Adjustments* adjustments);
// Unescapes the following ampersand character codes from |text|:
// &lt; &gt; &amp; &quot; &#39;
NET_EXPORT base::string16 UnescapeForHTML(const base::string16& text);
-namespace internal {
-
-// Private Functions (Exposed for Unit Testing) --------------------------------
-
-// A function called by std::for_each that will adjust any offset which occurs
-// after one or more encoded characters.
-struct NET_EXPORT_PRIVATE AdjustEncodingOffset {
- typedef std::vector<size_t> Adjustments;
-
- explicit AdjustEncodingOffset(const Adjustments& adjustments);
- void operator()(size_t& offset);
-
- const Adjustments& adjustments;
-};
-
-} // namespace internal
-
} // namespace net
#endif // NET_BASE_ESCAPE_H_