29#include "absl/strings/ascii.h"
34inline int64_t
strtoint64(
const char* nptr,
char** endptr,
int base) {
35 return std::strtoll(nptr, endptr, base);
38inline uint64_t
strtouint64(
const char* nptr,
char** endptr,
int base) {
39 return std::strtoull(nptr, endptr, base);
42inline int32_t
strtoint32(
const char* nptr,
char** endptr,
int base) {
43 return std::strtol(nptr, endptr, base);
46inline uint32_t
strtouint32(
const char* nptr,
char** endptr,
int base) {
47 return std::strtoul(nptr, endptr, base);
59 using std::numeric_limits;
61 char* error =
nullptr;
62 long value = strtol(str, &error, 0);
64 if (
value > numeric_limits<int32_t>::max()) {
65 value = numeric_limits<int32_t>::max();
66 }
else if (
value < numeric_limits<int32_t>::min()) {
67 value = numeric_limits<int32_t>::min();
69 return (error == str) ? deflt :
value;
73 using std::numeric_limits;
75 if (numeric_limits<unsigned long>::max() ==
76 numeric_limits<uint32_t>::max()) {
78 char* error =
nullptr;
79 const uint32_t
value = strtoul(str, &error, 0);
80 return (error == str) ? deflt :
value;
87 char* error =
nullptr;
89 if (
value > numeric_limits<uint32_t>::max() ||
90 value < -
static_cast<int64_t
>(numeric_limits<uint32_t>::max())) {
91 value = numeric_limits<uint32_t>::max();
94 return (error == str) ? deflt :
value;
108 using std::numeric_limits;
110 char* error =
nullptr;
111 long value = strtol(str, &error, 10);
113 if (
value > numeric_limits<int32_t>::max()) {
114 value = numeric_limits<int32_t>::max();
115 }
else if (
value < numeric_limits<int32_t>::min()) {
116 value = numeric_limits<int32_t>::min();
118 return (error == str) ? deflt :
value;
122 using std::numeric_limits;
124 if (numeric_limits<unsigned long>::max() ==
125 numeric_limits<uint32_t>::max()) {
127 char* error =
nullptr;
128 const uint32_t
value = strtoul(str, &error, 10);
129 return (error == str) ? deflt :
value;
136 char* error =
nullptr;
138 if (
value > numeric_limits<uint32_t>::max() ||
139 value < -
static_cast<int64_t
>(numeric_limits<uint32_t>::max())) {
140 value = numeric_limits<uint32_t>::max();
143 return (error == str) ? deflt :
value;
156 char* error =
nullptr;
158 return (error == str) ? deflt :
value;
162 char* error =
nullptr;
164 return (error == str) ? deflt :
value;
168 char* error =
nullptr;
170 return (error == str) ? deflt :
value;
183 char* error =
nullptr;
185 return (error == str) ? deflt :
value;
189 char* error =
nullptr;
191 return (error == str) ? deflt :
value;
201 char* error =
nullptr;
203 const double value = strtod(str, &error);
220 static const int kMaxLen = 5;
221 char value[kMaxLen + 1];
223 while (absl::ascii_isspace(*str)) {
227 for (; len <= kMaxLen && absl::ascii_isalnum(*str); ++str) {
228 value[len++] = absl::ascii_tolower(*str);
230 if (len == 0 || len > kMaxLen)
return deflt;
234 if (
value[0] ==
'0' ||
value[0] ==
'n')
return false;
235 if (
value[0] ==
'1' ||
value[0] ==
'y')
return true;
238 if (!strcmp(
value,
"no"))
return false;
241 if (!strcmp(
value,
"yes"))
return true;
244 if (!strcmp(
value,
"true"))
return true;
247 if (!strcmp(
value,
"false"))
return false;
#include "ortools/base/logging.h"
uint64_t ParseLeadingUInt64Value(const char *str, uint64_t deflt)
uint64_t ParseLeadingUDec64Value(const char *str, uint64_t deflt)
double ParseLeadingDoubleValue(const char *str, double deflt)
int32_t ParseLeadingDec32Value(const char *str, int32_t deflt)
int64_t ParseLeadingDec64Value(const char *str, int64_t deflt)
int64_t strtoint64(const char *nptr, char **endptr, int base)
uint32_t ParseLeadingUDec32Value(const char *str, uint32_t deflt)
uint64_t strtouint64(const char *nptr, char **endptr, int base)
uint32_t strtouint32(const char *nptr, char **endptr, int base)
int32_t ParseLeadingInt32Value(const char *str, int32_t deflt)
false no n y bool ParseLeadingBoolValue(const char *str, bool deflt)
uint64_t ParseLeadingHex64Value(const char *str, uint64_t deflt)
int32_t strtoint32(const char *nptr, char **endptr, int base)
uint32_t ParseLeadingUInt32Value(const char *str, uint32_t deflt)
int64_t ParseLeadingInt64Value(const char *str, int64_t deflt)