From 03e56f57309a7e9efad0b52cf46e80605f91e57a Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 29 Jan 2010 23:55:14 +0100 Subject: use trim, trim_left, trim_right from boost::algorithm::string --- src/base/songloading/songloading_strategy_txt.cpp | 56 +++-------------------- src/base/songloading/songloading_strategy_txt.hpp | 25 ---------- 2 files changed, 7 insertions(+), 74 deletions(-) (limited to 'src/base/songloading') diff --git a/src/base/songloading/songloading_strategy_txt.cpp b/src/base/songloading/songloading_strategy_txt.cpp index c65e9347..efcc3740 100644 --- a/src/base/songloading/songloading_strategy_txt.cpp +++ b/src/base/songloading/songloading_strategy_txt.cpp @@ -29,6 +29,8 @@ #include #include +#include + #include "songloading_strategy_txt.hpp" #include "utils/file.hpp" #include "utils/locale_independent_float.hpp" @@ -65,63 +67,18 @@ namespace usdx result.first.begin(), toupper); // line is already ltrimmed - rtrim(result.first); + boost::trim_right(result.first); result.second = line.substr(pos + 1); // line is already rtrimmed - ltrim(result.second); + boost::trim_left(result.second); LOG4CXX_DEBUG(log, L"Found header: '" << result.first << L"' with value '" << result.second << L"'"); return result; } - std::wstring& SongloadingStrategyTxt::ltrim(std::wstring& line) - { - std::size_t found = line.find_first_not_of(L" \t\n\r"); - if (found != std::wstring::npos && found >= 1) { - line.erase(0, found - 1); - } - - return line; - } - - std::wstring& SongloadingStrategyTxt::ltrim_newlines(std::wstring& line) - { - std::size_t found = line.find_first_not_of(L"\n\r"); - if (found != std::wstring::npos) { - line.erase(0, found - 1); - } - - return line; - } - - std::wstring& SongloadingStrategyTxt::rtrim(std::wstring& line) - { - std::size_t found = line.find_last_not_of(L" \t\n\r"); - if (found != std::wstring::npos) { - line.erase(found + 1); - } - - return line; - } - - std::wstring& SongloadingStrategyTxt::rtrim_newlines(std::wstring& line) - { - std::size_t found = line.find_last_not_of(L"\n\r"); - if (found != std::wstring::npos) { - line.erase(found + 1); - } - - return line; - } - - std::wstring& SongloadingStrategyTxt::trim(std::wstring& line) - { - return ltrim(rtrim(line)); - } - Song* SongloadingStrategyTxt::load_song(Song *song) { LOG4CXX_DEBUG(log, "Starting loading song from file: " << song->get_filename()); @@ -225,7 +182,7 @@ namespace usdx linestream >> beat >> length >> height >> std::noskipws; linestream.ignore(); getline(linestream, lyric); - rtrim_newlines(lyric); + boost::trim_right_if(lyric, boost::is_cntrl()); LOG4CXX_DEBUG(log, L"Found lyric: '" << lyric << L"' at line: " << line_number << L" at beat: " << beat << L" with length: " << length << @@ -243,7 +200,8 @@ namespace usdx while (file.stream().good()) { std::getline(file.stream(), line); - trim(line); + boost::trim(line); + boost::trim_if(line, boost::is_cntrl()); LOG4CXX_DEBUG(log, L"Line: " << line); if (header && line[0] == L'#') { diff --git a/src/base/songloading/songloading_strategy_txt.hpp b/src/base/songloading/songloading_strategy_txt.hpp index 097f35cf..a285042f 100644 --- a/src/base/songloading/songloading_strategy_txt.hpp +++ b/src/base/songloading/songloading_strategy_txt.hpp @@ -44,31 +44,6 @@ namespace usdx */ std::pair split_header_field(std::wstring &line); - /** - * Removes whitespaces in front of the string. - */ - std::wstring& ltrim(std::wstring& line); - - /** - * Removes whitespaces behind the string. - */ - std::wstring& rtrim(std::wstring& line); - - /** - * Removes ''\r'' and ''\n'' in front of the string. - */ - std::wstring& ltrim_newlines(std::wstring& line); - - /** - * Removes ''\r'' and ''\n'' behind the string. - */ - std::wstring& rtrim_newlines(std::wstring& line); - - /** - * Removes whitespaces in front of the string and behind it. - */ - std::wstring& trim(std::wstring& line); - bool parse_line(Song* song, File& file, const int line_number); void parse_newline(Song* song, std::wistringstream& linestream, const int line_number); void parse_bpm(Song* song, std::wistringstream& linestream, const int line_number); -- cgit v1.2.3