1. Edd Dawson
  2. pngxx


Clone wiki

pngxx / unicode

Unicode paths

pngxx and jpegxx provide convenience functions for reading from and writing to files whose names are specified by strings.

In order to do this, these strings are passed internally to the constructor of an std::ifstream (for reading) or std::ofstream (for writing).

Because of this implementation, one cannot in general expect to be able to supply a UTF8 path to one of these convenience functions and have it work as expected.

Performing encoding conversions is out of the scope of pngxx and jpegxx so in order to use the libraries to read from and write to files with arbitrary names, you should open the file yourself using the appropriate platform-specific mechanism and then pass a stream or iterator pair to a different overload of the convenience function.

Platform specific hints

Windows: Modern versions of Windows standardise around UTF16. Since Visual C++ 2005, Microsoft's C++ standard library implementation ships with overloaded std::[i|o]fstream constructors that are able to take wide character pointers, allowing you to open paths represented by UTF16 strings.

UNIX: Most modern UNIX operating systems can handle UTF8 natively. In other words, passing UTF8 strings to the pngxx and jpegxx convenience functions will do the right thing if the std::[i|o]fstream implementation in turn does the right thing. Some care should be taken with Unicode normalization, however. For example, Mac OS X requires UTF8 paths to be in Normalization Form D (NFD).