Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use precomposedStringWithCanonicalMapping with CFStringref in plain C
    text
    copied!<p>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.</p> <p>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".</p> <p>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 <strong>hopefully</strong> gets converted into precomposed UTF-16, I convert that back to UTF-8, and prints it.</p> <p>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!</p> <p>Thanks!</p> <p>Here is what I have got so far:</p> <pre><code>#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) ; } } </code></pre> <p>This appears to work, so far in converting back and forth, (not run <strong>leaks</strong> on it.) What I need help with, is to convert the CFString into precomposed UTF-16.</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload