Index: net/base/escape.cc |
diff --git a/net/base/escape.cc b/net/base/escape.cc |
index ab70f1db30187e6a28e09757819d2f307291fd53..136970c7ef0d1425c0794273775fab0b11367540 100644 |
--- a/net/base/escape.cc |
+++ b/net/base/escape.cc |
@@ -40,7 +40,8 @@ struct Charmap { |
// return an escaped string. If use_plus is true, spaces are converted |
// to +, otherwise, if spaces are in the charmap, they are converted to |
// %20. |
-std::string Escape(const std::string& text, const Charmap& charmap, |
+std::string Escape(const std::string& text, |
+ const Charmap& charmap, |
bool use_plus) { |
std::string escaped; |
escaped.reserve(text.length() * 3); |
@@ -80,27 +81,26 @@ std::string Escape(const std::string& text, const Charmap& charmap, |
// not unescaped, to avoid turning a valid url according to spec into an |
// invalid one. |
const char kUrlUnescape[128] = { |
-// NULL, control chars... |
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
-// ' ' ! " # $ % & ' ( ) * + , - . / |
- 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, |
-// 0 1 2 3 4 5 6 7 8 9 : ; < = > ? |
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, |
-// @ A B C D E F G H I J K L M N O |
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
-// P Q R S T U V W X Y Z [ \ ] ^ _ |
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, |
-// ` a b c d e f g h i j k l m n o |
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
-// p q r s t u v w x y z { | } ~ <NBSP> |
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 |
-}; |
+ // NULL, control chars... |
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
+ // ' ' ! " # $ % & ' ( ) * + , - . / |
+ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, |
+ // 0 1 2 3 4 5 6 7 8 9 : ; < = > ? |
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, |
+ // @ A B C D E F G H I J K L M N O |
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
+ // P Q R S T U V W X Y Z [ \ ] ^ _ |
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, |
+ // ` a b c d e f g h i j k l m n o |
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
+ // p q r s t u v w x y z { | } ~ <NBSP> |
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0}; |
// Attempts to unescape the sequence at |index| within |escaped_text|. If |
// successful, sets |value| to the unescaped value. Returns whether |
// unescaping succeeded. |
-template<typename STR> |
+template <typename STR> |
bool UnescapeUnsignedCharAtIndex(const STR& escaped_text, |
size_t index, |
unsigned char* value) { |
@@ -113,8 +113,8 @@ bool UnescapeUnsignedCharAtIndex(const STR& escaped_text, |
const typename STR::value_type least_sig_digit( |
static_cast<typename STR::value_type>(escaped_text[index + 2])); |
if (IsHexDigit(most_sig_digit) && IsHexDigit(least_sig_digit)) { |
- *value = HexDigitToInt(most_sig_digit) * 16 + |
- HexDigitToInt(least_sig_digit); |
+ *value = |
+ HexDigitToInt(most_sig_digit) * 16 + HexDigitToInt(least_sig_digit); |
return true; |
} |
return false; |
@@ -125,7 +125,7 @@ bool UnescapeUnsignedCharAtIndex(const STR& escaped_text, |
// the alterations done to the string that are not one-character-to-one- |
// character. The resulting |adjustments| will always be sorted by increasing |
// offset. |
-template<typename STR> |
+template <typename STR> |
STR UnescapeURLWithAdjustmentsImpl( |
const STR& escaped_text, |
UnescapeRule::Type rules, |
@@ -189,10 +189,10 @@ STR UnescapeURLWithAdjustmentsImpl( |
((second_byte == 0x80) || (second_byte == 0x81))) { |
unsigned char third_byte; |
if (UnescapeUnsignedCharAtIndex(escaped_text, i + 6, &third_byte) && |
- ((second_byte == 0x80) ? |
- ((third_byte == 0x8E) || (third_byte == 0x8F) || |
- ((third_byte >= 0xAA) && (third_byte <= 0xAE))) : |
- ((third_byte >= 0xA6) && (third_byte <= 0xA9)))) { |
+ ((second_byte == 0x80) |
+ ? ((third_byte == 0x8E) || (third_byte == 0x8F) || |
+ ((third_byte >= 0xAA) && (third_byte <= 0xAE))) |
+ : ((third_byte >= 0xA6) && (third_byte <= 0xA9)))) { |
result.append(escaped_text, i, 9); |
i += 8; |
continue; |
@@ -237,12 +237,12 @@ void AppendEscapedCharForHTMLImpl(typename str::value_type c, str* output) { |
char key; |
const char* replacement; |
} kCharsToEscape[] = { |
- { '<', "<" }, |
- { '>', ">" }, |
- { '&', "&" }, |
- { '"', """ }, |
- { '\'', "'" }, |
- }; |
+ {'<', "<"}, |
+ {'>', ">"}, |
+ {'&', "&"}, |
+ {'"', """}, |
+ {'\'', "'"}, |
+ }; |
size_t k; |
for (k = 0; k < ARRAYSIZE_UNSAFE(kCharsToEscape); ++k) { |
if (c == kCharsToEscape[k].key) { |
@@ -269,35 +269,30 @@ str EscapeForHTMLImpl(const str& input) { |
// Everything except alphanumerics and !'()*-._~ |
// See RFC 2396 for the list of reserved characters. |
-static const Charmap kQueryCharmap = {{ |
- 0xffffffffL, 0xfc00987dL, 0x78000001L, 0xb8000001L, |
- 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL |
-}}; |
+static const Charmap kQueryCharmap = {{0xffffffffL, 0xfc00987dL, 0x78000001L, |
+ 0xb8000001L, 0xffffffffL, 0xffffffffL, |
+ 0xffffffffL, 0xffffffffL}}; |
// non-printable, non-7bit, and (including space) "#%:<>?[\]^`{|} |
-static const Charmap kPathCharmap = {{ |
- 0xffffffffL, 0xd400002dL, 0x78000000L, 0xb8000001L, |
- 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL |
-}}; |
+static const Charmap kPathCharmap = {{0xffffffffL, 0xd400002dL, 0x78000000L, |
+ 0xb8000001L, 0xffffffffL, 0xffffffffL, |
+ 0xffffffffL, 0xffffffffL}}; |
// non-printable, non-7bit, and (including space) ?>=<;+'&%$#"![\]^`{|} |
-static const Charmap kUrlEscape = {{ |
- 0xffffffffL, 0xf80008fdL, 0x78000001L, 0xb8000001L, |
- 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL |
-}}; |
+static const Charmap kUrlEscape = {{0xffffffffL, 0xf80008fdL, 0x78000001L, |
+ 0xb8000001L, 0xffffffffL, 0xffffffffL, |
+ 0xffffffffL, 0xffffffffL}}; |
// non-7bit |
-static const Charmap kNonASCIICharmap = {{ |
- 0x00000000L, 0x00000000L, 0x00000000L, 0x00000000L, |
- 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL |
-}}; |
+static const Charmap kNonASCIICharmap = {{0x00000000L, 0x00000000L, 0x00000000L, |
+ 0x00000000L, 0xffffffffL, 0xffffffffL, |
+ 0xffffffffL, 0xffffffffL}}; |
// Everything except alphanumerics, the reserved characters(;/?:@&=+$,) and |
// !'()*-._~% |
-static const Charmap kExternalHandlerCharmap = {{ |
- 0xffffffffL, 0x5000080dL, 0x68000000L, 0xb8000001L, |
- 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL |
-}}; |
+static const Charmap kExternalHandlerCharmap = { |
+ {0xffffffffL, 0x5000080dL, 0x68000000L, 0xb8000001L, 0xffffffffL, |
+ 0xffffffffL, 0xffffffffL, 0xffffffffL}}; |
} // namespace |
@@ -354,11 +349,10 @@ base::string16 UnescapeAndDecodeUTF8URLComponentWithAdjustments( |
base::OffsetAdjuster::Adjustments* adjustments) { |
base::string16 result; |
base::OffsetAdjuster::Adjustments unescape_adjustments; |
- std::string unescaped_url(UnescapeURLWithAdjustmentsImpl( |
- text, rules, &unescape_adjustments)); |
- if (base::UTF8ToUTF16WithAdjustments(unescaped_url.data(), |
- unescaped_url.length(), |
- &result, adjustments)) { |
+ std::string unescaped_url( |
+ UnescapeURLWithAdjustmentsImpl(text, rules, &unescape_adjustments)); |
+ if (base::UTF8ToUTF16WithAdjustments( |
+ unescaped_url.data(), unescaped_url.length(), &result, adjustments)) { |
// Character set looks like it's valid. |
if (adjustments) { |
base::OffsetAdjuster::MergeSequentialAdjustments(unescape_adjustments, |
@@ -375,20 +369,20 @@ base::string16 UnescapeForHTML(const base::string16& input) { |
const char* ampersand_code; |
const char replacement; |
} kEscapeToChars[] = { |
- { "<", '<' }, |
- { ">", '>' }, |
- { "&", '&' }, |
- { """, '"' }, |
- { "'", '\''}, |
- }; |
+ {"<", '<'}, |
+ {">", '>'}, |
+ {"&", '&'}, |
+ {""", '"'}, |
+ {"'", '\''}, |
+ }; |
if (input.find(base::ASCIIToUTF16("&")) == std::string::npos) |
return input; |
base::string16 ampersand_chars[ARRAYSIZE_UNSAFE(kEscapeToChars)]; |
base::string16 text(input); |
- for (base::string16::iterator iter = text.begin(); |
- iter != text.end(); ++iter) { |
+ for (base::string16::iterator iter = text.begin(); iter != text.end(); |
+ ++iter) { |
if (*iter == '&') { |
// Potential ampersand encode char. |
size_t index = iter - text.begin(); |
@@ -398,8 +392,10 @@ base::string16 UnescapeForHTML(const base::string16& input) { |
base::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); |
+ text.replace(iter, |
+ iter + ampersand_chars[i].length(), |
+ 1, |
+ kEscapeToChars[i].replacement); |
break; |
} |
} |