mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-11 13:15:38 +02:00
count unicode chars to extra function
This commit is contained in:
parent
e6f1677d3a
commit
37e2292720
@ -214,8 +214,7 @@ void CPlayerInterface::performAutosave()
|
||||
if(prefix.empty())
|
||||
{
|
||||
std::string name = cb->getMapHeader()->name;
|
||||
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> conv;
|
||||
int txtlen = conv.from_bytes(name).size();
|
||||
int txtlen = TextOperations::getUnicodeCharactersCount(name);
|
||||
|
||||
TextOperations::trimRightUnicode(name, std::max(0, txtlen - 15));
|
||||
std::string forbiddenChars("\\/:?\"<>| ");
|
||||
|
@ -193,6 +193,12 @@ void TextOperations::trimRightUnicode(std::string & text, const size_t amount)
|
||||
}
|
||||
}
|
||||
|
||||
size_t getUnicodeCharactersCount(const std::string & text)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> conv;
|
||||
return conv.from_bytes(text).size();
|
||||
}
|
||||
|
||||
std::string TextOperations::escapeString(std::string input)
|
||||
{
|
||||
boost::replace_all(input, "\\", "\\\\");
|
||||
|
@ -46,6 +46,9 @@ namespace TextOperations
|
||||
///delete specified amount of UTF-8 characters from right
|
||||
DLL_LINKAGE void trimRightUnicode(std::string & text, size_t amount = 1);
|
||||
|
||||
/// give back amount of unicode characters
|
||||
size_t DLL_LINKAGE getUnicodeCharactersCount(const std::string & text);
|
||||
|
||||
/// converts number into string using metric system prefixes, e.g. 'k' or 'M' to keep resulting strings within specified size
|
||||
/// Note that resulting string may have more symbols than digits: minus sign and prefix symbol
|
||||
template<typename Arithmetic>
|
||||
|
Loading…
x
Reference in New Issue
Block a user