aboutsummaryrefslogtreecommitdiffstats
path: root/NSString+LispExtensions.m
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-04-02 19:20:20 -0400
committerBrian Cully <bjc@kublai.com>2008-04-02 19:20:20 -0400
commitab10720260e2c184b319026da89f4dfd338500bb (patch)
treea692a27435da0296972e43b21b2f35762e720bfd /NSString+LispExtensions.m
downloadmoxie-ab10720260e2c184b319026da89f4dfd338500bb.tar.gz
moxie-ab10720260e2c184b319026da89f4dfd338500bb.zip
Initial commit
Diffstat (limited to 'NSString+LispExtensions.m')
-rw-r--r--NSString+LispExtensions.m40
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