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

Unified Diff: net/base/escape.cc

Issue 6898026: Eliminate wstring from base/utf_offset_string_conversions.h, net/base/escape.h, and net/base/net_... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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
Index: net/base/escape.cc
===================================================================
--- net/base/escape.cc (revision 82762)
+++ net/base/escape.cc (working copy)
@@ -105,7 +105,7 @@
if (offsets_for_adjustment) {
std::for_each(offsets_for_adjustment->begin(),
offsets_for_adjustment->end(),
- LimitOffset<std::wstring>(escaped_text.length()));
+ LimitOffset<STR>(escaped_text.length()));
}
// Do not unescape anything, return the |escaped_text| text.
if (rules == UnescapeRule::NONE)
@@ -177,19 +177,6 @@
return result;
}
-template<typename STR>
-STR UnescapeURLImpl(const STR& escaped_text,
- UnescapeRule::Type rules,
- size_t* offset_for_adjustment) {
- std::vector<size_t> offsets;
- if (offset_for_adjustment)
- offsets.push_back(*offset_for_adjustment);
- STR result = UnescapeURLWithOffsetsImpl(escaped_text, rules, &offsets);
- if (offset_for_adjustment)
- *offset_for_adjustment = offsets[0];
- return result;
-}
-
} // namespace
// Everything except alphanumerics and !'()*-._~
@@ -251,22 +238,21 @@
const std::string& text,
UnescapeRule::Type rules,
std::vector<size_t>* offsets_for_adjustment) {
- std::wstring result;
+ string16 result;
std::vector<size_t> original_offsets;
if (offsets_for_adjustment)
original_offsets = *offsets_for_adjustment;
std::string unescaped_url(
UnescapeURLWithOffsetsImpl(text, rules, offsets_for_adjustment));
- if (UTF8ToWideAndAdjustOffsets(unescaped_url.data(), unescaped_url.length(),
- &result, offsets_for_adjustment))
- return WideToUTF16Hack(result); // Character set looks like it's valid.
+ if (UTF8ToUTF16AndAdjustOffsets(unescaped_url.data(), unescaped_url.length(),
+ &result, offsets_for_adjustment))
+ return result; // Character set looks like it's valid.
// Not valid. Return the escaped version. Undo our changes to
// |offset_for_adjustment| since we haven't changed the string after all.
if (offsets_for_adjustment)
*offsets_for_adjustment = original_offsets;
- return WideToUTF16Hack(UTF8ToWideAndAdjustOffsets(
- text, offsets_for_adjustment));
+ return UTF8ToUTF16AndAdjustOffsets(text, offsets_for_adjustment);
}
string16 UnescapeAndDecodeUTF8URLComponent(const std::string& text,
@@ -284,12 +270,12 @@
std::string UnescapeURLComponent(const std::string& escaped_text,
UnescapeRule::Type rules) {
- return UnescapeURLWithOffsetsImpl<std::string>(escaped_text, rules, NULL);
+ return UnescapeURLWithOffsetsImpl(escaped_text, rules, NULL);
}
string16 UnescapeURLComponent(const string16& escaped_text,
UnescapeRule::Type rules) {
- return UnescapeURLWithOffsetsImpl<string16>(escaped_text, rules, NULL);
+ return UnescapeURLWithOffsetsImpl(escaped_text, rules, NULL);
}
@@ -322,10 +308,6 @@
AppendEscapedCharForHTMLImpl(c, output);
}
-void AppendEscapedCharForHTML(wchar_t c, string16* output) {
- AppendEscapedCharForHTMLImpl(c, output);
-}
-
template <class str>
str EscapeForHTMLImpl(const str& input) {
str result;
@@ -347,17 +329,17 @@
string16 UnescapeForHTML(const string16& input) {
static const struct {
- const wchar_t* ampersand_code;
+ const char* ampersand_code;
const char replacement;
} kEscapeToChars[] = {
- { L"&lt;", '<' },
- { L"&gt;", '>' },
- { L"&amp;", '&' },
- { L"&quot;", '"' },
- { L"&#39;", '\''},
+ { "&lt;", '<' },
+ { "&gt;", '>' },
+ { "&amp;", '&' },
+ { "&quot;", '"' },
+ { "&#39;", '\''},
};
- if (input.find(WideToUTF16(L"&")) == std::string::npos)
+ if (input.find(ASCIIToUTF16("&")) == std::string::npos)
return input;
string16 ampersand_chars[ARRAYSIZE_UNSAFE(kEscapeToChars)];
@@ -368,7 +350,7 @@
size_t index = iter - text.begin();
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEscapeToChars); i++) {
if (ampersand_chars[i].empty())
- ampersand_chars[i] = WideToUTF16(kEscapeToChars[i].ampersand_code);
+ ampersand_chars[i] = ASCIIToUTF16(kEscapeToChars[i].ampersand_code);
if (text.find(ampersand_chars[i], index) == index) {
text.replace(iter, iter + ampersand_chars[i].length(),
1, kEscapeToChars[i].replacement);
« no previous file with comments | « net/base/escape.h ('k') | net/base/escape_unittest.cc » ('j') | net/base/net_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698