Win32: add Unicode conversion functions
commit94a3822a16c5b7fe02e54a6f1ef5bc1f88787f7e
authorKarsten Blees <blees@dcon.de>
Fri, 25 Nov 2011 20:05:06 +0000 (25 21:05 +0100)
committerPat Thoyts <patthoyts@users.sourceforge.net>
Mon, 22 Oct 2012 12:30:21 +0000 (22 13:30 +0100)
tree1a1447b435b175f86232c68d5fcb9cddd0e70107
parent3dc3ce4c1dfd7dea2ba43d86313fda26d379f6ae
Win32: add Unicode conversion functions

Add Unicode conversion functions to convert between Windows native UTF-16LE
encoding to UTF-8 and back.

To support repositories with legacy-encoded file names, the UTF-8 to UTF-16
conversion function tries to create valid, unique file names even for
invalid UTF-8 byte sequences, so that these repositories can be checked out
without error.

The current implementation leaves invalid UTF-8 bytes in range 0xa0 - 0xff
as is (producing printable Unicode chars \u00a0 - \u00ff, equivalent to
ISO-8859-1), and converts 0x80 - 0x9f to hex-code (\u0080 - \u009f are
control chars).

The Windows MultiByteToWideChar API was not used as it either drops invalid
UTF-8 sequences (on Win2k/XP; producing non-unique or even empty file
names) or converts them to the replacement char \ufffd (Vista/7; causing
ERROR_INVALID_NAME in subsequent calls to file system APIs).

Signed-off-by: Karsten Blees <blees@dcon.de>
compat/mingw.c
compat/mingw.h