| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <unicode/ucnv.h> | 9 #include <unicode/ucnv.h> |
| 10 #include <unicode/uidna.h> | 10 #include <unicode/uidna.h> |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 if (!header.empty()) | 932 if (!header.empty()) |
| 933 result.assign(header.data(), header.size()); | 933 result.assign(header.data(), header.size()); |
| 934 | 934 |
| 935 result.append("<script>start("); | 935 result.append("<script>start("); |
| 936 string_escape::JsonDoubleQuote(title, true, &result); | 936 string_escape::JsonDoubleQuote(title, true, &result); |
| 937 result.append(");</script>\n"); | 937 result.append(");</script>\n"); |
| 938 | 938 |
| 939 return result; | 939 return result; |
| 940 } | 940 } |
| 941 | 941 |
| 942 inline bool IsHostCharAlpha(char c) { |
| 943 // We can just check lowercase because uppercase characters have already been |
| 944 // normalized. |
| 945 return (c >= 'a') && (c <= 'z'); |
| 946 } |
| 947 |
| 948 inline bool IsHostCharDigit(char c) { |
| 949 return (c >= '0') && (c <= '9'); |
| 950 } |
| 951 |
| 952 bool IsCanonicalizedHostRFC1738Compliant(const std::string& host) { |
| 953 if (host.empty()) |
| 954 return false; |
| 955 |
| 956 enum State { |
| 957 NOT_IN_COMPONENT, |
| 958 IN_COMPONENT_STARTED_DIGIT, |
| 959 IN_COMPONENT_STARTED_ALPHA |
| 960 } state = NOT_IN_COMPONENT; |
| 961 bool last_char_was_hyphen = false; |
| 962 |
| 963 for (std::string::const_iterator i(host.begin()); i != host.end(); ++i) { |
| 964 const char c = *i; |
| 965 if (state == NOT_IN_COMPONENT) { |
| 966 if (IsHostCharDigit(c)) |
| 967 state = IN_COMPONENT_STARTED_DIGIT; |
| 968 else if (IsHostCharAlpha(c)) |
| 969 state = IN_COMPONENT_STARTED_ALPHA; |
| 970 else |
| 971 return false; |
| 972 } else { |
| 973 if (c == '.') { |
| 974 if (last_char_was_hyphen) |
| 975 return false; |
| 976 state = NOT_IN_COMPONENT; |
| 977 } else if (IsHostCharAlpha(c) || IsHostCharDigit(c)) { |
| 978 last_char_was_hyphen = false; |
| 979 } else if (c == '-') { |
| 980 last_char_was_hyphen = true; |
| 981 } else { |
| 982 return false; |
| 983 } |
| 984 } |
| 985 } |
| 986 |
| 987 return state == IN_COMPONENT_STARTED_ALPHA; |
| 988 } |
| 989 |
| 942 std::string GetDirectoryListingEntry(const string16& name, | 990 std::string GetDirectoryListingEntry(const string16& name, |
| 943 const std::string& raw_bytes, | 991 const std::string& raw_bytes, |
| 944 bool is_dir, | 992 bool is_dir, |
| 945 int64 size, | 993 int64 size, |
| 946 Time modified) { | 994 Time modified) { |
| 947 std::string result; | 995 std::string result; |
| 948 result.append("<script>addRow("); | 996 result.append("<script>addRow("); |
| 949 string_escape::JsonDoubleQuote(name, true, &result); | 997 string_escape::JsonDoubleQuote(name, true, &result); |
| 950 result.append(","); | 998 result.append(","); |
| 951 if (raw_bytes.empty()) { | 999 if (raw_bytes.empty()) { |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 if (length > 0) | 1414 if (length > 0) |
| 1367 ports.insert(StringToInt(WideToASCII( | 1415 ports.insert(StringToInt(WideToASCII( |
| 1368 allowed_ports.substr(last, length)))); | 1416 allowed_ports.substr(last, length)))); |
| 1369 last = i + 1; | 1417 last = i + 1; |
| 1370 } | 1418 } |
| 1371 } | 1419 } |
| 1372 explicitly_allowed_ports = ports; | 1420 explicitly_allowed_ports = ports; |
| 1373 } | 1421 } |
| 1374 | 1422 |
| 1375 } // namespace net | 1423 } // namespace net |
| OLD | NEW |