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

Unified Diff: net/base/escape.cc

Issue 642403002: git cl format the first third of the net/base directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit Created 6 years, 1 month 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
diff --git a/net/base/escape.cc b/net/base/escape.cc
index 7a068f87ee571ce555d5f063b7a0101ef280d1de..000dadaff3e03d365303de2f86860296d858bb43 100644
--- a/net/base/escape.cc
+++ b/net/base/escape.cc
@@ -85,28 +85,30 @@ std::string Escape(const std::string& text,
// allowed in query strings according to http://www.ietf.org/rfc/rfc3261.txt are
// not unescaped, to avoid turning a valid url according to spec into an
// invalid one.
+// clang-format off
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
};
+// clang-format on
// 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) {
@@ -119,8 +121,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;
@@ -128,7 +130,7 @@ bool UnescapeUnsignedCharAtIndex(const STR& escaped_text,
// Returns true if there is an Arabic Language Mark at |index|. |first_byte|
// is the byte at |index|.
-template<typename STR>
+template <typename STR>
bool HasArabicLanguageMarkAtIndex(const STR& escaped_text,
unsigned char first_byte,
size_t index) {
@@ -142,7 +144,7 @@ bool HasArabicLanguageMarkAtIndex(const STR& escaped_text,
// Returns true if there is a BiDi control char at |index|. |first_byte| is the
// byte at |index|.
-template<typename STR>
+template <typename STR>
bool HasThreeByteBidiControlCharAtIndex(const STR& escaped_text,
unsigned char first_byte,
size_t index) {
@@ -157,8 +159,7 @@ bool HasThreeByteBidiControlCharAtIndex(const STR& escaped_text,
if (!UnescapeUnsignedCharAtIndex(escaped_text, index + 6, &third_byte))
return false;
if (second_byte == 0x80) {
- return third_byte == 0x8E ||
- third_byte == 0x8F ||
+ return third_byte == 0x8E || third_byte == 0x8F ||
(third_byte >= 0xAA && third_byte <= 0xAE);
}
return third_byte >= 0xA6 && third_byte <= 0xA9;
@@ -169,7 +170,7 @@ bool HasThreeByteBidiControlCharAtIndex(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,
@@ -275,11 +276,11 @@ void AppendEscapedCharForHTMLImpl(typename str::value_type c, str* output) {
char key;
const char* replacement;
} kCharsToEscape[] = {
- { '<', "&lt;" },
- { '>', "&gt;" },
- { '&', "&amp;" },
- { '"', "&quot;" },
- { '\'', "&#39;" },
+ {'<', "&lt;"},
+ {'>', "&gt;"},
+ {'&', "&amp;"},
+ {'"', "&quot;"},
+ {'\'', "&#39;"},
};
size_t k;
for (k = 0; k < arraysize(kCharsToEscape); ++k) {
@@ -307,35 +308,55 @@ 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, 0x50000025L, 0x50000000L, 0xb8000001L,
- 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL
-}};
+static const Charmap kExternalHandlerCharmap = {{0xffffffffL,
+ 0x50000025L,
+ 0x50000000L,
+ 0xb8000001L,
+ 0xffffffffL,
+ 0xffffffffL,
+ 0xffffffffL,
+ 0xffffffffL}};
} // namespace
@@ -392,11 +413,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,
@@ -413,11 +433,11 @@ base::string16 UnescapeForHTML(const base::string16& input) {
const char* ampersand_code;
const char replacement;
} kEscapeToChars[] = {
- { "&lt;", '<' },
- { "&gt;", '>' },
- { "&amp;", '&' },
- { "&quot;", '"' },
- { "&#39;", '\''},
+ {"&lt;", '<'},
+ {"&gt;", '>'},
+ {"&amp;", '&'},
+ {"&quot;", '"'},
+ {"&#39;", '\''},
};
if (input.find(base::ASCIIToUTF16("&")) == std::string::npos)
@@ -425,8 +445,8 @@ base::string16 UnescapeForHTML(const base::string16& input) {
base::string16 ampersand_chars[arraysize(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();
@@ -436,8 +456,8 @@ 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;
}
}

Powered by Google App Engine
This is Rietveld 408576698