Convert string from UTF-8 to ISO-8859-1

前端 未结 3 894
孤独总比滥情好
孤独总比滥情好 2021-01-05 08:06

I\'m trying to convert a UTF-8 string to a ISO-8859-1 char* for use in legacy code. The only way I\'m seeing to do this is with iconv.

I w

3条回答
  •  Happy的楠姐
    2021-01-05 08:48

    First convert UTF-8 to 32-bit Unicode.

    Then keep the values that are in the range 0 through 255.

    Those are the Latin-1 code points, and for other values, decide if you want to treat that as an error or perhaps replace with code point 127 (my fav, the ASCII "del") or question mark or something.


    The C++ standard library defines a std::codecvt specialization that can be used,

    template<>
    codecvt
    

    C++11 §22.4.1.4/3: “the specialization codecvt converts between the UTF-32 and UTF-8 encoding schemes”

提交回复
热议问题