Returning a reference from various corestr.cpp calls to avoid unnecessary string copies (#2613)

This commit is contained in:
npwoods 2017-09-02 09:09:00 -04:00 committed by Vas Crabb
parent e0c2b67676
commit d217e1fbec
2 changed files with 13 additions and 13 deletions

View File

@ -171,7 +171,7 @@ void strreplacechr(std::string& str, char ch, char newch)
} }
} }
static std::string internal_strtrimspace(std::string& str, bool right_only) static std::string &internal_strtrimspace(std::string& str, bool right_only)
{ {
// identify the start // identify the start
std::string::iterator start = str.begin(); std::string::iterator start = str.begin();
@ -196,33 +196,33 @@ static std::string internal_strtrimspace(std::string& str, bool right_only)
return str; return str;
} }
std::string strtrimspace(std::string& str) std::string &strtrimspace(std::string& str)
{ {
return internal_strtrimspace(str, false); return internal_strtrimspace(str, false);
} }
std::string strtrimrightspace(std::string& str) std::string &strtrimrightspace(std::string& str)
{ {
return internal_strtrimspace(str, true); return internal_strtrimspace(str, true);
} }
std::string strmakeupper(std::string& str) std::string &strmakeupper(std::string& str)
{ {
std::transform(str.begin(), str.end(), str.begin(), ::toupper); std::transform(str.begin(), str.end(), str.begin(), ::toupper);
return str; return str;
} }
/** /**
* @fn std::string strmakelower(std::string& str) * @fn std::string &strmakelower(std::string& str)
* *
* @brief Strmakelowers the given string. * @brief Changes the given string to lower case.
* *
* @param [in,out] str The string. * @param [in,out] str The string to make lower case
* *
* @return A std::string. * @return A reference to the original std::string having been changed to lower case
*/ */
std::string strmakelower(std::string& str) std::string &strmakelower(std::string& str)
{ {
std::transform(str.begin(), str.end(), str.begin(), ::tolower); std::transform(str.begin(), str.end(), str.begin(), ::tolower);
return str; return str;

View File

@ -66,10 +66,10 @@ int strcatvprintf(std::string &str, const char *format, va_list args);
void strdelchr(std::string& str, char chr); void strdelchr(std::string& str, char chr);
void strreplacechr(std::string& str, char ch, char newch); void strreplacechr(std::string& str, char ch, char newch);
std::string strtrimspace(std::string& str); std::string &strtrimspace(std::string& str);
std::string strtrimrightspace(std::string& str); std::string &strtrimrightspace(std::string& str);
std::string strmakeupper(std::string& str); std::string &strmakeupper(std::string& str);
std::string strmakelower(std::string& str); std::string &strmakelower(std::string& str);
int strreplace(std::string &str, const std::string& search, const std::string& replace); int strreplace(std::string &str, const std::string& search, const std::string& replace);
#endif /* __CORESTR_H__ */ #endif /* __CORESTR_H__ */