MCPcopy Create free account
hub / github.com/anjo76/angelscript / parseInt

Function parseInt

sdk/add_on/scriptstdstring/scriptstdstring.cpp:805–858  ·  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

803// AngelScript signature:
804// int64 parseInt(const string &in val, uint base = 10, uint &out byteCount = 0)
805static asINT64 parseInt(const string &val, asUINT base, asUINT *byteCount)
806{
807 // Only accept base 10 and 16
808 if( base != 10 && base != 16 )
809 {
810 if( byteCount ) *byteCount = 0;
811 return 0;
812 }
813
814 const char *end = &val[0];
815
816 // Determine the sign
817 bool sign = false;
818 if( *end == '-' )
819 {
820 sign = true;
821 end++;
822 }
823 else if( *end == '+' )
824 end++;
825
826 asINT64 res = 0;
827 if( base == 10 )
828 {
829 while( *end >= '0' && *end <= '9' )
830 {
831 res *= 10;
832 res += *end++ - '0';
833 }
834 }
835 else if( base == 16 )
836 {
837 while( (*end >= '0' && *end <= '9') ||
838 (*end >= 'a' && *end <= 'f') ||
839 (*end >= 'A' && *end <= 'F') )
840 {
841 res *= 16;
842 if( *end >= '0' && *end <= '9' )
843 res += *end++ - '0';
844 else if( *end >= 'a' && *end <= 'f' )
845 res += *end++ - 'a' + 10;
846 else if( *end >= 'A' && *end <= 'F' )
847 res += *end++ - 'A' + 10;
848 }
849 }
850
851 if( byteCount )
852 *byteCount = asUINT(size_t(end - val.c_str()));
853
854 if( sign )
855 res = -res;
856
857 return res;
858}
859
860// AngelScript signature:
861// 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