diff options
Diffstat (limited to 'NSString+LispExtensions.m')
-rw-r--r-- | NSString+LispExtensions.m | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/NSString+LispExtensions.m b/NSString+LispExtensions.m new file mode 100644 index 0000000..4d36e52 --- /dev/null +++ b/NSString+LispExtensions.m @@ -0,0 +1,40 @@ +// +// NSString+LispExtensions.m +// Moxie +// +// Created by Brian Cully on Sat Sep 04 2004. +// Copyright (c) 2004 Brian Cully. All rights reserved. +// + +#import "NSString+LispExtensions.h" + +@implementation NSString (LispExtensions) +- (NSString *)lispForm +{ + NSMutableString *result; + NSRange subrange; + unsigned int len, i; + + result = [NSMutableString stringWithString: @"\""]; + len = [self length]; + subrange.location = 0; + for (i = 0; i < len; i++) { + switch ([self characterAtIndex: i]) { + case '\\': + case '\"': + subrange.length = i - subrange.location; + [result appendString: [self substringWithRange: subrange]]; + [result appendString: @"\\"]; + subrange.location = i; + break; + } + } + if (subrange.location < len) { + subrange.length = len - subrange.location; + [result appendString: [self substringWithRange: subrange]]; + } + [result appendString: @"\""]; + + return result; +} +@end
\ No newline at end of file |