diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2010-01-29 23:55:14 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-05 17:17:46 +0100 |
commit | 03e56f57309a7e9efad0b52cf46e80605f91e57a (patch) | |
tree | beb3b81242a55581ded6a95f9fd49ef3b2b4a628 /src/base | |
parent | 4e71abc1c94647e600e6db322636707bdb9f5817 (diff) | |
download | usdx-03e56f57309a7e9efad0b52cf46e80605f91e57a.tar.gz usdx-03e56f57309a7e9efad0b52cf46e80605f91e57a.tar.xz usdx-03e56f57309a7e9efad0b52cf46e80605f91e57a.zip |
use trim, trim_left, trim_right from boost::algorithm::string
Diffstat (limited to '')
-rw-r--r-- | src/base/songloading/songloading_strategy_txt.cpp | 56 | ||||
-rw-r--r-- | src/base/songloading/songloading_strategy_txt.hpp | 25 |
2 files changed, 7 insertions, 74 deletions
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 <sstream> #include <string> +#include <boost/algorithm/string.hpp> + #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<std::wstring, std::wstring> 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); |