>
https://github.com/alf-p-steinbach/cppx/commit/6bcf5be4b53e882dbf76b5414bfcf8820cddc240
Now, on Github:
https://github.com/alf-p-steinbach/cppx/commit/c7daa7c6decd4a48c1278217557eb4404f4c469a
Finally Unicode interactive line input so that this kind of beginner's
program now works as expected with non-ASCII characters in Windows:
<code>
#include <p/cppx/basics_and_main.hpp> // This header brings in a
default "main".
using namespace progrock::cppx;
void cpp_main()
{
// Basics: output of text parts, input of Unicode line.
sys.out << "Hi, what’s your name? ";
const String username = line_from(
sys.in );
sys.out << "Pleased to meet you, " << username << "!" << endl;
// Just to input at least 2 lines, so as to test the g++ workaround:
sys.out << endl;
sys.out << "What’s your favorite activity, then, " << username << "? ";
const String activity = line_from(
sys.in );
sys.out
<< "What a coincidence!" << endl
<< "Earlier I favored making Norwegian blåbærsyltetøy," << endl
<< "but now my favorite activity is also " << activity << "!"
<< endl;
sys.out << endl;
sys.out << "Well, have a nice day, " << username << "! Bye!" << endl;
}
</code>
Here
• The "’" apostrophe is displayed correctly (it's not in Latin-1).
• In Windows any character in Unicode's Basic Multilingual Plane should
work as input. Testing with “日本国 кошка” (a “Japanese cat”, with
“Japanese” expressed in Chinese and “cat” in Russian, or I believe it's
so :) ) worked nicely, except the console window, with my choice of
font, was unable to display the Chinese glyphs.
• The narrow string literals are translated at run time using the code
page that the compiler encoded them with. In Windows this relies on a
simple text file that specifies that code page, e.g. "1252".
Unfortunately, as far as I know it can't be more automatically
determined, but I supply a little batch file that can generate the text
file; it just looks up the ACP codepage in the Windows registry.
Of course one doesn't need to use the library's “main”, but it avoids
coding up a minimal exception-handling “main”, and I believe that the
ability to just use a “cpp_main” and throw exceptions for failures, will
be useful to a beginner.
Probably next is making this work with g++, and then testing in
Unix-land. And then, not doing the constant-time-operations string
optimizations, which is much work for not much manifestly apparent gain,
but rather file operations, I think. Opening and creating files with
Unicode paths – in an amazing coincidence someone just now directed me
to my old code for that in an SO answer, by upvoting.
Constructive thoughts?
Cheers, & new year survival to all! :),
- Alf