diff --git a/uppsrc/Core/String.cpp b/uppsrc/Core/String.cpp index be5ae42a1..c18219940 100644 --- a/uppsrc/Core/String.cpp +++ b/uppsrc/Core/String.cpp @@ -307,6 +307,11 @@ WString String::ToWString() const return WString(Begin(), GetCount()); } +int String::GetCharCount() const +{ + return GetDefaultCharset() == CHARSET_UTF8 ? utf8len(Begin(), GetCount()) : GetCount(); +} + String::String(StringBuffer& b) { if(b.begin == b.buffer) { diff --git a/uppsrc/Core/String.h b/uppsrc/Core/String.h index ab03d05ad..3ebbf621b 100644 --- a/uppsrc/Core/String.h +++ b/uppsrc/Core/String.h @@ -313,6 +313,7 @@ public: String& operator<<=(const String& s) { if(this != &s) { String0::Free(); String0::Set(s, s.GetCount()); } return *this; } void Shrink() { *this = String(Begin(), GetLength()); } + int GetCharCount() const; String() {} String(const Nuller&) {} diff --git a/uppsrc/Core/src.tpp/String$en-us.tpp b/uppsrc/Core/src.tpp/String$en-us.tpp index b95a987bb..b72980372 100644 --- a/uppsrc/Core/src.tpp/String$en-us.tpp +++ b/uppsrc/Core/src.tpp/String$en-us.tpp @@ -100,6 +100,13 @@ empty [* String]).&] [s2; Reduces memory used by string to minimum (size optimization).&] [s3; &] [s4;%- &] +[s5;:String`:`:GetCharCount`(`)const:%- [@(0.0.255) int]_[* GetCharCount]()_[@(0.0.255) con +st]&] +[s2; Returns a number of characters contained in String. This is +equal GetCount() if default charset is not UTF`-8, but different +for UTF`-8. It is faster equivalent of ToWString().GetCount().&] +[s3;%- &] +[s4;%- &] [s5;:String`:`:ToWString`(`)const:%- [_^WString^ WString]_[* ToWString]()_[@(0.0.255) const ]&] [s2; Convert String to WString using current default character set.&]