MCPcopy Create free account
hub / github.com/audacity/audacity / integerValue

Function integerValue

lib-src/sqlite/shell.c:760–801  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

758** Interpret zArg as an integer value, possibly with suffixes.
759*/
760static sqlite3_int64 integerValue(const char *zArg){
761 sqlite3_int64 v = 0;
762 static const struct { char *zSuffix; int iMult; } aMult[] = {
763 { "KiB", 1024 },
764 { "MiB", 1024*1024 },
765 { "GiB", 1024*1024*1024 },
766 { "KB", 1000 },
767 { "MB", 1000000 },
768 { "GB", 1000000000 },
769 { "K", 1000 },
770 { "M", 1000000 },
771 { "G", 1000000000 },
772 };
773 int i;
774 int isNeg = 0;
775 if( zArg[0]=='-' ){
776 isNeg = 1;
777 zArg++;
778 }else if( zArg[0]=='+' ){
779 zArg++;
780 }
781 if( zArg[0]=='0' && zArg[1]=='x' ){
782 int x;
783 zArg += 2;
784 while( (x = hexDigitValue(zArg[0]))>=0 ){
785 v = (v<<4) + x;
786 zArg++;
787 }
788 }else{
789 while( IsDigit(zArg[0]) ){
790 v = v*10 + zArg[0] - '0';
791 zArg++;
792 }
793 }
794 for(i=0; i<ArraySize(aMult); i++){
795 if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
796 v *= aMult[i].iMult;
797 break;
798 }
799 }
800 return isNeg? -v : v;
801}
802
803/*
804** 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 1

hexDigitValueFunction · 0.85

Tested by

no test coverage detected