merge of '7dba10bc15c3a16348c5fd263d5aeea5ee17d063'
and 'a0b3d112eca99119d0e99fa3a948f74e17a73249' Monotone-Parent: 7dba10bc15c3a16348c5fd263d5aeea5ee17d063 Monotone-Parent: a0b3d112eca99119d0e99fa3a948f74e17a73249 Monotone-Revision: 0a48d70dd58905fd233548415a50a48cf1114607 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-03-15T17:12:05 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
commit
3e2d20947c
|
@ -1,3 +1,9 @@
|
|||
2011-03-15 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* NSString+NGCards.m (-asCardAttributeValues): rewritten method
|
||||
properly in order to parse the values string by properly taking
|
||||
quoted, escaping and special characters into account.
|
||||
|
||||
2011-01-14 Francis Lachapelle <flachapelle@inverse.ca>
|
||||
|
||||
* iCalTimeZone.m (-computedDateForString:): new method that
|
||||
|
|
|
@ -32,16 +32,8 @@
|
|||
|
||||
#import "NSString+NGCards.h"
|
||||
|
||||
static NSString *commaSeparator = nil;
|
||||
|
||||
@implementation NSString (NGCardsExtensions)
|
||||
|
||||
- (void) _initCommaSeparator
|
||||
{
|
||||
commaSeparator = [NSMutableString stringWithFormat: @"%c", 255];
|
||||
[commaSeparator retain];
|
||||
}
|
||||
|
||||
- (NSString *) foldedForVersitCards
|
||||
{
|
||||
NSMutableString *foldedString;
|
||||
|
@ -76,25 +68,85 @@ static NSString *commaSeparator = nil;
|
|||
- (NSArray *) asCardAttributeValues
|
||||
{
|
||||
NSMutableArray *values;
|
||||
NSEnumerator *rawValues;
|
||||
NSString *tmpString, *rawValue, *newString;
|
||||
NSString *newString;
|
||||
unichar *characters, *currentChar, *lastChar, *newPart, *newCurrentChar;
|
||||
NSUInteger max;
|
||||
BOOL isEscaped, isQuoted;
|
||||
|
||||
values = [NSMutableArray array];
|
||||
|
||||
if (!commaSeparator)
|
||||
[self _initCommaSeparator];
|
||||
max = [self length];
|
||||
characters = NSZoneMalloc (NULL, max * sizeof (unichar));
|
||||
[self getCharacters: characters];
|
||||
currentChar = characters;
|
||||
lastChar = characters + max;
|
||||
|
||||
tmpString = [self stringByReplacingString: @"\\,"
|
||||
withString: commaSeparator];
|
||||
rawValues = [[tmpString componentsSeparatedByString: @","]
|
||||
objectEnumerator];
|
||||
while ((rawValue = [rawValues nextObject]))
|
||||
newPart = NSZoneMalloc (NULL, max * sizeof (unichar));
|
||||
newCurrentChar = newPart;
|
||||
|
||||
isEscaped = NO;
|
||||
isQuoted = NO;
|
||||
|
||||
while (currentChar < lastChar)
|
||||
{
|
||||
newString = [rawValue stringByReplacingString: commaSeparator
|
||||
withString: @","];
|
||||
[values addObject: [newString stringByTrimmingSpaces]];
|
||||
if (isQuoted)
|
||||
{
|
||||
if (*currentChar == '"')
|
||||
isQuoted = NO;
|
||||
else
|
||||
{
|
||||
*newCurrentChar = *currentChar;
|
||||
newCurrentChar++;
|
||||
}
|
||||
}
|
||||
else if (isEscaped)
|
||||
{
|
||||
if (*currentChar == 'n' || *currentChar == 'N')
|
||||
*newCurrentChar = '\n';
|
||||
else if (*currentChar == 'r' || *currentChar == 'R')
|
||||
*newCurrentChar = '\r';
|
||||
else if (*currentChar == 't' || *currentChar == 'T')
|
||||
*newCurrentChar = '\t';
|
||||
else if (*currentChar == 'b' || *currentChar == 'B')
|
||||
*newCurrentChar = '\b';
|
||||
else
|
||||
*newCurrentChar = *currentChar;
|
||||
newCurrentChar++;
|
||||
isEscaped = NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*currentChar == '"')
|
||||
isQuoted = YES;
|
||||
else if (*currentChar == '\\')
|
||||
isEscaped = YES;
|
||||
else if (*currentChar == ',')
|
||||
{
|
||||
newString = [[NSString alloc]
|
||||
initWithCharactersNoCopy: newPart
|
||||
length: (newCurrentChar - newPart)
|
||||
freeWhenDone: YES];
|
||||
[values addObject: newString];
|
||||
[newString release];
|
||||
newPart = NSZoneMalloc (NULL, max * sizeof (unichar));
|
||||
newCurrentChar = newPart;
|
||||
}
|
||||
else
|
||||
{
|
||||
*newCurrentChar = *currentChar;
|
||||
newCurrentChar++;
|
||||
}
|
||||
}
|
||||
currentChar++;
|
||||
}
|
||||
|
||||
newString = [[NSString alloc]
|
||||
initWithCharactersNoCopy: newPart
|
||||
length: (newCurrentChar - newPart)
|
||||
freeWhenDone: YES];
|
||||
[values addObject: newString];
|
||||
[newString release];
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
2011-03-15 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* VSSaxDriver.m (-_parseAttr:intoAttr:intoValue:): removed useless
|
||||
"tag" parameter. Removed code handling the quoted values, as it's
|
||||
now done from -[NSString asCardAttributeValues].
|
||||
|
||||
2010-08-11 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* VSSaxDriver.m (_parseAttr:forTag:intoAttr:intoValue:): when no
|
||||
|
|
|
@ -320,7 +320,6 @@ static NSCharacterSet *whitespaceCharSet = nil;
|
|||
}
|
||||
|
||||
- (void) _parseAttr: (NSString *) _attr
|
||||
forTag: (NSString *) _tagName
|
||||
intoAttr: (NSString **) attr_
|
||||
intoValue: (NSString **) value_
|
||||
{
|
||||
|
@ -330,33 +329,8 @@ static NSCharacterSet *whitespaceCharSet = nil;
|
|||
r = [_attr rangeOfCharacterFromSet: equalSignCharSet];
|
||||
if (r.length > 0)
|
||||
{
|
||||
unsigned left, right;
|
||||
|
||||
attrName = [[_attr substringToIndex: r.location] uppercaseString];
|
||||
left = NSMaxRange(r);
|
||||
right = [_attr length] - 1;
|
||||
if (left < right)
|
||||
{
|
||||
if (([_attr characterAtIndex: left] == '"') &&
|
||||
([_attr characterAtIndex: right] == '"'))
|
||||
{
|
||||
left += 1;
|
||||
r = NSMakeRange(left, right - left);
|
||||
attrValue = [_attr substringWithRange: r];
|
||||
}
|
||||
else
|
||||
{
|
||||
attrValue = [_attr substringFromIndex: left];
|
||||
}
|
||||
}
|
||||
else if (left == right)
|
||||
{
|
||||
attrValue = [_attr substringFromIndex: left];
|
||||
}
|
||||
else
|
||||
{
|
||||
attrValue = @"";
|
||||
}
|
||||
attrValue = [_attr substringFromIndex: NSMaxRange(r)];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -411,9 +385,7 @@ static NSCharacterSet *whitespaceCharSet = nil;
|
|||
while (curAttr)
|
||||
{
|
||||
[self _parseAttr: curAttr
|
||||
forTag: _tagName
|
||||
intoAttr: &mappedAttr
|
||||
intoValue: &mappedValue];
|
||||
intoAttr: &mappedAttr intoValue: &mappedValue];
|
||||
values = [[mappedValue asCardAttributeValues] objectEnumerator];
|
||||
curValue = [values nextObject];
|
||||
while (curValue)
|
||||
|
|
Loading…
Reference in a new issue