** Interpret zArg as an integer value, possibly with suffixes. */
| 1364 | ** Interpret zArg as an integer value, possibly with suffixes. |
| 1365 | */ |
| 1366 | static sqlite3_int64 integerValue(const char *zArg){ |
| 1367 | sqlite3_int64 v = 0; |
| 1368 | static const struct { char *zSuffix; int iMult; } aMult[] = { |
| 1369 | { "KiB", 1024 }, |
| 1370 | { "MiB", 1024*1024 }, |
| 1371 | { "GiB", 1024*1024*1024 }, |
| 1372 | { "KB", 1000 }, |
| 1373 | { "MB", 1000000 }, |
| 1374 | { "GB", 1000000000 }, |
| 1375 | { "K", 1000 }, |
| 1376 | { "M", 1000000 }, |
| 1377 | { "G", 1000000000 }, |
| 1378 | }; |
| 1379 | int i; |
| 1380 | int isNeg = 0; |
| 1381 | if( zArg[0]=='-' ){ |
| 1382 | isNeg = 1; |
| 1383 | zArg++; |
| 1384 | }else if( zArg[0]=='+' ){ |
| 1385 | zArg++; |
| 1386 | } |
| 1387 | if( zArg[0]=='0' && zArg[1]=='x' ){ |
| 1388 | int x; |
| 1389 | zArg += 2; |
| 1390 | while( (x = hexDigitValue(zArg[0]))>=0 ){ |
| 1391 | v = (v<<4) + x; |
| 1392 | zArg++; |
| 1393 | } |
| 1394 | }else{ |
| 1395 | while( IsDigit(zArg[0]) ){ |
| 1396 | v = v*10 + zArg[0] - '0'; |
| 1397 | zArg++; |
| 1398 | } |
| 1399 | } |
| 1400 | for(i=0; i<ArraySize(aMult); i++){ |
| 1401 | if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){ |
| 1402 | v *= aMult[i].iMult; |
| 1403 | break; |
| 1404 | } |
| 1405 | } |
| 1406 | return isNeg? -v : v; |
| 1407 | } |
| 1408 | |
| 1409 | /* |
| 1410 | ** A variable length string to which one can append text. |
no test coverage detected