diff --git a/cocos/ui/UIHelper.cpp b/cocos/ui/UIHelper.cpp index 01ef4362ac..73f1fdbabc 100644 --- a/cocos/ui/UIHelper.cpp +++ b/cocos/ui/UIHelper.cpp @@ -109,7 +109,7 @@ Widget* Helper::seekActionWidgetByActionTag(Widget* root, int tag) return nullptr; } -std::string Helper::utf8_substr(const std::string& str, std::string::size_type start, std::string::size_type length) +std::string Helper::getSubStringOfUTF8String(const std::string& str, std::string::size_type start, std::string::size_type length) { if (length==0) { diff --git a/cocos/ui/UIHelper.h b/cocos/ui/UIHelper.h index 7d174735e0..fb6136e7c7 100644 --- a/cocos/ui/UIHelper.h +++ b/cocos/ui/UIHelper.h @@ -68,13 +68,13 @@ public: static Widget* seekActionWidgetByActionTag(Widget* root, int tag); /** - * @brief Get a utf8 substring from a std::string with a given start position and length - * Sample: std::string str = "中国中国中国”; substr = utf8_substr(str,0,2) will = "中国" + * @brief Get a UTF8 substring from a std::string with a given start position and length + * Sample: std::string str = "中国中国中国”; substr = getSubStringOfUTF8String(str,0,2) will = "中国" * @param start The start position of the substring. - * @param length The length of the substring in utf8 count - * @return a utf8 substring + * @param length The length of the substring in UTF8 count + * @return a UTF8 substring */ - static std::string utf8_substr(const std::string& str, + static std::string getSubStringOfUTF8String(const std::string& str, std::string::size_type start, std::string::size_type length); diff --git a/cocos/ui/UIRichText.cpp b/cocos/ui/UIRichText.cpp index b443cffba2..e6d53993d2 100644 --- a/cocos/ui/UIRichText.cpp +++ b/cocos/ui/UIRichText.cpp @@ -283,18 +283,18 @@ void RichText::handleTextRenderer(const std::string& text, const std::string& fo std::string curText = text; size_t stringLength = StringUtils::getCharacterCountInUTF8String(text); int leftLength = stringLength * (1.0f - overstepPercent); - std::string leftWords = Helper::utf8_substr(curText,0,leftLength); - std::string cutWords = Helper::utf8_substr(curText, leftLength, stringLength - leftLength); + std::string leftWords = Helper::getSubStringOfUTF8String(curText,0,leftLength); + std::string cutWords = Helper::getSubStringOfUTF8String(curText, leftLength, stringLength - leftLength); if (leftLength > 0) { Label* leftRenderer = nullptr; if (fileExist) { - leftRenderer = Label::createWithTTF(Helper::utf8_substr(leftWords, 0, leftLength), fontName, fontSize); + leftRenderer = Label::createWithTTF(Helper::getSubStringOfUTF8String(leftWords, 0, leftLength), fontName, fontSize); } else { - leftRenderer = Label::createWithSystemFont(Helper::utf8_substr(leftWords, 0, leftLength), fontName, fontSize); + leftRenderer = Label::createWithSystemFont(Helper::getSubStringOfUTF8String(leftWords, 0, leftLength), fontName, fontSize); } if (leftRenderer) { diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp index 88cca2d6f5..eda603d421 100644 --- a/cocos/ui/UITextField.cpp +++ b/cocos/ui/UITextField.cpp @@ -133,7 +133,7 @@ void UICCTextField::insertText(const char* text, size_t len) { long length = _maxLength - text_count; - input_text = Helper::utf8_substr(input_text, 0, length); + input_text = Helper::getSubStringOfUTF8String(input_text, 0, length); len = input_text.length(); } } @@ -415,7 +415,7 @@ void TextField::setText(const std::string& text) long total = text_count + StringUtils::getCharacterCountInUTF8String(getStringValue()); if (total > max) { - strText = Helper::utf8_substr(strText, 0, max); + strText = Helper::getSubStringOfUTF8String(strText, 0, max); } } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp index 23174dc551..ae7d403f4e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp @@ -26,12 +26,12 @@ bool UIRichTextTest::init() str1.c_str(), str1.length(), StringUtils::getCharacterCountInUTF8String(str1), - Helper::utf8_substr(str1, 0, 5).c_str()); + Helper::getSubStringOfUTF8String(str1, 0, 5).c_str()); CCLOG("str2:%s ascii length = %ld, utf8 length = %ld, substr = %s", str2.c_str(), str2.length(), StringUtils::getCharacterCountInUTF8String(str2), - Helper::utf8_substr(str2, 0, 2).c_str()); + Helper::getSubStringOfUTF8String(str2, 0, 2).c_str()); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp index 66048484b8..9f3b8485e6 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp @@ -277,7 +277,7 @@ bool UITextFieldTest_LineWrap::init() textField->ignoreContentAdaptWithSize(false); ((Label*)(textField->getVirtualRenderer()))->setLineBreakWithoutSpace(true); textField->setContentSize(Size(240, 170)); - textField->setText("input words hereinput words hereinput words hereinput words hereinput words hereinput words here"); + textField->setText("input words here"); textField->setTextHorizontalAlignment(TextHAlignment::CENTER); textField->setTextVerticalAlignment(TextVAlignment::CENTER); textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));