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];
[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