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

Unified Diff: net/base/parse_number.cc

Issue 1829873002: Add base/parse_number.h to generalize number parsing done in //net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more tests 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
« no previous file with comments | « net/base/parse_number.h ('k') | net/base/parse_number_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/parse_number.cc
diff --git a/net/base/parse_number.cc b/net/base/parse_number.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d315bec63a906dba00b5f27e56dd20161ace6266
--- /dev/null
+++ b/net/base/parse_number.cc
@@ -0,0 +1,23 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/base/parse_number.h"
+
+#include "base/strings/string_number_conversions.h"
+
+namespace net {
+
+bool ParseNonNegativeDecimalInt(const base::StringPiece& input, int* output) {
+ if (input.empty() || input[0] > '9' || input[0] < '0')
+ return false;
+
+ int result;
+ if (!base::StringToInt(input, &result))
+ return false;
+
+ *output = result;
+ return true;
+}
+
+} // namespace net
« no previous file with comments | « net/base/parse_number.h ('k') | net/base/parse_number_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698