MohammadFakhreddin / cocos2dx-persian-arabic-support

Create custom font with ttf won't work on Persian and Arabic. By using this project you can fix this issue.
5 stars 1 forks source link

Trim fails for single char english text #3

Open monkeyibrowstudios opened 1 year ago

monkeyibrowstudios commented 1 year ago

I have both english and persian texts in my cocos2d-x (some things cannot be translated). But the std::string trim(std::string rawText) method is failing when executed with one single english character. For example: "M" becomes "". I replaced the trim method with the following:

    string whitespace = " ";
    const auto strBegin = str.find_first_not_of(whitespace);
    if (strBegin == std::string::npos)
        return ""; // no content
    const auto strEnd = str.find_last_not_of(whitespace);
    const auto strRange = strEnd - strBegin + 1;

    return str.substr(strBegin, strRange);

But not sure if I'm breaking something with UTF8 persian chars.