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

Side by Side Diff: third_party/crashpad/crashpad/util/stdlib/string_number_conversion.cc

Issue 2478633002: Update Crashpad to b47bf6c250c6b825dee1c5fbad9152c2c962e828 (Closed)
Patch Set: mac comment 2 Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/stdlib/string_number_conversion.h" 15 #include "util/stdlib/string_number_conversion.h"
16 16
17 #include <ctype.h> 17 #include <ctype.h>
18 #include <errno.h> 18 #include <errno.h>
19 #include <inttypes.h>
19 #include <stdlib.h> 20 #include <stdlib.h>
20 #include <string.h> 21 #include <string.h>
21 22
22 #include <limits> 23 #include <limits>
23 24
24 #include "base/logging.h" 25 #include "base/logging.h"
25 #include "util/stdlib/cxx.h" 26 #include "util/stdlib/cxx.h"
26 27
27 // CONSTEXPR_STATIC_ASSERT will be a normal static_assert if the C++ library is 28 // CONSTEXPR_STATIC_ASSERT will be a normal static_assert if the C++ library is
28 // the C++11 library. If using an older C++ library, the 29 // the C++11 library. If using an older C++ library, the
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 struct StringToIntTraits : public StringToSignedIntegerTraits<int, long> { 96 struct StringToIntTraits : public StringToSignedIntegerTraits<int, long> {
96 static LongType Convert(const char* str, char** end, int base) { 97 static LongType Convert(const char* str, char** end, int base) {
97 return strtol(str, end, base); 98 return strtol(str, end, base);
98 } 99 }
99 }; 100 };
100 101
101 struct StringToUnsignedIntTraits 102 struct StringToUnsignedIntTraits
102 : public StringToUnsignedIntegerTraits<unsigned int, unsigned long> { 103 : public StringToUnsignedIntegerTraits<unsigned int, unsigned long> {
103 static LongType Convert(const char* str, char** end, int base) { 104 static LongType Convert(const char* str, char** end, int base) {
104 if (str[0] == '-') { 105 if (str[0] == '-') {
106 *end = const_cast<char*>(str);
105 return 0; 107 return 0;
106 } 108 }
107 return strtoul(str, end, base); 109 return strtoul(str, end, base);
108 } 110 }
109 }; 111 };
110 112
113 struct StringToUnsignedInt64Traits
114 : public StringToUnsignedIntegerTraits<uint64_t, uint64_t> {
115 static LongType Convert(const char* str, char** end, int base) {
116 if (str[0] == '-') {
117 *end = const_cast<char*>(str);
118 return 0;
119 }
120 return strtoull(str, end, base);
121 }
122 };
123
111 template <typename Traits> 124 template <typename Traits>
112 bool StringToIntegerInternal(const base::StringPiece& string, 125 bool StringToIntegerInternal(const base::StringPiece& string,
113 typename Traits::IntType* number) { 126 typename Traits::IntType* number) {
114 using IntType = typename Traits::IntType; 127 using IntType = typename Traits::IntType;
115 using LongType = typename Traits::LongType; 128 using LongType = typename Traits::LongType;
116 129
117 Traits::TypeCheck(); 130 Traits::TypeCheck();
118 131
119 if (string.empty() || isspace(string[0])) { 132 if (string.empty() || isspace(string[0])) {
120 return false; 133 return false;
(...skipping 25 matching lines...) Expand all
146 namespace crashpad { 159 namespace crashpad {
147 160
148 bool StringToNumber(const base::StringPiece& string, int* number) { 161 bool StringToNumber(const base::StringPiece& string, int* number) {
149 return StringToIntegerInternal<StringToIntTraits>(string, number); 162 return StringToIntegerInternal<StringToIntTraits>(string, number);
150 } 163 }
151 164
152 bool StringToNumber(const base::StringPiece& string, unsigned int* number) { 165 bool StringToNumber(const base::StringPiece& string, unsigned int* number) {
153 return StringToIntegerInternal<StringToUnsignedIntTraits>(string, number); 166 return StringToIntegerInternal<StringToUnsignedIntTraits>(string, number);
154 } 167 }
155 168
169 bool StringToNumber(const base::StringPiece& string, uint64_t* number) {
170 return StringToIntegerInternal<StringToUnsignedInt64Traits>(string, number);
171 }
172
156 } // namespace crashpad 173 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698