void MailSystemCell::resizeString(std::string &str,int len){
// std::string language = LocalController::shared()->getLanguageFileName();
// len= CCLabelIF::canBeSupportedWithBmpFont(language)?len:len*0.5;
// 两个英文约算作一个汉字,换行符转换为空格
int splitIndex = str.length();
double totalLen = 0;
int i=0;
int lenU8Char = 0; // 正好等于限制数时不需要回退,大于限制数时回退到限制数
while( i < str.length() ) {
if( (int)totalLen > len )
{
splitIndex = i;
break;
}
const char* ds = str.c_str() + i;
lenU8Char = Utf8Utils::fetch_utf_length( ds );
if( lenU8Char == 1 )
{
totalLen += 0.5;
}
else
{
totalLen += 1;
}
if(str[i] == '\n' // 换行符
|| str[i] == '\r' ) // 回车符
{
str[i] = ' ';
}
i += lenU8Char;
}
if( (int)totalLen > len )
{
str = str.substr(0, splitIndex - lenU8Char);
str.append("...");
}
}