Fossil SCM
Code simplification. No change in functionality.
Commit
8d627980aa3b7a79314613667ff79f44114e6165
Parent
99901fbf7951a54…
1 file changed
+16
-19
M
src/th.c
+16
-19
| --- src/th.c | ||
| +++ src/th.c | ||
| @@ -1878,28 +1878,26 @@ | ||
| 1878 | 1878 | Th_Interp *interp, |
| 1879 | 1879 | const char *zInput, |
| 1880 | 1880 | int nInput, |
| 1881 | 1881 | int *pnLiteral |
| 1882 | 1882 | ){ |
| 1883 | - int i = 0; | |
| 1883 | + int i; | |
| 1884 | 1884 | int seenDot = 0; |
| 1885 | 1885 | int (*isdigit)(char) = th_isdigit; |
| 1886 | - if( nInput>2 ){ | |
| 1887 | - if( zInput[1]=='x' || zInput[1]=='X' ){ | |
| 1888 | - i=2; | |
| 1889 | - isdigit = th_ishexdig; | |
| 1890 | - }else if( zInput[1]=='o' || zInput[1]=='O' ){ | |
| 1891 | - i=2; | |
| 1892 | - }else if( zInput[1]=='b' || zInput[1]=='B' ){ | |
| 1893 | - i=2; | |
| 1894 | - }else{ | |
| 1895 | - *pnLiteral = 0; | |
| 1896 | - return TH_OK; | |
| 1897 | - } | |
| 1898 | - } | |
| 1899 | - for(; i<nInput; i++){ | |
| 1900 | - char c = zInput[i]; | |
| 1886 | + char c; | |
| 1887 | + | |
| 1888 | + if( nInput<3) return TH_ERROR; | |
| 1889 | + assert(zInput[0]=='0'); | |
| 1890 | + c = zInput[1]; | |
| 1891 | + if( c>='A' && c<='Z' ) c += 'a' - 'A'; | |
| 1892 | + if( c=='x' ){ | |
| 1893 | + isdigit = th_ishexdig; | |
| 1894 | + }else if( c!='o' && c!='b' ){ | |
| 1895 | + return TH_ERROR; | |
| 1896 | + } | |
| 1897 | + for(i=2; i<nInput; i++){ | |
| 1898 | + c = zInput[i]; | |
| 1901 | 1899 | if( !isdigit(c) ){ |
| 1902 | 1900 | break; |
| 1903 | 1901 | } |
| 1904 | 1902 | } |
| 1905 | 1903 | *pnLiteral = i; |
| @@ -2193,13 +2191,12 @@ | ||
| 2193 | 2191 | Expr *pNew = (Expr *)Th_Malloc(interp, sizeof(Expr)); |
| 2194 | 2192 | const char *z = &zExpr[i]; |
| 2195 | 2193 | |
| 2196 | 2194 | switch (c) { |
| 2197 | 2195 | case '0': |
| 2198 | - if( (i+2<nExpr) && th_isalpha(zExpr[i+1]) ){ | |
| 2199 | - thNextInteger(interp, z, nExpr-i, &pNew->nValue); | |
| 2200 | - if(pNew->nValue) break; | |
| 2196 | + if( thNextInteger(interp, z, nExpr-i, &pNew->nValue)==TH_OK ){ | |
| 2197 | + break; | |
| 2201 | 2198 | } |
| 2202 | 2199 | /* fall through */ |
| 2203 | 2200 | case '1': case '2': case '3': case '4': case '5': |
| 2204 | 2201 | case '6': case '7': case '8': case '9': |
| 2205 | 2202 | thNextNumber(interp, z, nExpr-i, &pNew->nValue); |
| 2206 | 2203 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -1878,28 +1878,26 @@ | |
| 1878 | Th_Interp *interp, |
| 1879 | const char *zInput, |
| 1880 | int nInput, |
| 1881 | int *pnLiteral |
| 1882 | ){ |
| 1883 | int i = 0; |
| 1884 | int seenDot = 0; |
| 1885 | int (*isdigit)(char) = th_isdigit; |
| 1886 | if( nInput>2 ){ |
| 1887 | if( zInput[1]=='x' || zInput[1]=='X' ){ |
| 1888 | i=2; |
| 1889 | isdigit = th_ishexdig; |
| 1890 | }else if( zInput[1]=='o' || zInput[1]=='O' ){ |
| 1891 | i=2; |
| 1892 | }else if( zInput[1]=='b' || zInput[1]=='B' ){ |
| 1893 | i=2; |
| 1894 | }else{ |
| 1895 | *pnLiteral = 0; |
| 1896 | return TH_OK; |
| 1897 | } |
| 1898 | } |
| 1899 | for(; i<nInput; i++){ |
| 1900 | char c = zInput[i]; |
| 1901 | if( !isdigit(c) ){ |
| 1902 | break; |
| 1903 | } |
| 1904 | } |
| 1905 | *pnLiteral = i; |
| @@ -2193,13 +2191,12 @@ | |
| 2193 | Expr *pNew = (Expr *)Th_Malloc(interp, sizeof(Expr)); |
| 2194 | const char *z = &zExpr[i]; |
| 2195 | |
| 2196 | switch (c) { |
| 2197 | case '0': |
| 2198 | if( (i+2<nExpr) && th_isalpha(zExpr[i+1]) ){ |
| 2199 | thNextInteger(interp, z, nExpr-i, &pNew->nValue); |
| 2200 | if(pNew->nValue) break; |
| 2201 | } |
| 2202 | /* fall through */ |
| 2203 | case '1': case '2': case '3': case '4': case '5': |
| 2204 | case '6': case '7': case '8': case '9': |
| 2205 | thNextNumber(interp, z, nExpr-i, &pNew->nValue); |
| 2206 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -1878,28 +1878,26 @@ | |
| 1878 | Th_Interp *interp, |
| 1879 | const char *zInput, |
| 1880 | int nInput, |
| 1881 | int *pnLiteral |
| 1882 | ){ |
| 1883 | int i; |
| 1884 | int seenDot = 0; |
| 1885 | int (*isdigit)(char) = th_isdigit; |
| 1886 | char c; |
| 1887 | |
| 1888 | if( nInput<3) return TH_ERROR; |
| 1889 | assert(zInput[0]=='0'); |
| 1890 | c = zInput[1]; |
| 1891 | if( c>='A' && c<='Z' ) c += 'a' - 'A'; |
| 1892 | if( c=='x' ){ |
| 1893 | isdigit = th_ishexdig; |
| 1894 | }else if( c!='o' && c!='b' ){ |
| 1895 | return TH_ERROR; |
| 1896 | } |
| 1897 | for(i=2; i<nInput; i++){ |
| 1898 | c = zInput[i]; |
| 1899 | if( !isdigit(c) ){ |
| 1900 | break; |
| 1901 | } |
| 1902 | } |
| 1903 | *pnLiteral = i; |
| @@ -2193,13 +2191,12 @@ | |
| 2191 | Expr *pNew = (Expr *)Th_Malloc(interp, sizeof(Expr)); |
| 2192 | const char *z = &zExpr[i]; |
| 2193 | |
| 2194 | switch (c) { |
| 2195 | case '0': |
| 2196 | if( thNextInteger(interp, z, nExpr-i, &pNew->nValue)==TH_OK ){ |
| 2197 | break; |
| 2198 | } |
| 2199 | /* fall through */ |
| 2200 | case '1': case '2': case '3': case '4': case '5': |
| 2201 | case '6': case '7': case '8': case '9': |
| 2202 | thNextNumber(interp, z, nExpr-i, &pNew->nValue); |
| 2203 |