Fossil SCM

Use our own isspace() function since the standard-library isspace() sometimes gives incorrect results for non-ASCII characters.

drh 2008-11-03 21:56 trunk
Commit 054dd31b715829b7dd0c75f03e0f2c837f3db1c8
1 file changed +13 -4
+13 -4
--- src/blob.c
+++ src/blob.c
@@ -73,10 +73,19 @@
7373
#define blob_is_reset(x) \
7474
assert((x)->xRealloc!=blobReallocMalloc || (x)->nAlloc==0)
7575
#else
7676
#define blob_is_reset(x)
7777
#endif
78
+
79
+/*
80
+** We find that the built-in isspace() function does not work for
81
+** some international character sets. So here is a substitute.
82
+*/
83
+static int blob_isspace(char c){
84
+ return c==' ' || c=='\n' || c=='\t' ||
85
+ c=='\r' || c=='\f' || c=='\v';
86
+}
7887
7988
/*
8089
** This routine is called if a blob operation fails because we
8190
** have run out of memory.
8291
*/
@@ -411,11 +420,11 @@
411420
** not insert a new zero terminator.
412421
*/
413422
int blob_trim(Blob *p){
414423
char *z = p->aData;
415424
int n = p->nUsed;
416
- while( n>0 && isspace(z[n-1]) ){ n--; }
425
+ while( n>0 && blob_isspace(z[n-1]) ){ n--; }
417426
p->nUsed = n;
418427
return n;
419428
}
420429
421430
/*
@@ -434,15 +443,15 @@
434443
*/
435444
int blob_token(Blob *pFrom, Blob *pTo){
436445
char *aData = pFrom->aData;
437446
int n = pFrom->nUsed;
438447
int i = pFrom->iCursor;
439
- while( i<n && isspace(aData[i]) ){ i++; }
448
+ while( i<n && blob_isspace(aData[i]) ){ i++; }
440449
pFrom->iCursor = i;
441
- while( i<n && !isspace(aData[i]) ){ i++; }
450
+ while( i<n && !blob_isspace(aData[i]) ){ i++; }
442451
blob_extract(pFrom, i-pFrom->iCursor, pTo);
443
- while( i<n && isspace(aData[i]) ){ i++; }
452
+ while( i<n && blob_isspace(aData[i]) ){ i++; }
444453
pFrom->iCursor = i;
445454
return pTo->nUsed;
446455
}
447456
448457
/*
449458
--- src/blob.c
+++ src/blob.c
@@ -73,10 +73,19 @@
73 #define blob_is_reset(x) \
74 assert((x)->xRealloc!=blobReallocMalloc || (x)->nAlloc==0)
75 #else
76 #define blob_is_reset(x)
77 #endif
 
 
 
 
 
 
 
 
 
78
79 /*
80 ** This routine is called if a blob operation fails because we
81 ** have run out of memory.
82 */
@@ -411,11 +420,11 @@
411 ** not insert a new zero terminator.
412 */
413 int blob_trim(Blob *p){
414 char *z = p->aData;
415 int n = p->nUsed;
416 while( n>0 && isspace(z[n-1]) ){ n--; }
417 p->nUsed = n;
418 return n;
419 }
420
421 /*
@@ -434,15 +443,15 @@
434 */
435 int blob_token(Blob *pFrom, Blob *pTo){
436 char *aData = pFrom->aData;
437 int n = pFrom->nUsed;
438 int i = pFrom->iCursor;
439 while( i<n && isspace(aData[i]) ){ i++; }
440 pFrom->iCursor = i;
441 while( i<n && !isspace(aData[i]) ){ i++; }
442 blob_extract(pFrom, i-pFrom->iCursor, pTo);
443 while( i<n && isspace(aData[i]) ){ i++; }
444 pFrom->iCursor = i;
445 return pTo->nUsed;
446 }
447
448 /*
449
--- src/blob.c
+++ src/blob.c
@@ -73,10 +73,19 @@
73 #define blob_is_reset(x) \
74 assert((x)->xRealloc!=blobReallocMalloc || (x)->nAlloc==0)
75 #else
76 #define blob_is_reset(x)
77 #endif
78
79 /*
80 ** We find that the built-in isspace() function does not work for
81 ** some international character sets. So here is a substitute.
82 */
83 static int blob_isspace(char c){
84 return c==' ' || c=='\n' || c=='\t' ||
85 c=='\r' || c=='\f' || c=='\v';
86 }
87
88 /*
89 ** This routine is called if a blob operation fails because we
90 ** have run out of memory.
91 */
@@ -411,11 +420,11 @@
420 ** not insert a new zero terminator.
421 */
422 int blob_trim(Blob *p){
423 char *z = p->aData;
424 int n = p->nUsed;
425 while( n>0 && blob_isspace(z[n-1]) ){ n--; }
426 p->nUsed = n;
427 return n;
428 }
429
430 /*
@@ -434,15 +443,15 @@
443 */
444 int blob_token(Blob *pFrom, Blob *pTo){
445 char *aData = pFrom->aData;
446 int n = pFrom->nUsed;
447 int i = pFrom->iCursor;
448 while( i<n && blob_isspace(aData[i]) ){ i++; }
449 pFrom->iCursor = i;
450 while( i<n && !blob_isspace(aData[i]) ){ i++; }
451 blob_extract(pFrom, i-pFrom->iCursor, pTo);
452 while( i<n && blob_isspace(aData[i]) ){ i++; }
453 pFrom->iCursor = i;
454 return pTo->nUsed;
455 }
456
457 /*
458

Keyboard Shortcuts

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