5 @implementation NSMutableString(XmlRpcDecoder)
7 - (void)appendXmlRpcString:(NSString *)_value {
8 #if 1 // TODO: to be tested !
11 unichar *buf, *escbuf = NULL;
13 if ((len = [_value length]) == 0)
14 /* nothing to add ... */
21 switch ((c = [_value characterAtIndex:0])) {
22 case '&': [self appendString:@"&"]; break;
23 case '<': [self appendString:@"<"]; break;
24 case '>': [self appendString:@">"]; break;
25 case '"': [self appendString:@"""]; break;
26 default: [self appendString:_value]; break;
31 buf = calloc(len + 2, sizeof(unichar));
32 [_value getCharacters:buf];
34 for (i = 0, j = 0; i < len; i++) {
42 /* worst case: string consists of quotes */
43 escbuf = calloc(len * 6 + 2, sizeof(unichar));
44 memcpy(escbuf, buf, i * sizeof(unichar));
50 escbuf[j++] = 'a'; escbuf[j++] = 'm'; escbuf[j++] = 'p';
53 escbuf[j++] = 'l'; escbuf[j++] = 't';
56 escbuf[j++] = 'g'; escbuf[j++] = 't';
59 escbuf[j++] = 'q'; escbuf[j++] = 'u';
60 escbuf[j++] = 'o'; escbuf[j++] = 't';
76 s = [[NSString alloc] initWithCharacters:escbuf length:j];
77 [self appendString:s];
82 [self appendString:_value];
87 void (*addBytes)(id,SEL,const char *,unsigned);
93 if ([_value length] == 0) return;
95 clen = [_value cStringLength];
96 if (clen == 0) return; /* nothing to add .. */
98 cbuf = cstr = malloc(clen + 1);
99 [_value getCString:cbuf]; cbuf[clen] = '\0';
100 dummy = [[NSMutableData alloc] initWithCapacity:2*clen];
102 addBytes = (void*)[dummy methodForSelector:@selector(appendBytes:length:)];
103 NSAssert(addBytes != NULL, @"could not get appendBytes:length: ..");
108 addBytes(dummy, @selector(appendBytes:length:), "&", 5);
111 addBytes(dummy, @selector(appendBytes:length:), "<", 4);
114 addBytes(dummy, @selector(appendBytes:length:), ">", 4);
117 addBytes(dummy, @selector(appendBytes:length:), """, 6);
121 addBytes(dummy, @selector(appendBytes:length:), cstr, 1);
130 tmp = [[NSString alloc] initWithData:dummy
131 encoding:[NSString defaultCStringEncoding]];
132 [self appendString:tmp];
138 @end /* NSMutableString(XmlRpcDecoder) */