From 5b6945d909883767a7bd1c9c065d5be0f4f3c37b Mon Sep 17 00:00:00 2001 From: Chao Shen Date: Thu, 1 Feb 2018 17:12:36 +0800 Subject: [PATCH] Remove last CR. --- src/utils.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/utils.cc b/src/utils.cc index 84bdca07..f7de11d9 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -52,6 +52,10 @@ std::string Trim(std::string s) { TrimInPlace(s); return s; } +void RemoveLastCR(std::string& s) { + if (!s.empty() && *s.rbegin() == '\r') + s.pop_back(); +} uint64_t HashUsr(const std::string& s) { return HashUsr(s.c_str(), s.size()); @@ -334,6 +338,8 @@ std::vector ToLines(const std::string& content, while (getline(lines, line)) { if (trim_whitespace) TrimInPlace(line); + else + RemoveLastCR(line); result.push_back(line); }