From 9bb157fdd3fbd699ceef737e55e08382e613490c Mon Sep 17 00:00:00 2001 From: helge Date: Thu, 24 Nov 2005 23:01:51 +0000 Subject: [PATCH] fixed a Unicode issue git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1190 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-xml/SaxObjC/ChangeLog | 5 ++ sope-xml/SaxObjC/SaxMethodCallHandler.m | 76 +++++++++++++------------ sope-xml/SaxObjC/Version | 2 +- 3 files changed, 47 insertions(+), 36 deletions(-) diff --git a/sope-xml/SaxObjC/ChangeLog b/sope-xml/SaxObjC/ChangeLog index 2ae3f6c7..a8f58a8c 100644 --- a/sope-xml/SaxObjC/ChangeLog +++ b/sope-xml/SaxObjC/ChangeLog @@ -1,3 +1,8 @@ +2005-11-25 Helge Hess + + * SaxMethodCallHandler.m: rewrote tag=>selector mapping function to be + Unicode safe (v4.5.53) + 2005-08-16 Helge Hess * v4.5.52 diff --git a/sope-xml/SaxObjC/SaxMethodCallHandler.m b/sope-xml/SaxObjC/SaxMethodCallHandler.m index 85ed9e4b..b6c97228 100644 --- a/sope-xml/SaxObjC/SaxMethodCallHandler.m +++ b/sope-xml/SaxObjC/SaxMethodCallHandler.m @@ -36,12 +36,13 @@ static BOOL debugOn = NO; - (id)init { - if ((self = [super init])) { + if ((self = [super init]) != nil) { self->delegate = self; - self->fqNameToStartSel = NSCreateMapTable(NSObjectMapKeyCallBacks, - NSNonOwnedPointerMapValueCallBacks, - 64); + self->fqNameToStartSel = + NSCreateMapTable(NSObjectMapKeyCallBacks, + NSNonOwnedPointerMapValueCallBacks, + 64); self->selName = [[NSMutableString alloc] initWithCapacity:64]; self->tagStack = [[NSMutableArray alloc] initWithCapacity:16]; @@ -137,52 +138,57 @@ static inline void _selAdd(SaxMethodCallHandler *self, NSString *_s) { [self->selName appendString:_s]; } static inline void _selAddEscaped(SaxMethodCallHandler *self, NSString *_s) { - const unsigned char *cstr; register unsigned i, len; + unichar *buf16; BOOL needsEscape = NO; + unichar *buf; + unsigned j; + NSString *s; - if ((len = [_s cStringLength]) == 0) + if ((len = [_s length]) == 0) return; - cstr = (const unsigned char *)[_s cString]; + buf16 = calloc(len + 2, sizeof(unichar)); for (i = 0; i < len; i++) { - register unsigned char c = cstr[i]; - - if (!(isalnum((int)c) || (c == '_'))) { + // TODO: does isalnum work OK for Unicode? (at least it takes an int) + if (!(isalnum(buf16[i]) || (buf16[i] == '_'))) { needsEscape = YES; break; } } - if (needsEscape) { - unsigned char *buf; - unsigned j; - NSString *s; - - buf = malloc(len + 1); - for (i = 0, j = 0; i < len; i++) { - register unsigned char c = cstr[i]; + if (!needsEscape) { /* no escaping required, stop processing */ + if (buf16 != NULL) free(buf16); + [self->selName appendString:_s]; + return; + } + + /* strip out all non-ASCII, non-alnum or _ chars */ + + buf = calloc(len + 2, sizeof(unichar)); + for (i = 0, j = 0; i < len; i++) { + register unichar c = buf16[i]; - if (isalnum((int)c) || (c == '_')) { - if (i > 0) { - if (cstr[i - 1] == '-') - c = toupper(c); - } - buf[j] = c; - j++; - } - else { - /* do nothing, leave out char */ + // TODO: isalnum() vs Unicode + if (isalnum((int)c) || (c == '_')) { + if (i > 0) { + if (buf16[i - 1] == '-') + c = toupper(c); } + buf[j] = c; + j++; } - buf[j] = '\0'; - - s = [[NSString alloc] initWithCString:(char *)buf length:j]; - [self->selName appendString:s]; - [s release]; + /* else: do nothing, leave out non-ASCII char */ } - else - [self->selName appendString:_s]; + buf[j] = '\0'; + + if (buf16 != NULL) free(buf16); + + s = [[NSString alloc] initWithCharacters:buf length:j]; + if (buf != NULL) free(buf); + + [self->selName appendString:s]; + [s release]; } - (void)startElement:(NSString *)_localName diff --git a/sope-xml/SaxObjC/Version b/sope-xml/SaxObjC/Version index 063faafb..d124b50f 100644 --- a/sope-xml/SaxObjC/Version +++ b/sope-xml/SaxObjC/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=52 +SUBMINOR_VERSION:=53 -- 2.39.5