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

Unified Diff: net/base/parse_number.h

Issue 1828103002: Extend net/base/parse_number.h for parsing of negative numbers, and determining if there was overflo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proxy_num
Patch Set: Created 4 years, 9 months 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/parse_number.h
diff --git a/net/base/parse_number.h b/net/base/parse_number.h
index 0b88cf0435b3af69d1330c33d07acdbc11c60e52..2be434c73cf7e7047d759c7b2887085cacafe765 100644
--- a/net/base/parse_number.h
+++ b/net/base/parse_number.h
@@ -34,34 +34,80 @@ class GURL;
namespace net {
-// Parses a string representing a decimal number to an |int|. Returns true on
-// success, and fills |*output| with the result. Note that |*output| is not
-// modified on failure.
+// ParseNonNegativeInteger() parses a string representing a decimal number.
+// Returns true on success, and fills |*output| with the result:
//
-// Recognized inputs take the form:
+// ParseNonNegativeInteger() recognizes inputs of the form:
// 1*DIGIT
//
-// Where DIGIT is an ASCII number in the range '0' - '9'
+// Where DIGIT is an ASCII number in the range '0' - '9'
//
-// Note that:
+// Note that:
// * Parsing is locale independent
+// * |*output| is not modified on failure
// * Leading zeros are allowed (numbers needn't be in minimal encoding)
-// * Inputs that would overflow the output are rejected.
-// * Only accepts integers
+// * Inputs that would overflow the output type are rejected
+// * ParseNonNegativeInteger() has overloads for a variety of output
+// types. Regardless of the output type's signedness, the output is NEVER
+// negative on success.
//
-// Examples of recognized inputs are:
+// Examples of accepted inputs are:
// "13"
// "0"
// "00013"
//
-// Examples of rejected inputs are:
+// Examples of rejected inputs are:
// " 13"
// "-13"
// "+13"
// "0x15"
// "13.3"
-NET_EXPORT bool ParseNonNegativeDecimalInt(const base::StringPiece& input,
- int* output) WARN_UNUSED_RESULT;
+// "999999999999999999999999999999999999999999999"
+NET_EXPORT bool ParseNonNegativeInteger(const base::StringPiece& input,
+ int32_t* output) WARN_UNUSED_RESULT;
+
+NET_EXPORT bool ParseNonNegativeInteger(const base::StringPiece& input,
+ uint32_t* output) WARN_UNUSED_RESULT;
+
+NET_EXPORT bool ParseNonNegativeInteger(const base::StringPiece& input,
+ int64_t* output) WARN_UNUSED_RESULT;
+
+NET_EXPORT bool ParseNonNegativeInteger(const base::StringPiece& input,
+ uint64_t* output) WARN_UNUSED_RESULT;
+
+// ParseSignedInteger() parses a string representing a decimal number.
+// Returns true on success, and fills |*output| with the result:
+//
+// ParseSignedInteger() recognizes inputs of the form:
+// ("" | "-") 1*DIGIT
+//
+// Where DIGIT is an ASCII number in the range '0' - '9'
+//
+// Note that:
+// * Parsing is locale independent
+// * |*output| is not modified on failure
+// * Leading zeros are allowed (numbers needn't be in minimal encoding)
+// * Zero can be expressed as a negative or positive quantity.
+// * Inputs that would overflow/underflow the output type are rejected
+//
+// Examples of accepted inputs are:
+// "13"
+// "-13"
+// "0"
+// "-0"
+// "00013"
+//
+// Examples of rejected inputs are:
+// " 13"
+// "+13"
+// "0x15"
+// "13.3"
+// "999999999999999999999999999999999999999999999"
+NET_EXPORT bool ParseSignedInteger(const base::StringPiece& input,
+ int64_t* output) WARN_UNUSED_RESULT;
+
+NET_EXPORT bool ParseSignedInteger(const base::StringPiece& input,
+ int32_t* output) WARN_UNUSED_RESULT;
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698