| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#ifndef DMLC_STRTONUM_H_ |
| 7 |
#define DMLC_STRTONUM_H_ |
| 8 |
|
| 9 |
#if DMLC_USE_CXX11 |
| 10 |
#include <type_traits> |
| 11 |
#endif |
| 12 |
|
| 13 |
#include <cstdint> |
| 14 |
#include <limits> |
| 15 |
#include <string> |
| 16 |
|
| 17 |
#include "./base.h" |
| 18 |
#include "./logging.h" |
| 19 |
|
| 20 |
namespace dmlc { |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
inline bool isspace(char c) { |
| 28 |
return (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f'); |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
inline bool isblank(char c) { |
| 38 |
return (c == ' ' || c == '\t'); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
inline bool isdigit(char c) { |
| 48 |
return (c >= '0' && c <= '9'); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
inline bool isalpha(char c) { |
| 58 |
static_assert(static_cast<int>('A') == 65 && static_cast<int>('Z' - 'A') == 25, |
| 59 |
"Only system with ASCII character set is supported"); |
| 60 |
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
inline bool isdigitchars(char c) { |
| 71 |
return (c >= '0' && c <= '9') || c == '+' || c == '-' || c == '.' || c == 'e' || c == 'E'; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
const int kStrtofMaxDigits = 19; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
template <typename FloatType, bool CheckRange = false> |
| 96 |
inline FloatType ParseFloat(const char *nptr, char **endptr) { |
| 97 |
#if DMLC_USE_CXX11 |
| 98 |
static_assert(std::is_same<FloatType, double>::value || std::is_same<FloatType, float>::value, |
| 99 |
"ParseFloat is defined only for 'float' and 'double' types"); |
| 100 |
constexpr unsigned kMaxExponent = (std::is_same<FloatType, double>::value ? 308U : 38U); |
| 101 |
constexpr FloatType kMaxSignificandForMaxExponent = static_cast<FloatType>( |
| 102 |
std::is_same<FloatType, double>::value ? 1.79769313486231570 : 3.402823466); |
| 103 |
|
| 104 |
|
| 105 |
constexpr FloatType kMaxSignificandForNegMaxExponent = static_cast<FloatType>( |
| 106 |
std::is_same<FloatType, double>::value ? 2.22507385850720139 : 1.175494351); |
| 107 |
|
| 108 |
|
| 109 |
#else |
| 110 |
const unsigned kMaxExponent = (sizeof(FloatType) == sizeof(double) ? 308U : 38U); |
| 111 |
const FloatType kMaxSignificandForMaxExponent = static_cast<FloatType>( |
| 112 |
sizeof(FloatType) == sizeof(double) ? 1.79769313486231570 : 3.402823466); |
| 113 |
const FloatType kMaxSignificandForNegMaxExponent = static_cast<FloatType>( |
| 114 |
sizeof(FloatType) == sizeof(double) ? 2.22507385850720139 : 1.175494351); |
| 115 |
#endif |
| 116 |
|
| 117 |
const char *p = nptr; |
| 118 |
|
| 119 |
while (isspace(*p)) { |
| 120 |
++p; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
bool sign = true; |
| 125 |
if (*p == '-') { |
| 126 |
sign = false; |
| 127 |
++p; |
| 128 |
} else if (*p == '+') { |
| 129 |
++p; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
{ |
| 134 |
int i = 0; |
| 135 |
|
| 136 |
while (i < 8 && static_cast<char>((*p) | 32) == "infinity"[i]) { |
| 137 |
++i; |
| 138 |
++p; |
| 139 |
} |
| 140 |
if (i == 3 || i == 8) { |
| 141 |
if (endptr) { |
| 142 |
*endptr = (char *)p; |
| 143 |
} |
| 144 |
return sign ? std::numeric_limits<FloatType>::infinity() |
| 145 |
: -std::numeric_limits<FloatType>::infinity(); |
| 146 |
} else { |
| 147 |
p -= i; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
i = 0; |
| 152 |
while (i < 3 && static_cast<char>((*p) | 32) == "nan"[i]) { |
| 153 |
++i; |
| 154 |
++p; |
| 155 |
} |
| 156 |
if (i == 3) { |
| 157 |
|
| 158 |
if (*p == '(') { |
| 159 |
++p; |
| 160 |
while (isdigit(*p) || isalpha(*p) || *p == '_') { |
| 161 |
++p; |
| 162 |
} |
| 163 |
CHECK_EQ(*p, ')') << "Invalid NAN literal"; |
| 164 |
++p; |
| 165 |
} |
| 166 |
static_assert( |
| 167 |
std::numeric_limits<FloatType>::has_quiet_NaN, "Only system with quiet NaN is supported"); |
| 168 |
if (endptr) { |
| 169 |
*endptr = (char *)p; |
| 170 |
} |
| 171 |
return std::numeric_limits<FloatType>::quiet_NaN(); |
| 172 |
} else { |
| 173 |
p -= i; |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
uint64_t predec; |
| 179 |
for (predec = 0; isdigit(*p); ++p) { |
| 180 |
predec = predec * 10ULL + static_cast<uint64_t>(*p - '0'); |
| 181 |
} |
| 182 |
FloatType value = static_cast<FloatType>(predec); |
| 183 |
|
| 184 |
|
| 185 |
if (*p == '.') { |
| 186 |
uint64_t pow10 = 1; |
| 187 |
uint64_t val2 = 0; |
| 188 |
int digit_cnt = 0; |
| 189 |
++p; |
| 190 |
while (isdigit(*p)) { |
| 191 |
if (digit_cnt < kStrtofMaxDigits) { |
| 192 |
val2 = val2 * 10ULL + static_cast<uint64_t>(*p - '0'); |
| 193 |
pow10 *= 10ULL; |
| 194 |
} |
| 195 |
++p; |
| 196 |
++digit_cnt; |
| 197 |
} |
| 198 |
value += static_cast<FloatType>(static_cast<double>(val2) / static_cast<double>(pow10)); |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
if ((*p == 'e') || (*p == 'E')) { |
| 203 |
++p; |
| 204 |
bool frac = false; |
| 205 |
FloatType scale = static_cast<FloatType>(1.0f); |
| 206 |
unsigned expon; |
| 207 |
|
| 208 |
if (*p == '-') { |
| 209 |
frac = true; |
| 210 |
++p; |
| 211 |
} else if (*p == '+') { |
| 212 |
++p; |
| 213 |
} |
| 214 |
|
| 215 |
for (expon = 0; isdigit(*p); ++p) { |
| 216 |
expon = expon * 10U + static_cast<unsigned>(*p - '0'); |
| 217 |
} |
| 218 |
if (expon > kMaxExponent) { |
| 219 |
if (CheckRange) { |
| 220 |
errno = ERANGE; |
| 221 |
if (endptr) { |
| 222 |
*endptr = (char *)p; |
| 223 |
} |
| 224 |
return std::numeric_limits<FloatType>::infinity(); |
| 225 |
} else { |
| 226 |
expon = kMaxExponent; |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
if (expon == kMaxExponent |
| 231 |
&& ((!frac && value > kMaxSignificandForMaxExponent) |
| 232 |
|| (frac && value < kMaxSignificandForNegMaxExponent))) { |
| 233 |
if (CheckRange) { |
| 234 |
errno = ERANGE; |
| 235 |
if (endptr) { |
| 236 |
*endptr = (char *)p; |
| 237 |
} |
| 238 |
return std::numeric_limits<FloatType>::infinity(); |
| 239 |
} else { |
| 240 |
value = (frac ? kMaxSignificandForNegMaxExponent : kMaxSignificandForMaxExponent); |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
while (expon >= 8U) { |
| 245 |
scale *= static_cast<FloatType>(1E8f); |
| 246 |
expon -= 8U; |
| 247 |
} |
| 248 |
while (expon > 0U) { |
| 249 |
scale *= static_cast<FloatType>(10.0f); |
| 250 |
expon -= 1U; |
| 251 |
} |
| 252 |
|
| 253 |
value = frac ? (value / scale) : (value * scale); |
| 254 |
} |
| 255 |
|
| 256 |
if (*p == 'f' || *p == 'F') { |
| 257 |
++p; |
| 258 |
} |
| 259 |
|
| 260 |
if (endptr) { |
| 261 |
*endptr = (char *)p; |
| 262 |
} |
| 263 |
return sign ? value : -value; |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
inline float strtof(const char *nptr, char **endptr) { |
| 280 |
return ParseFloat<float>(nptr, endptr); |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
inline float strtof_check_range(const char *nptr, char **endptr) { |
| 298 |
return ParseFloat<float, true>(nptr, endptr); |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
inline double strtod(const char *nptr, char **endptr) { |
| 315 |
return ParseFloat<double>(nptr, endptr); |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
inline double strtod_check_range(const char *nptr, char **endptr) { |
| 333 |
return ParseFloat<double, true>(nptr, endptr); |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
template <typename SignedIntType> |
| 348 |
inline SignedIntType ParseSignedInt(const char *nptr, char **endptr, int base) { |
| 349 |
#ifdef DMLC_USE_CXX11 |
| 350 |
static_assert(std::is_signed<SignedIntType>::value && std::is_integral<SignedIntType>::value, |
| 351 |
"ParseSignedInt is defined for signed integers only"); |
| 352 |
#endif |
| 353 |
CHECK(base <= 10 && base >= 2); |
| 354 |
const char *p = nptr; |
| 355 |
|
| 356 |
while (isspace(*p)) { |
| 357 |
++p; |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
bool sign = true; |
| 362 |
if (*p == '-') { |
| 363 |
sign = false; |
| 364 |
++p; |
| 365 |
} else if (*p == '+') { |
| 366 |
++p; |
| 367 |
} |
| 368 |
|
| 369 |
SignedIntType value; |
| 370 |
const SignedIntType base_val = static_cast<SignedIntType>(base); |
| 371 |
for (value = 0; isdigit(*p); ++p) { |
| 372 |
value = value * base_val + static_cast<SignedIntType>(*p - '0'); |
| 373 |
} |
| 374 |
|
| 375 |
if (endptr) { |
| 376 |
*endptr = (char *)p; |
| 377 |
} |
| 378 |
return sign ? value : -value; |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
template <typename UnsignedIntType> |
| 393 |
inline UnsignedIntType ParseUnsignedInt(const char *nptr, char **endptr, int base) { |
| 394 |
#ifdef DMLC_USE_CXX11 |
| 395 |
static_assert( |
| 396 |
std::is_unsigned<UnsignedIntType>::value && std::is_integral<UnsignedIntType>::value, |
| 397 |
"ParseUnsignedInt is defined for unsigned integers only"); |
| 398 |
#endif |
| 399 |
CHECK(base <= 10 && base >= 2); |
| 400 |
const char *p = nptr; |
| 401 |
|
| 402 |
while (isspace(*p)) { |
| 403 |
++p; |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
bool sign = true; |
| 408 |
if (*p == '-') { |
| 409 |
sign = false; |
| 410 |
++p; |
| 411 |
} else if (*p == '+') { |
| 412 |
++p; |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
CHECK_EQ(sign, true); |
| 417 |
|
| 418 |
UnsignedIntType value; |
| 419 |
const UnsignedIntType base_val = static_cast<UnsignedIntType>(base); |
| 420 |
for (value = 0; isdigit(*p); ++p) { |
| 421 |
value = value * base_val + static_cast<UnsignedIntType>(*p - '0'); |
| 422 |
} |
| 423 |
|
| 424 |
if (endptr) { |
| 425 |
*endptr = (char *)p; |
| 426 |
} |
| 427 |
return value; |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
inline uint64_t strtoull(const char *nptr, char **endptr, int base) { |
| 443 |
return ParseUnsignedInt<uint64_t>(nptr, endptr, base); |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
inline long atol(const char *p) { |
| 455 |
return ParseSignedInt<long>(p, 0, 10); |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
inline float atof(const char *nptr) { |
| 469 |
return strtof(nptr, 0); |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
inline float stof(const std::string &value, size_t *pos = nullptr) { |
| 488 |
const char *str_source = value.c_str(); |
| 489 |
char *endptr; |
| 490 |
const float parsed_value = dmlc::strtof_check_range(str_source, &endptr); |
| 491 |
if (errno == ERANGE && parsed_value == std::numeric_limits<float>::infinity()) { |
| 492 |
throw std::out_of_range("Out of range value"); |
| 493 |
} else if (const_cast<const char *>(endptr) == str_source) { |
| 494 |
throw std::invalid_argument("No conversion could be performed"); |
| 495 |
} |
| 496 |
if (pos) { |
| 497 |
*pos = static_cast<size_t>(const_cast<const char *>(endptr) - str_source); |
| 498 |
} |
| 499 |
return parsed_value; |
| 500 |
} |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
inline double stod(const std::string &value, size_t *pos = nullptr) { |
| 518 |
const char *str_source = value.c_str(); |
| 519 |
char *endptr; |
| 520 |
const double parsed_value = dmlc::strtod_check_range(str_source, &endptr); |
| 521 |
if (errno == ERANGE && parsed_value == std::numeric_limits<double>::infinity()) { |
| 522 |
throw std::out_of_range("Out of range value"); |
| 523 |
} else if (const_cast<const char *>(endptr) == str_source) { |
| 524 |
throw std::invalid_argument("No conversion could be performed"); |
| 525 |
} |
| 526 |
if (pos) { |
| 527 |
*pos = static_cast<size_t>(const_cast<const char *>(endptr) - str_source); |
| 528 |
} |
| 529 |
return parsed_value; |
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
template <typename T> |
| 539 |
class Str2T { |
| 540 |
public: |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
static inline T get(const char *begin); |
| 547 |
}; |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
template <typename T> |
| 556 |
inline T Str2Type(const char *begin) { |
| 557 |
return Str2T<T>::get(begin); |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
template <> |
| 564 |
class Str2T<int32_t> { |
| 565 |
public: |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
static inline int32_t get(const char *begin) { |
| 572 |
return ParseSignedInt<int32_t>(begin, NULL, 10); |
| 573 |
} |
| 574 |
}; |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
template <> |
| 580 |
class Str2T<uint32_t> { |
| 581 |
public: |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
static inline uint32_t get(const char *begin) { |
| 588 |
return ParseUnsignedInt<uint32_t>(begin, NULL, 10); |
| 589 |
} |
| 590 |
}; |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
template <> |
| 596 |
class Str2T<int64_t> { |
| 597 |
public: |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
static inline int64_t get(const char *begin) { |
| 604 |
return ParseSignedInt<int64_t>(begin, NULL, 10); |
| 605 |
} |
| 606 |
}; |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
template <> |
| 612 |
class Str2T<uint64_t> { |
| 613 |
public: |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
static inline uint64_t get(const char *begin) { |
| 620 |
return ParseUnsignedInt<uint64_t>(begin, NULL, 10); |
| 621 |
} |
| 622 |
}; |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
template <> |
| 628 |
class Str2T<float> { |
| 629 |
public: |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
static inline float get(const char *begin) { |
| 636 |
return atof(begin); |
| 637 |
} |
| 638 |
}; |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
template <> |
| 644 |
class Str2T<double> { |
| 645 |
public: |
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
static inline double get(const char *begin) { |
| 652 |
return strtod(begin, 0); |
| 653 |
} |
| 654 |
}; |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
template <typename T1, typename T2> |
| 668 |
inline int ParsePair( |
| 669 |
const char *begin, const char *end, const char **endptr, T1 &v1, T2 &v2) { |
| 670 |
const char *p = begin; |
| 671 |
while (p != end && !isdigitchars(*p)) { |
| 672 |
++p; |
| 673 |
} |
| 674 |
if (p == end) { |
| 675 |
*endptr = end; |
| 676 |
return 0; |
| 677 |
} |
| 678 |
const char *q = p; |
| 679 |
while (q != end && isdigitchars(*q)) { |
| 680 |
++q; |
| 681 |
} |
| 682 |
v1 = Str2Type<T1>(p); |
| 683 |
p = q; |
| 684 |
while (p != end && isblank(*p)) { |
| 685 |
++p; |
| 686 |
} |
| 687 |
if (p == end || *p != ':') { |
| 688 |
|
| 689 |
*endptr = p; |
| 690 |
return 1; |
| 691 |
} |
| 692 |
p++; |
| 693 |
while (p != end && !isdigitchars(*p)) { |
| 694 |
++p; |
| 695 |
} |
| 696 |
q = p; |
| 697 |
while (q != end && isdigitchars(*q)) { |
| 698 |
++q; |
| 699 |
} |
| 700 |
*endptr = q; |
| 701 |
v2 = Str2Type<T2>(p); |
| 702 |
return 2; |
| 703 |
} |
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
template <typename T1, typename T2, typename T3> |
| 719 |
inline int ParseTriple( |
| 720 |
const char *begin, const char *end, const char **endptr, T1 &v1, T2 &v2, T3 &v3) { |
| 721 |
const char *p = begin; |
| 722 |
while (p != end && !isdigitchars(*p)) { |
| 723 |
++p; |
| 724 |
} |
| 725 |
if (p == end) { |
| 726 |
*endptr = end; |
| 727 |
return 0; |
| 728 |
} |
| 729 |
const char *q = p; |
| 730 |
while (q != end && isdigitchars(*q)) { |
| 731 |
++q; |
| 732 |
} |
| 733 |
v1 = Str2Type<T1>(p); |
| 734 |
p = q; |
| 735 |
while (p != end && isblank(*p)) { |
| 736 |
++p; |
| 737 |
} |
| 738 |
if (p == end || *p != ':') { |
| 739 |
|
| 740 |
*endptr = p; |
| 741 |
return 1; |
| 742 |
} |
| 743 |
p++; |
| 744 |
while (p != end && !isdigitchars(*p)) { |
| 745 |
++p; |
| 746 |
} |
| 747 |
q = p; |
| 748 |
while (q != end && isdigitchars(*q)) { |
| 749 |
++q; |
| 750 |
} |
| 751 |
v2 = Str2Type<T2>(p); |
| 752 |
p = q; |
| 753 |
while (p != end && isblank(*p)) { |
| 754 |
++p; |
| 755 |
} |
| 756 |
if (p == end || *p != ':') { |
| 757 |
|
| 758 |
*endptr = p; |
| 759 |
return 2; |
| 760 |
} |
| 761 |
p++; |
| 762 |
while (p != end && !isdigitchars(*p)) { |
| 763 |
++p; |
| 764 |
} |
| 765 |
q = p; |
| 766 |
while (q != end && isdigitchars(*q)) { |
| 767 |
++q; |
| 768 |
} |
| 769 |
*endptr = q; |
| 770 |
v3 = Str2Type<T3>(p); |
| 771 |
return 3; |
| 772 |
} |
| 773 |
} |
| 774 |
|
| 775 |
#endif |