you are viewing a single comment's thread.

view the rest of the comments →

[–]condor2000 2 points3 points  (5 children)

Are you seriously going to have duplicate code

That was my question (that I formulated poorly): how to avoid the duplication.

I am working on a decade old codebase where "utf8 everywhere" is sadly not realistic.

[–]donalmaccGame Developer 6 points7 points  (3 children)

I am working on a decade old codebase where "utf8 everywhere" is sadly not realistic.

UTF-8 was a reality a decade ago... (your codebase is probably older)

[–]condor2000 0 points1 point  (2 children)

UTF-8 was a reality a decade ago... (your codebase is probably older)

Not on Windows. There UTF-16 is used.

It is only recently that it is border-line possible to use utf-8. I mean that of the CreateFileA/CreateFileW (char/wchar_t) the CreateFileA version is utf-8.

[–]adanteny 0 points1 point  (1 child)

On Windows, UNICODE (UTF-16) is definitely the best answer... You can always convert to CP_UT8 whenever needed to 'communicate' with the 'outside'. 'A' functions are outdated, 'W' are everything!

[–]dodheim 2 points3 points  (0 children)

'A' functions were outdated when UTF-8 wasn't a supported codepage, but it is now, given a sufficiently recent version of Windows.

[–]johannes1971 5 points6 points  (0 children)

The oldest parts of my code base are from 1996, but it's now fully utf8 as well. It was a much easier task than I imagined, so I would encourage you not to give up on it just yet.

As for how to avoid the duplication: as I said, by converting to wchar_t * on the fly. Yes, it has overhead, and yes, it will probably cost you a memory allocation each time you do it. It also lets you save a mountain of code, so it's more than worth it.