Almost all of them require iterators to begin of original string | end of original string | begin of output string.
Output string is empty by default and most conversion function from there (http://www.sfml-dev.org/documentation/2.4.1/classsf_1_1Utf_3_018_01_4.php) would give me string iterator + offset out of range
if I do not set the size of output string manually like that:
std::string ANSI_to_UTF8(const sf::String& original)
{
std::string ansi;
ansi.resize(original.getSize() * 4);
std::string::iterator last = sf::Utf<8>::fromAnsi(original.begin(), original.end(), ansi.begin(), std::locale("Russian"));
ansi.resize(last - ansi.begin());
return ansi;
}
string iterator + offset out of range
if I do not set the size of output string manually like that
You want std::back_inserter (http://en.cppreference.com/w/cpp/iterator/back_inserter)
std::string String::toAnsiString(const std::locale& locale) const
{
// Prepare the output string
std::string output;
output.reserve(m_string.length() + 1);
// Convert
Utf32::toAnsi(m_string.begin(), m_string.end(), std::back_inserter(output), 0, locale);
return output;
}
Why would you use string::reserve in this case? Is not it unneeded when you use std::back_inserter?