MCPcopy Create free account
hub / github.com/NazaraEngine/NazaraEngine / IsNumber

Method IsNumber

src/Nazara/Core/String.cpp:2469–2529  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2467 */
2468
2469 bool String::IsNumber(UInt8 base, UInt32 flags) const
2470 {
2471 #if NAZARA_CORE_SAFE
2472 if (base < 2 || base > 36)
2473 {
2474 NazaraError("Base must be between 2 and 36");
2475 return false;
2476 }
2477 #endif
2478
2479 if (m_sharedString->size == 0)
2480 return false;
2481
2482 String check = Simplified();
2483 if (check.m_sharedString->size == 0)
2484 return false;
2485
2486 char* ptr = (check.m_sharedString->string[0] == '-') ? &check.m_sharedString->string[1] : check.m_sharedString->string.get();
2487
2488 if (base > 10)
2489 {
2490 if (flags & CaseInsensitive)
2491 {
2492 char limitLower = 'a' + base-10 - 1;
2493 char limitUpper = 'A' + base-10 - 1;
2494
2495 do
2496 {
2497 char c = *ptr;
2498 if (c != ' ' && (c < '0' || (c > '9' && c < 'A') || (c > limitUpper && c < 'a') || c > limitLower))
2499 return false;
2500 }
2501 while (*++ptr);
2502 }
2503 else
2504 {
2505 char limit = 'a' + base-10 - 1;
2506 do
2507 {
2508 char c = *ptr;
2509 if (c != ' ' && (c < '0' || (c > '9' && c < 'a') || c > limit))
2510 return false;
2511 }
2512 while (*++ptr);
2513 }
2514 }
2515 else
2516 {
2517 char limit = '0' + base - 1;
2518
2519 do
2520 {
2521 char c = *ptr;
2522 if (c != ' ' && (c < '0' || c > limit))
2523 return false;
2524 }
2525 while (*++ptr);
2526 }

Callers 2

ParseMethod · 0.80
String.cppFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected