2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 @implementation NSMutableString(XmlRpcDecoder)
26 - (void)appendXmlRpcString:(NSString *)_value {
27 #if 1 // TODO: to be tested !
30 unichar *buf, *escbuf = NULL;
32 if ((len = [_value length]) == 0)
33 /* nothing to add ... */
40 switch ((c = [_value characterAtIndex:0])) {
41 case '&': [self appendString:@"&"]; break;
42 case '<': [self appendString:@"<"]; break;
43 case '>': [self appendString:@">"]; break;
44 case '"': [self appendString:@"""]; break;
45 default: [self appendString:_value]; break;
50 buf = calloc(len + 2, sizeof(unichar));
51 [_value getCharacters:buf];
53 for (i = 0, j = 0; i < len; i++) {
61 /* worst case: string consists of quotes */
62 escbuf = calloc(len * 6 + 2, sizeof(unichar));
63 memcpy(escbuf, buf, i * sizeof(unichar));
69 escbuf[j++] = 'a'; escbuf[j++] = 'm'; escbuf[j++] = 'p';
72 escbuf[j++] = 'l'; escbuf[j++] = 't';
75 escbuf[j++] = 'g'; escbuf[j++] = 't';
78 escbuf[j++] = 'q'; escbuf[j++] = 'u';
79 escbuf[j++] = 'o'; escbuf[j++] = 't';
95 s = [[NSString alloc] initWithCharacters:escbuf length:j];
96 [self appendString:s];
101 [self appendString:_value];
106 void (*addBytes)(id,SEL,const char *,unsigned);
112 if ([_value length] == 0) return;
114 clen = [_value cStringLength];
115 if (clen == 0) return; /* nothing to add .. */
117 cbuf = cstr = malloc(clen + 1);
118 [_value getCString:cbuf]; cbuf[clen] = '\0';
119 dummy = [[NSMutableData alloc] initWithCapacity:2*clen];
121 addBytes = (void*)[dummy methodForSelector:@selector(appendBytes:length:)];
122 NSAssert(addBytes != NULL, @"could not get appendBytes:length: ..");
127 addBytes(dummy, @selector(appendBytes:length:), "&", 5);
130 addBytes(dummy, @selector(appendBytes:length:), "<", 4);
133 addBytes(dummy, @selector(appendBytes:length:), ">", 4);
136 addBytes(dummy, @selector(appendBytes:length:), """, 6);
140 addBytes(dummy, @selector(appendBytes:length:), cstr, 1);
149 tmp = [[NSString alloc] initWithData:dummy
150 encoding:[NSString defaultCStringEncoding]];
151 [self appendString:tmp];
157 @end /* NSMutableString(XmlRpcDecoder) */