From 7bced9e7855d0292be2da10d40aceb53a6c2575f Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 18 Jan 2010 02:55:02 +0100 Subject: added {r,l}trim_newline that only remove '\r' and '\n', remove '\r' from lyrics --- src/base/songloading/songloading_strategy_txt.cpp | 21 +++++++++++++++++++++ src/base/songloading/songloading_strategy_txt.hpp | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/base/songloading/songloading_strategy_txt.cpp b/src/base/songloading/songloading_strategy_txt.cpp index 1a2c8eaf..2a74dd1d 100644 --- a/src/base/songloading/songloading_strategy_txt.cpp +++ b/src/base/songloading/songloading_strategy_txt.cpp @@ -85,6 +85,16 @@ namespace usdx return line; } + std::string& SongloadingStrategyTxt::ltrim_newlines(std::string& line) + { + std::size_t found = line.find_first_not_of("\n\r"); + if (found != std::string::npos) { + line.erase(0, found - 1); + } + + return line; + } + std::string& SongloadingStrategyTxt::rtrim(std::string& line) { std::size_t found = line.find_last_not_of(" \t\n\r"); @@ -95,6 +105,16 @@ namespace usdx return line; } + std::string& SongloadingStrategyTxt::rtrim_newlines(std::string& line) + { + std::size_t found = line.find_last_not_of("\n\r"); + if (found != std::string::npos) { + line.erase(found + 1); + } + + return line; + } + std::string& SongloadingStrategyTxt::trim(std::string& line) { return ltrim(rtrim(line)); @@ -196,6 +216,7 @@ namespace usdx linestream >> beat >> length >> height >> std::noskipws; linestream.ignore(); getline(linestream, lyric); + rtrim_newlines(lyric); LOG4CXX_DEBUG(log, "Found lyric: '" << lyric << "' at line: " << line_number << " at beat: " << beat << " with length: " << length << diff --git a/src/base/songloading/songloading_strategy_txt.hpp b/src/base/songloading/songloading_strategy_txt.hpp index 0330772b..0f9fd23d 100644 --- a/src/base/songloading/songloading_strategy_txt.hpp +++ b/src/base/songloading/songloading_strategy_txt.hpp @@ -54,6 +54,16 @@ namespace usdx */ std::string& rtrim(std::string& line); + /** + * Removes ''\r'' and ''\n'' in front of the string. + */ + std::string& ltrim_newlines(std::string& line); + + /** + * Removes ''\r'' and ''\n'' behind the string. + */ + std::string& rtrim_newlines(std::string& line); + /** * Removes whitespaces in front of the string and behind it. */ -- cgit v1.2.3