String encoding problem in R wrappers on Windows
Kevin Smith <[email protected]>
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <[email protected]> |
I’m wrapping a library that uses all UTF-8 strings as results. I noticed recently that non-ASCII characters on Windows contained incorrect characters. I tracked it down to the use of Rf_mkString in the wrappers which I’m assuming must think the C string is encoded in the native encoding for the platform, not necessarily UTF-8. The lines looks like:
r_ans = result ? Rf_mkString(result) : R_NilValue;
I’m not sure how to make the wrappers work properly with UTF-8 result strings though. The only thing I can think of is to post-process the wrappers to generate code like the following. It forces the encoding to UTF-8. This approach seems pretty heavy-handed though and I was wondering if there was a better solution.
if ( result ) {
PROTECT(r_ans = Rf_mkCharCE((char *)(result), CE_UTF8));
r_ans = Rf_mkString(r_ans);
UNPROTECT(1);
} else {
r_ans = R_NilValue;
}
Kevin Smith
[email protected]
_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user