Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2015-12-22 21:15:00 +0300
committerHieu Hoang <hieuhoang@gmail.com>2015-12-22 21:15:00 +0300
commit139ee7e0c86a4b59bd24d9138e6b9eb8000d3054 (patch)
tree0f1a1a049c77379b847e2807634a4db1437d1d92 /util
parent1f2c4785b41ac0559695e3baaf720fe3ebbed319 (diff)
fix tokenization
Diffstat (limited to 'util')
-rw-r--r--util/string_piece.hh8
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()));