OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/dns_util.h" | 5 #include "net/base/dns_util.h" |
6 | 6 |
7 #include <cstring> | 7 #include <cstring> |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 *out = std::string(name, namelen); | 55 *out = std::string(name, namelen); |
56 return true; | 56 return true; |
57 } | 57 } |
58 | 58 |
59 std::string DNSDomainToString(const base::StringPiece& domain) { | 59 std::string DNSDomainToString(const base::StringPiece& domain) { |
60 std::string ret; | 60 std::string ret; |
61 | 61 |
62 for (unsigned i = 0; i < domain.size() && domain[i]; i += domain[i] + 1) { | 62 for (unsigned i = 0; i < domain.size() && domain[i]; i += domain[i] + 1) { |
63 #if CHAR_MIN < 0 | 63 #if CHAR_MIN < 0 |
64 if (domain[i] < 0) | 64 if (domain[i] < 0) |
65 return ""; | 65 return std::string(); |
66 #endif | 66 #endif |
67 if (domain[i] > 63) | 67 if (domain[i] > 63) |
68 return ""; | 68 return std::string(); |
69 | 69 |
70 if (i) | 70 if (i) |
71 ret += "."; | 71 ret += "."; |
72 | 72 |
73 if (static_cast<unsigned>(domain[i]) + i + 1 > domain.size()) | 73 if (static_cast<unsigned>(domain[i]) + i + 1 > domain.size()) |
74 return ""; | 74 return std::string(); |
75 | 75 |
76 domain.substr(i + 1, domain[i]).AppendToString(&ret); | 76 domain.substr(i + 1, domain[i]).AppendToString(&ret); |
77 } | 77 } |
78 return ret; | 78 return ret; |
79 } | 79 } |
80 | 80 |
81 bool IsSTD3ASCIIValidCharacter(char c) { | 81 bool IsSTD3ASCIIValidCharacter(char c) { |
82 if (c <= 0x2c) | 82 if (c <= 0x2c) |
83 return false; | 83 return false; |
84 if (c >= 0x7b) | 84 if (c >= 0x7b) |
(...skipping 10 matching lines...) Expand all Loading... |
95 std::string TrimEndingDot(const base::StringPiece& host) { | 95 std::string TrimEndingDot(const base::StringPiece& host) { |
96 base::StringPiece host_trimmed = host; | 96 base::StringPiece host_trimmed = host; |
97 size_t len = host_trimmed.length(); | 97 size_t len = host_trimmed.length(); |
98 if (len > 1 && host_trimmed[len - 1] == '.') { | 98 if (len > 1 && host_trimmed[len - 1] == '.') { |
99 host_trimmed.remove_suffix(1); | 99 host_trimmed.remove_suffix(1); |
100 } | 100 } |
101 return host_trimmed.as_string(); | 101 return host_trimmed.as_string(); |
102 } | 102 } |
103 | 103 |
104 } // namespace net | 104 } // namespace net |
OLD | NEW |