Duncan Gibson wrote:
> "fl_everything_to_utf8()"

        Hmm, but isn't that what iconv(3) is for?

        I'm not sure, but I think that was the rationale behind FLTK
        not providing that. I think the edict was: FLTK would support
        ascii and valid utf8 only; everything else would yield
        undefined behavior.

        I'm thinking it shouldn't be an FLTK issue if someone supplies
        non-utf8 strings and gets weird behaviors or a crash.

        I think that was the rationale behind not having an
        fl_everything_to_utf8(), but I might be over simplifying.

        I'm perhaps outta my league replying to this thread; I try to
        know as little as possible about Unicode, and didn't know what
        'surrogates' were in this context till I looked it up.

        Sounds like surrogate pairs are a kind of UTF-16 encoded Unicode,
        which sounds like non-utf8, something GNU iconv lib could convert?

        I had a similar situation where I was using O'ksi'D's utf8 fork
        to display Japanese text, and ran into some text that wouldn't display
        correctly. Turned out it was SJIS encoded japanese (non-utf8), and had
        to add iconv() to my code to do the conversion, then it worked fine.

        Had to find a Windows version of iconv, but that wasn't too hard IIRC.
        The code I ended up with was something like:

                const iconv_t ierr = (iconv_t)-1;
                const size_t  serr = (size_t)-1;
                static iconv_t it = ierr;

                // Open iconv conversion (if not already)
                if ( it == ierr ) {
                    const char *from = "SJIS";       // input text we want to 
convert
                    const char *to   = "UTF-8";      // desired output format 
(FLTK always utf8)
                    it = iconv_open(to, from);
                }
                // Assuming iconv_open() worked, pump SJIS strings into it, 
convert to utf8
                if ( it != ierr ) {
                    if ( iconv(it,                   // SJIS->UTF8 open 
descriptor
                               &in_buf, &in_siz,     // input string
                               &out_buf, &out_siz    // output string
                              ) == serr ) {
                        // conversion error
                    } else {
                        // success -- add terminating NULL, display utf8 string 
in FLTK
                    }
                }

        I imagine similar code could be used to convert the UTF-16 -> UTF-8?
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to