Skip to content

Instantly share code, notes, and snippets.

@benstiglitz
Last active August 29, 2015 13:56
Show Gist options
  • Save benstiglitz/9214234 to your computer and use it in GitHub Desktop.
Save benstiglitz/9214234 to your computer and use it in GitHub Desktop.
Hacked up raw NSStrings in C.
#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