Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 22, 2009, 2:07:44 PM (15 years ago)
Author:
rgrieder
Message:

std::string tweaks:

  • Declared BLANKSTRING in UtilPrereqs.h as well (removed obsolete StringUtils.h includes to avoid dependencies)
  • Using BLANKSTRING if const std::string& return type is possible
  • Replaced a few (const) std::string arguments with const std::string&
  • if (str == "") —> if (str.empty())
  • std::string msg = name + "adsf"; —> const std::string& msg = name + "asdf";
  • std::string asdf = object→getFooBar(); —> const std::string& asdf = object→getFooBar();
  • std::string asdf = "asdf"; —> std::string asdf("asdf");
  • ostream << "."; and name + "." —> ostream << '.'; and name + '.'
  • str = ""; —> str.clear()
  • std::string asdf = ""; —> std::string asdf;
  • asdf_ = ""; (in c'tor) —> delete line
File:
1 edited

Legend:

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

    r5738 r6394  
    4040namespace orxonox
    4141{
    42     std::string BLANKSTRING("");
     42    std::string BLANKSTRING;
    4343
    4444    std::string getUniqueNumberString()
     
    5454    {
    5555        size_t pos;
    56         while ((pos = (*str).find(" ")) < (*str).length())
     56        while ((pos = (*str).find(' ')) < (*str).length())
    5757            (*str).erase(pos, 1);
    58         while ((pos = (*str).find("\t")) < (*str).length())
     58        while ((pos = (*str).find('\t')) < (*str).length())
    5959            (*str).erase(pos, 1);
    60         while ((pos = (*str).find("\n")) < (*str).length())
     60        while ((pos = (*str).find('\n')) < (*str).length())
    6161            (*str).erase(pos, 1);
    6262    }
     
    6969    std::string getStripped(const std::string& str)
    7070    {
    71         std::string output = std::string(str);
     71        std::string output(str);
    7272        strip(&output);
    7373        return output;
     
    9898        size_t quote = start - 1;
    9999
    100         while ((quote = str.find('\"', quote + 1)) != std::string::npos)
     100        while ((quote = str.find('"', quote + 1)) != std::string::npos)
    101101        {
    102102            size_t backslash = quote;
     
    231231    {
    232232        // Strip the line, whitespaces are disturbing
    233         std::string teststring = getStripped(str);
     233        const std::string& teststring = getStripped(str);
    234234
    235235        // There are four possible comment-symbols:
     
    259259    bool isEmpty(const std::string& str)
    260260    {
    261         std::string temp = getStripped(str);
    262         return ((temp == "") || (temp.size() == 0));
     261        return getStripped(str).empty();
    263262    }
    264263
     
    303302        for (size_t pos = 0; (pos = output.find('\f', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\f"); }
    304303        for (size_t pos = 0; (pos = output.find('\a', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\a"); }
    305         for (size_t pos = 0; (pos = output.find('"', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\""); }
     304        for (size_t pos = 0; (pos = output.find('"' , pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\""); }
    306305        for (size_t pos = 0; (pos = output.find('\0', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\0"); }
    307306
     
    319318            return str;
    320319
    321         std::string output = "";
     320        std::string output;
    322321        for (size_t pos = 0; pos < str.size() - 1; )
    323322        {
     
    363362    std::string getLowercase(const std::string& str)
    364363    {
    365         std::string output = std::string(str);
     364        std::string output(str);
    366365        lowercase(&output);
    367366        return output;
     
    387386    std::string getUppercase(const std::string& str)
    388387    {
    389         std::string output = std::string(str);
     388        std::string output(str);
    390389        uppercase(&output);
    391390        return output;
Note: See TracChangeset for help on using the changeset viewer.