OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef NET_BASE_PARSE_NUMBER_H_ | 5 #ifndef NET_BASE_PARSE_NUMBER_H_ |
6 #define NET_BASE_PARSE_NUMBER_H_ | 6 #define NET_BASE_PARSE_NUMBER_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
11 | 11 |
12 // This file contains utility functions for parsing numbers, in the context of | 12 // This file contains utility functions for parsing numbers, in the context of |
13 // network protocols. | 13 // network protocols. |
14 // | 14 // |
15 // Q: Doesn't //base already provide these in string_number_conversions.h, with | 15 // Q: Doesn't //base already provide these in string_number_conversions.h, with |
16 // functions like base::StringToInt()? | 16 // functions like base::StringToInt()? |
17 // | 17 // |
18 // A: Yes, and those functions are used under the hood by these implementations. | 18 // A: Yes, and those functions are used under the hood by these implementations. |
19 // | 19 // |
20 // However using the base::StringTo*() has historically led to subtle bugs | 20 // However using the base::StringTo*() has historically led to subtle bugs |
21 // in the context of parsing network protocols: | 21 // in the context of parsing network protocols: |
22 // | 22 // |
23 // * Permitting a leading '+' | 23 // * Permitting a leading '+' |
24 // * Incorrectly classifying overflow/underflow from a parsing failure | 24 // * Incorrectly classifying overflow/underflow from a parsing failure |
25 // * Allowing negative numbers for non-negative fields | 25 // * Allowing negative numbers for non-negative fields |
26 // | 26 // |
27 // This API tries to avoid these problems by picking sensible defaults for | 27 // This API tries to avoid these problems by picking sensible defaults for |
28 // //net code. For more details see crbug.com/596523. | 28 // //net code. For more details see crbug.com/596523. |
29 | 29 |
30 class GURL; | |
31 | |
32 namespace net { | 30 namespace net { |
33 | 31 |
34 // Format to use when parsing integers. | 32 // Format to use when parsing integers. |
35 enum class ParseIntFormat { | 33 enum class ParseIntFormat { |
36 // Accepts non-negative base 10 integers of the form: | 34 // Accepts non-negative base 10 integers of the form: |
37 // | 35 // |
38 // 1*DIGIT | 36 // 1*DIGIT |
39 // | 37 // |
40 // This construction is used in a variety of IETF standards, such as RFC 7230 | 38 // This construction is used in a variety of IETF standards, such as RFC 7230 |
41 // (HTTP). | 39 // (HTTP). |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 WARN_UNUSED_RESULT; | 104 WARN_UNUSED_RESULT; |
107 | 105 |
108 NET_EXPORT bool ParseUint64(const base::StringPiece& input, | 106 NET_EXPORT bool ParseUint64(const base::StringPiece& input, |
109 uint64_t* output, | 107 uint64_t* output, |
110 ParseIntError* optional_error = nullptr) | 108 ParseIntError* optional_error = nullptr) |
111 WARN_UNUSED_RESULT; | 109 WARN_UNUSED_RESULT; |
112 | 110 |
113 } // namespace net | 111 } // namespace net |
114 | 112 |
115 #endif // NET_BASE_PARSE_NUMBER_H_ | 113 #endif // NET_BASE_PARSE_NUMBER_H_ |
OLD | NEW |