MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / integerValue

Function integerValue

modules/dasSQLITE/sqlite/shell.c:887–928  ·  view source on GitHub ↗

** Interpret zArg as an integer value, possibly with suffixes. */

Source from the content-addressed store, hash-verified

885** Interpret zArg as an integer value, possibly with suffixes.
886*/
887static sqlite3_int64 integerValue(const char *zArg){
888 sqlite3_int64 v = 0;
889 static const struct { char *zSuffix; int iMult; } aMult[] = {
890 { "KiB", 1024 },
891 { "MiB", 1024*1024 },
892 { "GiB", 1024*1024*1024 },
893 { "KB", 1000 },
894 { "MB", 1000000 },
895 { "GB", 1000000000 },
896 { "K", 1000 },
897 { "M", 1000000 },
898 { "G", 1000000000 },
899 };
900 int i;
901 int isNeg = 0;
902 if( zArg[0]=='-' ){
903 isNeg = 1;
904 zArg++;
905 }else if( zArg[0]=='+' ){
906 zArg++;
907 }
908 if( zArg[0]=='0' && zArg[1]=='x' ){
909 int x;
910 zArg += 2;
911 while( (x = hexDigitValue(zArg[0]))>=0 ){
912 v = (v<<4) + x;
913 zArg++;
914 }
915 }else{
916 while( IsDigit(zArg[0]) ){
917 v = v*10 + zArg[0] - '0';
918 zArg++;
919 }
920 }
921 for(i=0; i<ArraySize(aMult); i++){
922 if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
923 v *= aMult[i].iMult;
924 break;
925 }
926 }
927 return isNeg? -v : v;
928}
929
930/*
931** A variable length string to which one can append text.

Callers 4

expertDotCommandFunction · 0.85
booleanValueFunction · 0.85
do_meta_commandFunction · 0.85
wmainFunction · 0.85

Calls 2

hexDigitValueFunction · 0.85
IsDigitFunction · 0.85

Tested by

no test coverage detected