Monotone-Parent: 584371c66b4989feaab5012db26f19d8ed7cd7ad

Monotone-Revision: 72a4f60ec4a14476e485da2ce400df860572fa48

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2010-01-05T22:34:35
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau committed 2010-01-05 22:34:35 +00:00
1 parent 7c3b61134a
commit aa7e1d2f5a
15 files changed
+987 -241

No files matched your search

+2
View File
@@ -51,6 +51,8 @@
withObject: (id) object1
withObject: (id) object2;
#endif
/* foreach ... */
- (NSArray *) resultsOfSelector: (SEL) operation;
@end
+25 -18
View File
@@ -36,7 +36,7 @@
unsigned int max;
max = [self count];
pointers = NSZoneMalloc (NULL, sizeof(id) * (max + 1));
pointers = NSZoneMalloc (NULL, sizeof (id) * (max + 1));
[self getObjects: pointers];
*(pointers + max) = nil;
@@ -154,6 +154,12 @@
return newArray;
}
- (NSArray *) trimmedComponents
{
return [self resultsOfSelector: @selector (stringByTrimmingSpaces)];
}
#ifdef GNUSTEP_BASE_LIBRARY
- (void) makeObjectsPerform: (SEL) selector
withObject: (id) object1
withObject: (id) object2
@@ -166,6 +172,24 @@
withObject: object1
withObject: object2];
}
#endif
- (NSArray *) resultsOfSelector: (SEL) operation
{
NSMutableArray *results;
int count, max;
id result;
max = [self count];
results = [NSMutableArray arrayWithCapacity: max];
for (count = 0; count < max; count++)
{
result = [[self objectAtIndex: count] performSelector: operation];
[results addObject: result];
}
return results;
}
- (NSString *) jsonRepresentation
{
@@ -204,23 +228,6 @@
return response;
}
- (NSArray *) trimmedComponents
{
NSMutableArray *newComponents;
NSString *currentString;
unsigned int count, max;
max = [self count];
newComponents = [NSMutableArray arrayWithCapacity: max];
for (count = 0; count < max; count++)
{
currentString = [[self objectAtIndex: count] stringByTrimmingSpaces];
[newComponents addObject: currentString];
}
return newComponents;
}
@end
@implementation NSMutableArray (SOGoArrayUtilities)
+1 -1
View File
@@ -47,7 +47,7 @@
- (NSString *) jsonRepresentation;
- (NSString *) asCSSIdentifier;
- (NSString *) fromCSSIdentifier;
/* bare email addresses */
- (NSString *) pureEMailAddress;
+100 -9
View File
@@ -27,6 +27,7 @@
#import <EOControl/EOQualifier.h>
#import <NGExtensions/NSDictionary+misc.h>
#import <NGExtensions/NGQuotedPrintableCoding.h>
#import "NSArray+Utilities.h"
@@ -39,6 +40,10 @@ static NSMutableCharacterSet *urlNonEndingChars = nil;
static NSMutableCharacterSet *urlAfterEndingChars = nil;
static NSMutableCharacterSet *urlStartChars = nil;
static NSString **cssEscapingStrings = NULL;
static unichar *cssEscapingCharacters = NULL;
static int cssEscapingCount = 0;
@implementation NSString (SOGoURLExtension)
- (NSString *) composeURLWithAction: (NSString *) action
@@ -305,23 +310,109 @@ static NSMutableCharacterSet *urlStartChars = nil;
return [self doubleQuotedString];
}
- (void) _setupCSSEscaping
{
NSArray *strings, *characters;
int count;
strings = [NSArray arrayWithObjects: @"_U_", @"_D_", @"_H_", @"_A_", @"_S_",
@"_C_", @"_CO_", @"_SP_", nil];
cssEscapingStrings = [strings asPointersOfObjects];
characters = [NSArray arrayWithObjects: @"_", @".", @"#", @"@", @"*", @":",
@",", @" ", nil];
cssEscapingCharacters
= NSZoneMalloc (NULL, sizeof ((cssEscapingCount + 1) * sizeof (unichar)));
cssEscapingCount = [strings count];
for (count = 0; count < cssEscapingCount; count++)
*(cssEscapingCharacters + count)
= [[characters objectAtIndex: count] characterAtIndex: 0];
*(cssEscapingCharacters + cssEscapingCount) = 0;
}
- (int) _cssCharacterIndex: (unichar) character
{
int idx, count;
idx = -1;
for (count = 0; idx == -1 && count < cssEscapingCount; count++)
if (*(cssEscapingCharacters + count) == character)
idx = count;
return idx;
}
- (NSString *) asCSSIdentifier
{
NSMutableString *cssIdentifier;
unichar currentChar;
int count, max, idx;
cssIdentifier = [NSMutableString stringWithString: self];
[cssIdentifier replaceString: @"_" withString: @"_U_"];
[cssIdentifier replaceString: @"." withString: @"_D_"];
[cssIdentifier replaceString: @"#" withString: @"_H_"];
[cssIdentifier replaceString: @"@" withString: @"_A_"];
[cssIdentifier replaceString: @"*" withString: @"_S_"];
[cssIdentifier replaceString: @":" withString: @"_C_"];
[cssIdentifier replaceString: @"," withString: @"_CO_"];
[cssIdentifier replaceString: @" " withString: @"_SP_"];
if (!cssEscapingStrings)
[self _setupCSSEscaping];
cssIdentifier = [NSMutableString string];
max = [self length];
for (count = 0; count < max; count++)
{
currentChar = [self characterAtIndex: count];
idx = [self _cssCharacterIndex: currentChar];
if (idx > -1)
[cssIdentifier appendString: cssEscapingStrings[idx]];
else
[cssIdentifier appendFormat: @"%lc", currentChar];
}
return cssIdentifier;
}
- (int) _cssStringIndex: (NSString *) string
{
int idx, count;
idx = -1;
for (count = 0; idx == -1 && count < cssEscapingCount; count++)
if ([string hasPrefix: *(cssEscapingStrings + count)])
idx = count;
return idx;
}
- (NSString *) fromCSSIdentifier
{
NSMutableString *newString;
NSString *currentString;
int count, length, max, idx;
if (!cssEscapingStrings)
[self _setupCSSEscaping];
newString = [NSMutableString string];
max = [self length];
for (count = 0; count < max - 2; count++)
{
/* The difficulty here is that most escaping strings are 3 chars long
except one. Therefore we must juggle a little bit with the lengths in
order to avoid an overflow exception. */
length = 4;
if (count + length > max)
length = max - count;
currentString = [self substringFromRange: NSMakeRange (count, length)];
idx = [self _cssStringIndex: currentString];
if (idx > -1)
{
[newString appendFormat: @"%lc", cssEscapingCharacters[idx]];
count += [cssEscapingStrings[idx] length] - 1;
}
else
[newString appendFormat: @"%lc", [self characterAtIndex: count]];
}
currentString = [self substringFromRange: NSMakeRange (count, max - count)];
[newString appendString: currentString];
return newString;
}
- (NSString *) pureEMailAddress
{
NSString *pureAddress;