If you are in a win32 platform you most likely want to use widechar for all your paths - especially when you write applications which deals with any kind of media.
On the other hand in a linux or unix based platform you dont want to deal with widechar at all and rather work with UTF-8 strings only.
Also sometimes you simply dont care and normal ansi strings are just fine, so you dont want to deal with any kind of that shit.
This boils down to two kind of string types: UTF-8 and Unicode.
So the options are:
1.) Leave it as it as and provide a "Ansi" and a "Wide" version for every functions which uses paths or string buffers. On *nix ansi would just be expected to be UTF-8 always.
or
2.) Remove all wide functions and use UTF-8 everywhere (Thats the way SDL handles it)
or
3.) Make a string buffer union which supports both and change every parameter to it
Some like that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | typedef enum fplCharBufferType { fplCharBufferType_AnsiOrUTF8 = 0, fplCharBufferType_Unicode, } fplCharBufferType; typedef struct fplCharBuffer { //! Union here has no meaning other than to have the first or the second option (Size is the always) union { char *ansiData; wchar_t *wideData; }; //! Only used for output buffers size_t capacity; //! Which type fplCharBufferType type; } fplCharBuffer; typedef fplCharBuffer fplPathString; // Old version fpl_platform_api bool fplAnsiDirectoryExists(const char *ansiPath); fpl_platform_api bool fplWideDirectoryExists(const char *widePath); fpl_common_api char *fplEnforceAnsiPathSeparatorLen(char *ansiPath); fpl_common_api char *fplEnforceWidePathSeparatorLen(wchar_t *widePath); // New version fpl_platform_api bool fplDirectoryExists(const fplPathString *path); fpl_common_api char *fplEnforcePathSeparatorLen(fplPathString *path); |
Seems like a pain...
or
4.) Dont separate between ansi and wide and just have something like that:
1 2 3 4 5 6 7 8 9 10 | #if defined(FPL_UNICODE) //! 16-bit unicode character typedef wchar_t fpl_char; #else //! UTF-8 or ansi character typedef char fpl_char; #endif fpl_platform_api bool fplDirectoryExists(const fpl_char *path); fpl_common_api char *fplEnforcePathSeparatorLen(fpl_char *path, size_t maxPathLen); |
I would prefer the last solution. What do you think?
Of course string functions like fplGetAnsiStringLength or fplGetWideStringLength i would not remove. But i would add a additional function which uses fpl_char and either use the ansi or the wide function callback.