Adding unicode support to the library for Windows

I would like to add Unicode support to the C library that I support. Currently, he expects all strings to be transmitted in utf8 encoding. Based on the feedback, it seems that windows usually provide 3 functional versions.

  • fooA () ANSI encoded strings
  • fooW () Unicode encoded strings String
  • foo () depends on the definition of UNICODE

Is there an easy way to add this support without writing many shell functions? Some functions are also called from the library by the user, and this complicates the situation a bit.

I would like to support utf8 string support as the library can be used on several operating systems.

+3
source share
2 answers

Functions foowithout a suffix are macros. Functions fooAare deprecated and are simple wrappers around functions fooWthat are the only ones that actually do the job. Windows uses UTF-16 strings for everything, so if you want to continue to use UTF-8 strings, you must convert them for every API call (e.g. using MultiByteToWideChar).

: UTF-16, UTF-32 UTF-8. ( ) . , UTF-8 : , ICU, Qt Java, UTF-16 . , Unicode , , : Windows, UTF-16, . Linux UTF-8 ( Unicode 8- ), . . OS X UTF-8 POSIX UTF-16 (Carbon, Cocoa).

: "ANSI" "Unicode", Microsoft, . Microsoft "Unicode" " ", "UTF-16" () BMP ( ). "ANSI" Microsoft , Windows.

, UTF-16 ICU.

+4

UTF-8, Unicode, UTF-8 Unicode. , UTF-16 UTF-32, UTF-8 . UTF-16/32, /.

+1

Source: https://habr.com/ru/post/1752444/


All Articles