Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 21, 2015, 7:05:53 PM (8 years ago)
Author:
muemart
Message:

Run clang-modernize -loop-convert

  • Again, not all possible loops were converted
  • It can do pretty cool transformations, but I had to fix a few compile errors, so there might be some runtime errors lurking around too
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/util/StringUtils.cc

    r10777 r10821  
    262262        std::string output(str.size() * 2, ' ');
    263263        size_t i = 0;
    264         for (size_t pos = 0; pos < str.size(); ++pos)
    265         {
    266             switch (str[pos])
     264        for (auto & elem : str)
     265        {
     266            switch (elem)
    267267            {
    268268            case '\\': output[i] = '\\'; output[i + 1] = '\\'; break;
     
    276276            case  '"': output[i] = '\\'; output[i + 1] =  '"'; break;
    277277            case '\0': output[i] = '\\'; output[i + 1] =  '0'; break;
    278             default  : output[i] = str[pos]; ++i; continue;
     278            default  : output[i] = elem; ++i; continue;
    279279            }
    280280            i += 2;
     
    336336    void lowercase(std::string* str)
    337337    {
    338         for (size_t i = 0; i < str->size(); ++i)
    339         {
    340             (*str)[i] = static_cast<char>(tolower((*str)[i]));
     338        for (auto & elem : *str)
     339        {
     340            elem = static_cast<char>(tolower(elem));
    341341        }
    342342    }
     
    353353    void uppercase(std::string* str)
    354354    {
    355         for (size_t i = 0; i < str->size(); ++i)
    356         {
    357             (*str)[i] = static_cast<char>(toupper((*str)[i]));
     355        for (auto & elem : *str)
     356        {
     357            elem = static_cast<char>(toupper(elem));
    358358        }
    359359    }
     
    460460    {
    461461        size_t j = 0;
    462         for (size_t i = 0; i < str.size(); ++i)
    463         {
    464             if (str[i] == target)
     462        for (auto & elem : str)
     463        {
     464            if (elem == target)
    465465            {
    466                 str[i] = replacement;
     466                elem = replacement;
    467467                ++j;
    468468            }
Note: See TracChangeset for help on using the changeset viewer.