mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-08-10 09:23:25 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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)));
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user