Beispiel #1
0
CCString* upperCaseString(CCString* text)
{
    timeval startTime;
    gettimeofday(&startTime, NULL);
    //TODO : speed up by sorting the vector and doing a better search
    static std::vector<std::pair<std::string, std::string>> conversions = getConversions();
    if(conversions.size() == 0)
    {
        CCLOG("Warning: missing file letters_conversion.txt, required for upperCaseString, string %s not converted", text->getCString());
        return text;
    }
    std::string from = text->getCString();
    std::string to;
    for(int i = 0; i < from.length(); i+= utf8_chsize(&from[i]))
    {
        long charLength = utf8_chsize(&from[i]);
        std::string charString = from.substr(i, charLength);
        int conversionIndex = 0;
        while(conversionIndex < conversions.size() && conversions[conversionIndex].second != charString)
        {
            conversionIndex++;
        }
        if(conversionIndex < conversions.size())
        {
            to += conversions[conversionIndex].first;
        }
        else
        {
            to += charString;
        }
    }
    timeval endTime;
    gettimeofday(&endTime, NULL);
    return Screate(to.c_str());
}
std::string upperCase(std::string text)
{
    //TODO : speed up by sorting the vector and doing a better search
    std::vector<std::pair<std::string, std::string>>* conversions = getConversions();
    if(conversions->size() == 0)
    {
        log("Warning: missing file letters_conversion.txt, required for upperCase, string %s not converted", text.c_str());
        return text;
    }
    std::string to;
    for(int i = 0; i < text.length(); i+= utf8_chsize(&text[i]))
    {
        long charLength = utf8_chsize(&text[i]);
        std::string charString = text.substr(i, charLength);
        int conversionIndex = 0;
        while(conversionIndex < conversions->size() && conversions->at(conversionIndex).second != charString)
        {
            conversionIndex++;
        }
        if(conversionIndex < conversions->size())
        {
            to += conversions->at(conversionIndex).first;
        }
        else
        {
            to += charString;
        }
    }
    return to;
}