MCPcopy Create free account
hub / github.com/avast/retdec / trim

Function trim

src/utils/string.cpp:566–580  ·  view source on GitHub ↗

* @brief Trims the given string. * * @param[in] str String to be trimmed. * @param[in] toTrim String of characters to be trimmed (removed) from the * beginning and the end of @a str. By default, it contains * all whitespace characters from the ASCII set. * * @return Trimmed string. * * For example, trim(" hey there ", " ") returns "hey * there"</t

Source from the content-addressed store, hash-verified

564* there"</tt>.
565*/
566std::string trim(std::string str, const std::string &toTrim) {
567 // Based on
568 // http://www.codeproject.com/Articles/10880/A-trim-implementation-for-std-string
569 std::string::size_type pos = str.find_last_not_of(toTrim);
570 if (pos != std::string::npos) {
571 str.erase(pos + 1);
572 pos = str.find_first_not_of(toTrim);
573 if (pos != std::string::npos) {
574 str.erase(0, pos);
575 }
576 } else {
577 str.erase(str.begin(), str.end());
578 }
579 return str;
580}
581
582/**
583* @brief Splits the given string by a separator.

Callers 7

splitFunction · 0.85
toStringMethod · 0.85
getCommentForFuncMethod · 0.85
TEST_FFunction · 0.85
_serializeMethod · 0.85

Calls 3

eraseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 2

TEST_FFunction · 0.68
_serializeMethod · 0.68