MCPcopy Create free account
hub / github.com/CytopiaTeam/Cytopia / parseInt

Function parseInt

external/as_add_on/scriptstdstring/scriptstdstring.cpp:569–622  ·  view source on GitHub ↗

AngelScript signature: int64 parseInt(const string &in val, uint base = 10, uint &out byteCount = 0)

Source from the content-addressed store, hash-verified

567// AngelScript signature:
568// int64 parseInt(const string &in val, uint base = 10, uint &out byteCount = 0)
569static asINT64 parseInt(const string &val, asUINT base, asUINT *byteCount)
570{
571 // Only accept base 10 and 16
572 if( base != 10 && base != 16 )
573 {
574 if( byteCount ) *byteCount = 0;
575 return 0;
576 }
577
578 const char *end = &val[0];
579
580 // Determine the sign
581 bool sign = false;
582 if( *end == '-' )
583 {
584 sign = true;
585 end++;
586 }
587 else if( *end == '+' )
588 end++;
589
590 asINT64 res = 0;
591 if( base == 10 )
592 {
593 while( *end >= '0' && *end <= '9' )
594 {
595 res *= 10;
596 res += *end++ - '0';
597 }
598 }
599 else if( base == 16 )
600 {
601 while( (*end >= '0' && *end <= '9') ||
602 (*end >= 'a' && *end <= 'f') ||
603 (*end >= 'A' && *end <= 'F') )
604 {
605 res *= 16;
606 if( *end >= '0' && *end <= '9' )
607 res += *end++ - '0';
608 else if( *end >= 'a' && *end <= 'f' )
609 res += *end++ - 'a' + 10;
610 else if( *end >= 'A' && *end <= 'F' )
611 res += *end++ - 'A' + 10;
612 }
613 }
614
615 if( byteCount )
616 *byteCount = asUINT(size_t(end - val.c_str()));
617
618 if( sign )
619 res = -res;
620
621 return res;
622}
623
624// AngelScript signature:
625// uint64 parseUInt(const string &in val, uint base = 10, uint &out byteCount = 0)

Callers 1

parseInt_GenericFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected