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/Convert.h

    r5738 r6394  
    4343
    4444#include "Debug.h"
    45 #include "StringUtils.h"
    4645#include "TemplateUtils.h"
    4746
     
    336335        FORCEINLINE static bool convert(std::string* output, const char input)
    337336        {
    338             *output = std::string(1, input);
     337            *output = input;
    339338            return true;
    340339        }
     
    345344        FORCEINLINE static bool convert(std::string* output, const unsigned char input)
    346345        {
    347             *output = std::string(1, input);
     346            *output = input;
    348347            return true;
    349348        }
     
    352351    struct ConverterExplicit<std::string, char>
    353352    {
    354         FORCEINLINE static bool convert(char* output, const std::string input)
    355         {
    356             if (input != "")
     353        FORCEINLINE static bool convert(char* output, const std::string& input)
     354        {
     355            if (!input.empty())
    357356                *output = input[0];
    358357            else
     
    364363    struct ConverterExplicit<std::string, unsigned char>
    365364    {
    366         FORCEINLINE static bool convert(unsigned char* output, const std::string input)
    367         {
    368             if (input != "")
     365        FORCEINLINE static bool convert(unsigned char* output, const std::string& input)
     366        {
     367            if (!input.empty())
    369368                *output = input[0];
    370369            else
     
    389388    };
    390389
     390    // Declarations to avoid StringUtils.h include
     391    _UtilExport std::string removeTrailingWhitespaces(const std::string& str);
     392    _UtilExport std::string getLowercase(const std::string& str);
     393
    391394    // std::string to bool
    392395    template <>
     
    395398        static bool convert(bool* output, const std::string& input)
    396399        {
    397             std::string stripped = getLowercase(removeTrailingWhitespaces(input));
     400            const std::string& stripped = getLowercase(removeTrailingWhitespaces(input));
    398401            if (stripped == "true" || stripped == "on" || stripped == "yes")
    399402            {
    400               *output = true;
    401               return true;
     403                *output = true;
     404                return true;
    402405            }
    403406            else if (stripped == "false" || stripped == "off" || stripped == "no")
    404407            {
    405               *output = false;
    406               return true;
     408                *output = false;
     409                return true;
    407410            }
    408411
Note: See TracChangeset for help on using the changeset viewer.