Chromium Code Reviews| 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..cd9671d9e117c904e1f0bef02031293a1fedfc15 |
| --- /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] == '+' || input[0] == '-') |
|
mmenke
2016/03/23 19:32:28
Can we just check if it's not between 0 and 9? Sa
eroman
2016/03/23 19:50:30
Done.
(I had same intuition, but somehow rejected
|
| + return false; |
| + |
| + int result; |
| + if (!base::StringToInt(input, &result)) |
| + return false; |
| + |
| + *output = result; |
| + return true; |
| +} |
| + |
| +} // namespace net |