diff options
-rw-r--r-- | Source/SPArrayAdditions.h | 1 | ||||
-rw-r--r-- | Source/SPArrayAdditions.m | 17 | ||||
-rw-r--r-- | Source/SPStringAdditions.m | 41 |
3 files changed, 20 insertions, 39 deletions
diff --git a/Source/SPArrayAdditions.h b/Source/SPArrayAdditions.h index eb11da02..e5e2e6a3 100644 --- a/Source/SPArrayAdditions.h +++ b/Source/SPArrayAdditions.h @@ -38,6 +38,7 @@ static inline void NSMutableArrayReplaceObject(NSArray* self, CFIndex idx, id an - (NSString *)componentsJoinedAndBacktickQuoted; - (NSString *)componentsJoinedByCommas; +- (NSString *)componentsJoinedByPeriodAndBacktickQuoted; - (NSArray *)subarrayWithIndexes:(NSIndexSet *)indexes; @end diff --git a/Source/SPArrayAdditions.m b/Source/SPArrayAdditions.m index 4742aa83..de7b8a3e 100644 --- a/Source/SPArrayAdditions.m +++ b/Source/SPArrayAdditions.m @@ -31,7 +31,7 @@ * This method quotes all elements with backticks and then joins them with * commas. Use it for field lists as in "SELECT (...) FROM somewhere" */ -- (NSString *)componentsJoinedAndBacktickQuoted; +- (NSString *)componentsJoinedAndBacktickQuoted { NSMutableString *result = [NSMutableString string]; [result setString:@""]; @@ -61,6 +61,21 @@ return result; } +- (NSString *)componentsJoinedByPeriodAndBacktickQuoted +{ + NSMutableString *result = [NSMutableString string]; + [result setString:@""]; + + for (NSString *component in self) + { + if ([result length]) + [result appendString: @"."]; + + [result appendString:[component backtickQuotedString]]; + } + return result; +} + - (NSArray *)subarrayWithIndexes:(NSIndexSet *)indexes { NSMutableArray *subArray = [NSMutableArray arrayWithCapacity:[indexes count]]; diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index bc9e99fe..18f62b0b 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -153,22 +153,7 @@ // ------------------------------------------------------------------------------- - (NSString *)backtickQuotedString { - // mutableCopy automatically retains the returned string, so don't forget to release it later... - NSMutableString *workingCopy = [self mutableCopy]; - - // First double all backticks in the string to escape them - // I don't want to use "stringByReplacingOccurrencesOfString:withString:" because it's only available in 10.5 - [workingCopy replaceOccurrencesOfString: @"`" - withString: @"``" - options: NSLiteralSearch - range: NSMakeRange(0, [workingCopy length]) ]; - - // Add the quotes around the string - NSString *quotedString = [NSString stringWithFormat: @"`%@`", workingCopy]; - - [workingCopy release]; - - return quotedString; + return [NSString stringWithFormat: @"`%@`", [self stringByReplacingOccurrencesOfString:@"`" withString:@"``"]]; } // ------------------------------------------------------------------------------- @@ -180,32 +165,12 @@ // ------------------------------------------------------------------------------- - (NSString *)tickQuotedString { - // mutableCopy automatically retains the returned string, so don't forget to release it later... - NSMutableString *workingCopy = [self mutableCopy]; - - // First double all backticks in the string to escape them - // I don't want to use "stringByReplacingOccurrencesOfString:withString:" because it's only available in 10.5 - [workingCopy replaceOccurrencesOfString: @"'" - withString: @"''" - options: NSLiteralSearch - range: NSMakeRange(0, [workingCopy length]) ]; - - // Add the quotes around the string - NSString *quotedString = [NSString stringWithFormat: @"'%@'", workingCopy]; - - [workingCopy release]; - - return quotedString; + return [NSString stringWithFormat: @"'%@'", [self stringByReplacingOccurrencesOfString:@"'" withString:@"''"]]; } - (NSString *)replaceUnderscoreWithSpace { - NSMutableString *workingCopy = [self mutableCopy]; - [workingCopy replaceOccurrencesOfString:@"_" - withString:@" " - options:NSLiteralSearch - range:NSMakeRange(0, [workingCopy length])]; - return [workingCopy autorelease]; + return [self stringByReplacingOccurrencesOfString:@"_" withString:@" "]; } // ------------------------------------------------------------------------------- |