This commit is contained in:
andyque 2014-07-30 10:45:35 +08:00
parent e7da7b3e42
commit f2b0528cc9
6 changed files with 15 additions and 15 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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)
{

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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));