Created
May 2, 2013 03:16
-
-
Save hlxwell/5499939 to your computer and use it in GitHub Desktop.
Define a static method, for escape string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static NSString* GAEscapeNSString(NSString* value) { | |
if (!value) return nil; | |
const char *chars = [value UTF8String]; | |
NSMutableString *escapedString = [NSMutableString string]; | |
while (*chars) { | |
if (*chars == '\\') { | |
[escapedString appendString:@"\\\\"]; | |
} else if (*chars == '\'') { | |
[escapedString appendString:@"\\'"]; | |
} else { | |
[escapedString appendFormat:@"%c", *chars]; | |
} | |
++chars; | |
} | |
return escapedString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment