Monotone-Parent: 829091932d60b0fc62276de7ab03d48d248b54e1

Monotone-Revision: 3e42d115059ba6eeaba7c45ff4f1b67baae90829

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2007-12-20T21:57:49
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2007-12-20 21:57:49 +00:00
parent 1808dddda5
commit 53d1958055
4 changed files with 49 additions and 17 deletions
+7
View File
@@ -1,3 +1,10 @@
2007-12-20 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* NSString+NGCards.m ([NSString
-componentsWithSafeSeparator:separator]): new method that
separated the elements of a string into an array while avoiding
escaped instances of the separator passed as parameter.
2007-12-12 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* iCalTimeZone.m ([iCalTimeZone -periodForDate:date]): at least
+2 -2
View File
@@ -247,7 +247,7 @@
free (content);
content = NULL;
// NSLog (@"content: '%@'", s);
contentValues = [s componentsSeparatedByString: @";"];
contentValues = [s componentsWithSafeSeparator: ';'];
}
else
contentValues = nil;
@@ -270,7 +270,7 @@
else
{
/* increase content */
content =
content =
realloc (content, (contentLength + _len+2) * sizeof(unichar));
memcpy (&(content[contentLength]), _chars,
(_len * sizeof(unichar)));
+2 -1
View File
@@ -25,6 +25,7 @@
#import <Foundation/NSString.h>
@class NSArray;
@class NSCalendarDate;
@class NSTimeZone;
@@ -39,7 +40,7 @@
- (NSCalendarDate *) asCalendarDate;
- (BOOL) isAllDayDate;
- (NSArray *) commaSeparatedValues;
- (NSArray *) componentsWithSafeSeparator: (unichar) separator;
@end
+38 -14
View File
@@ -261,26 +261,50 @@ static NSString *commaSeparator = nil;
return ([self length] == 8);
}
- (NSArray *) commaSeparatedValues
- (NSArray *) componentsWithSafeSeparator: (unichar) separator
{
NSEnumerator *rawValues;
NSMutableArray *values;
NSString *currentValue, *newValue;
NSMutableArray *components;
NSRange currentRange;
unichar *stringBuffer;
unichar currentChar;
unsigned int count, length;
BOOL escaped;
values = [NSMutableArray new];
[values autorelease];
components = [NSMutableArray array];
rawValues = [[self componentsSeparatedByString: @","] objectEnumerator];
currentValue = [rawValues nextObject];
while (currentValue)
length = [self length];
stringBuffer = malloc (sizeof (unichar) * length);
[self getCharacters: stringBuffer];
currentRange = NSMakeRange(0, 0);
escaped = NO;
count = 0;
while (count < length)
{
newValue = [currentValue stringByTrimmingSpaces];
if ([newValue length])
[values addObject: newValue];
currentValue = [rawValues nextObject];
if (escaped)
currentRange.length++;
else
{
currentChar = *(stringBuffer + count);
if (currentChar == '\\')
escaped = YES;
else if (currentChar == separator)
{
[components
addObject: [self substringWithRange: currentRange]];
currentRange = NSMakeRange (count + 1, 0);
}
else
currentRange.length++;
}
count++;
}
[components
addObject: [self substringWithRange: currentRange]];
return values;
free (stringBuffer);
return components;
}
@end