diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/string_piece.hh | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/util/string_piece.hh b/util/string_piece.hh index 9c4798217..428808692 100644 --- a/util/string_piece.hh +++ b/util/string_piece.hh @@ -257,6 +257,14 @@ inline bool operator>=(const StringPiece& x, const StringPiece& y) { return !(x < y); } +inline StringPiece Trim(const StringPiece& str, const std::string dropChars = " \t\n\r") +{ + StringPiece::size_type startPos = str.find_first_not_of(dropChars); + StringPiece::size_type endPos = str.find_last_not_of(dropChars); + StringPiece ret = str.substr(startPos, endPos - startPos + 1); + return ret; +} + // allow StringPiece to be logged (needed for unit testing). inline std::ostream& operator<<(std::ostream& o, const StringPiece& piece) { return o.write(piece.data(), static_cast<std::streamsize>(piece.size())); |