diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-12-22 21:15:00 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-12-22 21:15:00 +0300 |
commit | 139ee7e0c86a4b59bd24d9138e6b9eb8000d3054 (patch) | |
tree | 0f1a1a049c77379b847e2807634a4db1437d1d92 /util | |
parent | 1f2c4785b41ac0559695e3baaf720fe3ebbed319 (diff) |
fix tokenization
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())); |