I have a proprietary file (database) format which i am currently trying to migrate to a SQL database. Therefore i am converting the files to a sql dump, which is already working fine. The only problem left now is their weird way of handling characters which are not inside the ASCII-decimal range of 32 to 126. They have a collection of all those characters stored in Unicode (hex - e.g. 20AC = €), indexed by their own internal index.
My plan now is: I want to create a table where the internal index, the unicode (in hex) and the character representation (UTF-8) is stored. This table can then be used for future updates.
Now to the problem: How do i write the UTF-8 character representation of a unicode hex value to a file? Current code looks like this:
this->outFile.open(fileName + ".sql", std::ofstream::app);
std::string protyp;
this->inFile.ignore(2); // Ignore the ID = 01.
std::getline(this->inFile, protyp); // Get the PROTYP Identifier (e.g. \321)
protyp = "\\" + protyp;
std::string unicodeHex;
this->inFile.ignore(2); // Ignore the ID = 01.
std::getline(this->inFile, unicodeHex); // Get the Unicode HEX Identifier (e.g. 002C)
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
const std::wstring wide_string = this->s2ws("\\u" + unicodeHex);
const std::string utf8_rep = converter.to_bytes(wide_string);
std::string valueString = "('" + protyp + "', '" + unicodeHex + "', '" + utf8_rep + "')";
this->outFile << valueString << std::endl;
this->outFile.close();
But this just prints out something like this:
('\321', '002C', '\u002C'),
While the desired output would be:
('\321', '002C', ','),
What am i doing wrong? I have to admit that i am not that certain when it comes to character encoding and stuff :/. I am working on Windows 7 64bit, if it makes any difference. Thanks in advance.