I need to parse the defaults database for Recent files, in Mac Os X. This is done with sed. The caveat is that the filenames are stored in decomposed utf-16 inside there.
So, I thought, (after having being pointed to the NSString functions) "why don't I just make a little tool that takes care of it".
The tool is supposed to work basically like cat, it gets lines from input, it converts each line into a CFStringref object, before the CFStringref hopefully gets converted into precomposed UTF-16, I convert that back to UTF-8, and prints it.
I hate to say it, but I don't know this "toll-free bridging" works, I have no intention to use Cocoa and Objective C for this, I just want a straight solution using CFStringref, that is, if such a solution exists!
Thanks!
Here is what I have got so far:
#define BUFFERSIZE 512
static void
precomposedOutput( char *fn )
{
char buffer[BUFFERSIZE] ;
CFStringRef str ;
char *outbuf;
char *bytes ;
FILE *fd = stdin ;
if (fn) {
fd = fopen(fn,"r");
}
while ( fgets(buffer, sizeof(buffer),fd ) ) {
bytes = savestr(buffer) ;
str = CFStringCreateWithCStringNoCopy(NULL, bytes,kCFStringEncodingUTF8, NULL);
/* CONVERSION INTO PRECOMPOSED IS SUPPOSED TO HAPPEN HERE */
outbuf = Copy_CFStringRefToCString(str) ;
CFRelease(str) ;
fputs(outbuf,stdout) ;
free(outbuf) ;
}
}
This appears to work, so far in converting back and forth, (not run leaks on it.) What I need help with, is to convert the CFString into precomposed UTF-16.
Thanks!