Last active
August 29, 2015 13:56
-
-
Save benstiglitz/9214234 to your computer and use it in GitHub Desktop.
Hacked up raw NSStrings in C.
This file contains 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
#define raw_paste(...) #__VA_ARGS__ | |
#define raw_fix(...) raw_paste(__VA_ARGS__) | |
#define raw_join(x,y) x##y | |
#define raw_str_h(z, ...) ({char *raw_join(__raw_x, z) = raw_fix(raw_paste(__VA_ARGS__)); [[[NSString alloc] initWithBytes:raw_join(__raw_x, z) + 1 length:strlen(raw_join(__raw_x, z)) - 2 encoding:NSUTF8StringEncoding] autorelease];}) | |
#define raw_str(...) raw_str_h(__COUNTER__, __VA_ARGS__) | |
/* totally doesn't work with embedded single or double quotes */ | |
@import Foundation; | |
int main(int argc, char **argv) { | |
NSString *a = raw_str(check out this >>> \n <<< escape sequence); | |
NSLog(@"%@", a); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment