diff options
| author | Oz Linden <oz@lindenlab.com> | 2016-08-11 15:36:09 -0400 |
|---|---|---|
| committer | Oz Linden <oz@lindenlab.com> | 2016-08-11 15:36:09 -0400 |
| commit | 6ff420d705625fef4b0456c19bb9c766cabb31af (patch) | |
| tree | 16c27571df04932dd830b35e06cdf4e9b5dbf07e /indra/llcommon/llstring.cpp | |
| parent | c32b27f5b77c7d8e53b11163d04f2842949d71de (diff) | |
| parent | 4fb100ac7a33174883184f1320d0beac08ead3a7 (diff) | |
merge changes for 4.0.7-release
Diffstat (limited to 'indra/llcommon/llstring.cpp')
| -rw-r--r-- | indra/llcommon/llstring.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index f3b8999883..c45db3b185 100644 --- a/indra/llcommon/llstring.cpp +++ b/indra/llcommon/llstring.cpp @@ -576,6 +576,33 @@ std::string utf8str_truncate(const std::string& utf8str, const S32 max_len) } } +std::string utf8str_symbol_truncate(const std::string& utf8str, const S32 symbol_len) +{ + if (0 == symbol_len) + { + return std::string(); + } + if ((S32)utf8str.length() <= symbol_len) + { + return utf8str; + } + else + { + int len = 0, byteIndex = 0; + const char* aStr = utf8str.c_str(); + size_t origSize = utf8str.size(); + + for (byteIndex = 0; len < symbol_len && byteIndex < origSize; byteIndex++) + { + if ((aStr[byteIndex] & 0xc0) != 0x80) + { + len += 1; + } + } + return utf8str.substr(0, byteIndex); + } +} + std::string utf8str_substChar( const std::string& utf8str, const llwchar target_char, |
