From dcf2748abe446d6fcb0e0e622502f066759c258c Mon Sep 17 00:00:00 2001 From: jakob Date: Thu, 26 Mar 2009 13:50:20 +0000 Subject: - updated the backtickQuotedString method to be 10.4 compatible --- Source/SPStringAdditions.m | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'Source') diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index ef595dcc..80498d91 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -120,7 +120,22 @@ // ------------------------------------------------------------------------------- - (NSString *)backtickQuotedString { - return [NSString stringWithFormat: @"`%@`", [self stringByReplacingOccurrencesOfString: @"`" withString: @"``"] ]; + // 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, [quotedString length]) ]; + + // Add the quotes around the string + NSString *quotedString = [NSString stringWithFormat: @"`%@`", workingCopy]; + + [workingCopy release]; + + return quotedString; } #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 -- cgit v1.2.3