X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=sope-core%2FNGExtensions%2FFdExt.subproj%2FNSString%2Bmisc.m;fp=sope-core%2FNGExtensions%2FFdExt.subproj%2FNSString%2Bmisc.m;h=4093b284b946caa8dd1295c34cec4c298ce14353;hb=b963fea57efd5a37311ae24093b54caad1f6befd;hp=f7a6ffa7c08b66818108692de139a62042fef00f;hpb=745293aa20f6ff270b7f7fc1a231204707b47def;p=sope diff --git a/sope-core/NGExtensions/FdExt.subproj/NSString+misc.m b/sope-core/NGExtensions/FdExt.subproj/NSString+misc.m index f7a6ffa7..4093b284 100644 --- a/sope-core/NGExtensions/FdExt.subproj/NSString+misc.m +++ b/sope-core/NGExtensions/FdExt.subproj/NSString+misc.m @@ -1,6 +1,6 @@ /* - Copyright (C) 2000-2006 SKYRIX Software AG - Copyright (C) 2006 Helge Hess + Copyright (C) 2000-2008 SKYRIX Software AG + Copyright (C) 2006-2008 Helge Hess This file is part of SOPE. @@ -43,30 +43,31 @@ - (NSSet *)bindingVariables { unsigned len, pos = 0; - const char *buf = NULL; + unichar *wbuf = NULL; NSMutableSet *result = nil; - - result = [NSMutableSet set]; - len = [self cStringLength]; - buf = [self cString]; + + result = [NSMutableSet setWithCapacity:16]; + len = [self length]; + wbuf = malloc(sizeof(unichar) * (len + 4)); + [self getCharacters:wbuf]; while (pos < len) { unsigned startPos; if (pos + 1 == len) { /* last entry */ - if (buf[pos] == '$') { /* found $ without end-char */ + if (wbuf[pos] == '$') { /* found $ without end-char */ [[[NSStringVariableBindingException alloc] initWithFormat:@"did not find end of variable for string %@", self] raise]; } break; } - if (buf[pos] != '$') { + if (wbuf[pos] != '$') { pos++; continue; } - if (buf[pos + 1] == '$') { /* found $$ --> ignore*/ + if (wbuf[pos + 1] == '$') { /* found $$ --> ignore*/ pos += 2; continue; } @@ -75,31 +76,31 @@ startPos = pos; - pos += 2; /* buf[pos + 1] != '$' */ + pos += 2; /* wbuf[pos + 1] != '$' */ while (pos < len) { - if (buf[pos] != '$') + if (wbuf[pos] != '$') pos++; else break; } if (pos == len) { /* end of string was reached */ [[[NSStringVariableBindingException alloc] - initWithFormat:@"didn`t find end of " - @"variable for string %@", self] - raise]; + initWithFormat:@"did not find end of variable for string %@", self] + raise]; } else { - NSString *key = nil; - + NSString *key = nil; + key = [[NSString alloc] - initWithCStringNoCopy:(char*)buf + startPos + 1 - length:pos - startPos - 1 - freeWhenDone:NO]; + initWithCharacters:(unichar *)wbuf + startPos + 1 + length:(pos - startPos - 1)]; [result addObject:key]; [key release]; } pos++; } + if (wbuf != NULL) { free(wbuf); wbuf = NULL; } + return [[result copy] autorelease]; } @@ -107,34 +108,38 @@ stringForUnknownBindings:(NSString *)_unknown { unsigned len, pos = 0; - const char *buf = NULL; + unichar *wbuf = NULL; NSMutableString *str = nil; str = [self mutableCopy]; - len = [str cStringLength]; - buf = [str cString]; + len = [str length]; + wbuf = malloc(sizeof(unichar) * (len + 4)); + [self getCharacters:wbuf]; while (pos < len) { if (pos + 1 == len) { /* last entry */ - if (buf[pos] == '$') { /* found $ without end-char */ + if (wbuf[pos] == '$') { /* found $ without end-char */ [[[NSStringVariableBindingException alloc] initWithFormat:@"did not find end of variable for string %@", self] raise]; } break; } - if (buf[pos] == '$') { - if (buf[pos + 1] == '$') { /* found $$ --> $ */ + if (wbuf[pos] == '$') { + if (wbuf[pos + 1] == '$') { /* found $$ --> $ */ [str deleteCharactersInRange:NSMakeRange(pos, 1)]; - buf = [str cString]; - len = [str cStringLength]; + + if (wbuf != NULL) { free(wbuf); wbuf = NULL; } + len = [str length]; + wbuf = malloc(sizeof(unichar) * (len + 4)); + [str getCharacters:wbuf]; } else { unsigned startPos = pos; - pos += 2; /* buf[pos + 1] != '$' */ + pos += 2; /* wbuf[pos + 1] != '$' */ while (pos < len) { - if (buf[pos] != '$') + if (wbuf[pos] != '$') pos++; else break; @@ -149,9 +154,8 @@ NSString *value; key = [[NSString alloc] - initWithCStringNoCopy:(char*)buf + startPos + 1 - length:pos - startPos - 1 - freeWhenDone:NO]; + initWithCharacters:(wbuf + startPos + 1) + length:(pos - startPos - 1)]; if ((value = [_bindings valueForStringBinding:key]) == nil) { if (_unknown == nil) { @@ -164,17 +168,23 @@ value = _unknown; } [key release]; key = nil; + [str replaceCharactersInRange: NSMakeRange(startPos, pos - startPos + 1) withString:value]; - buf = [str cString]; - len = [str cStringLength]; + + if (wbuf != NULL) { free(wbuf); wbuf = NULL; } + len = [str length]; + wbuf = malloc(sizeof(unichar) * (len + 4)); + [str getCharacters:wbuf]; + pos = startPos - 1 + [value length]; } } } pos++; } + if (wbuf != NULL) { free(wbuf); wbuf = NULL; } { id tmp = str; str = [str copy];