Ever since Microsoft announced that they added support Unicode literals in Visual Studio 2015, I've been slowly replacing my wide strings with UTF-8 basic strings.
https://msdn.microsoft.com/en-us/library/hh409293.aspx I ran into an issue with std::basic_string<unsigned char>
With std::basic_string<unsigned char> (instead of std::basic_string<char>) I lose some functionality to interact with std. For example, I can't do this:
std::basic_string<unsigned char> something;
std::cout << something << std::endl; //error here
The sf::String::toUtf8 function returns std::basic_string<Uint8> which is results to std::basic_string<unsigned char>
Here's an example of an issue I'm running into:
void LogIt (const std::string& log)
{
std::cout << log;
OutputDebugString(log.c_str());
}
void LogIt (const std::basic_string<unsigned char>& log)
{
//Need to convert basic_string<sf::Uint8> to string<char>
}
void DoStringTest ()
{
//Value of string copied from: http://en.cppreference.com/w/cpp/locale/wstring_convert/from_bytes
std::string utf8String = u8"z\u00df\u6c34\U0001d10b \n";
std::string normalString = "z\u00df\u6c34\U0001d10b \n"; //invalid chars and compiler warnings
std::basic_string<char> utf8Basic = u8"z\u00df\u6c34\U0001d10b \n";
std::basic_string<char> normalBasic = "z\u00df\u6c34\U0001d10b \n"; //invalid chars and compiler warnings
sf::String sfString = utf8String;
//std::string something = sfString.toUtf8(); //error
std::basic_string<sf::Uint8> fromSF = sfString.toUtf8();
LogIt(utf8String); //produces "zÃ...." The remaining characters cannot be displayed in this forum post.
LogIt(utf8Basic); //produces "zÃ...." The remaining characters cannot be displayed in this forum post.
LogIt(sfString); //produces "zÃ...." The remaining characters cannot be displayed in this forum post.
LogIt(fromSF); //Goes to overloaded function with param std::basic_string<unsigned char>
}
Compiled in Microsoft Visual Studio 2015 Update 1
Using SFML version 2.4.0.
I'm not sure if I should have created a feature request to have that function return a std::basic_string<char> instead, or I should look at this problem at a different angle.
Thanks for your help.