Fossil SCM

Code simplification. No change in functionality.

jan.nijtmans 2014-04-04 10:57 trunk
Commit 8d627980aa3b7a79314613667ff79f44114e6165
1 file changed +16 -19
+16 -19
--- src/th.c
+++ src/th.c
@@ -1878,28 +1878,26 @@
18781878
Th_Interp *interp,
18791879
const char *zInput,
18801880
int nInput,
18811881
int *pnLiteral
18821882
){
1883
- int i = 0;
1883
+ int i;
18841884
int seenDot = 0;
18851885
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];
19011899
if( !isdigit(c) ){
19021900
break;
19031901
}
19041902
}
19051903
*pnLiteral = i;
@@ -2193,13 +2191,12 @@
21932191
Expr *pNew = (Expr *)Th_Malloc(interp, sizeof(Expr));
21942192
const char *z = &zExpr[i];
21952193
21962194
switch (c) {
21972195
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;
22012198
}
22022199
/* fall through */
22032200
case '1': case '2': case '3': case '4': case '5':
22042201
case '6': case '7': case '8': case '9':
22052202
thNextNumber(interp, z, nExpr-i, &pNew->nValue);
22062203
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button