aboutsummaryrefslogtreecommitdiffstats
path: root/src/base/songloading
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-01-28 11:32:39 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-05 17:17:46 +0100
commit271c7cabf5e16a1afed560b9f707b3955b3ec725 (patch)
tree026b6678c6973205e32698af795830d58c5121d6 /src/base/songloading
parent2adaea29500b412c342838e22df2f8b4ac2eb02d (diff)
downloadusdx-271c7cabf5e16a1afed560b9f707b3955b3ec725.tar.gz
usdx-271c7cabf5e16a1afed560b9f707b3955b3ec725.tar.xz
usdx-271c7cabf5e16a1afed560b9f707b3955b3ec725.zip
converted all strings and chars to wstrings and wchar_ts
all strings with displayable content are now the wide strings for proper unicode handling added boost dependency for proper reading unicode from files
Diffstat (limited to 'src/base/songloading')
-rw-r--r--src/base/songloading/songloading_strategy_txt.cpp107
-rw-r--r--src/base/songloading/songloading_strategy_txt.hpp18
2 files changed, 63 insertions, 62 deletions
diff --git a/src/base/songloading/songloading_strategy_txt.cpp b/src/base/songloading/songloading_strategy_txt.cpp
index 0f9e3fff..c65e9347 100644
--- a/src/base/songloading/songloading_strategy_txt.cpp
+++ b/src/base/songloading/songloading_strategy_txt.cpp
@@ -47,16 +47,16 @@ namespace usdx
{
}
- std::pair<std::string, std::string> SongloadingStrategyTxt::split_header_field(std::string &line)
+ std::pair<std::wstring, std::wstring> SongloadingStrategyTxt::split_header_field(std::wstring &line)
{
- std::size_t pos = line.find(':');
+ std::size_t pos = line.find(L':');
- if (line[0] != '#' || pos == std::string::npos) {
- LOG4CXX_DEBUG(log, "Tried to parse invalid header line: '" << line << "'");
+ if (line[0] != L'#' || pos == std::wstring::npos) {
+ LOG4CXX_DEBUG(log, L"Tried to parse invalid header line: '" << line << L"'");
throw "Invalid header!";
}
- std::pair<std::string, std::string> result;
+ std::pair<std::wstring, std::wstring> result;
// copy the substring until ':', without # to result.first and
// transform to upper case
@@ -72,52 +72,52 @@ namespace usdx
// line is already rtrimmed
ltrim(result.second);
- LOG4CXX_DEBUG(log, "Found header: '" << result.first << "' with value '" << result.second << "'");
+ LOG4CXX_DEBUG(log, L"Found header: '" << result.first << L"' with value '" << result.second << L"'");
return result;
}
- std::string& SongloadingStrategyTxt::ltrim(std::string& line)
+ std::wstring& SongloadingStrategyTxt::ltrim(std::wstring& line)
{
- std::size_t found = line.find_first_not_of(" \t\n\r");
- if (found != std::string::npos && found >= 1) {
+ 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::string& SongloadingStrategyTxt::ltrim_newlines(std::string& line)
+ std::wstring& SongloadingStrategyTxt::ltrim_newlines(std::wstring& line)
{
- std::size_t found = line.find_first_not_of("\n\r");
- if (found != std::string::npos) {
+ 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::string& SongloadingStrategyTxt::rtrim(std::string& line)
+ std::wstring& SongloadingStrategyTxt::rtrim(std::wstring& line)
{
- std::size_t found = line.find_last_not_of(" \t\n\r");
- if (found != std::string::npos) {
+ 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::string& SongloadingStrategyTxt::rtrim_newlines(std::string& line)
+ std::wstring& SongloadingStrategyTxt::rtrim_newlines(std::wstring& line)
{
- std::size_t found = line.find_last_not_of("\n\r");
- if (found != std::string::npos) {
+ std::size_t found = line.find_last_not_of(L"\n\r");
+ if (found != std::wstring::npos) {
line.erase(found + 1);
}
return line;
}
- std::string& SongloadingStrategyTxt::trim(std::string& line)
+ std::wstring& SongloadingStrategyTxt::trim(std::wstring& line)
{
return ltrim(rtrim(line));
}
@@ -139,17 +139,17 @@ namespace usdx
bool SongloadingStrategyTxt::parse_line(Song* song, File& file, const int line_number)
{
try {
- std::string line;
+ std::wstring line;
std::getline(file.stream(), line);
- char type;
- std::istringstream linestream(line);
+ wchar_t type;
+ std::wistringstream linestream(line);
linestream >> std::skipws >> type;
- if (type == '#') {
+ if (type == L'#') {
// ignore, header already read
}
- else if (type == 'E') {
+ else if (type == L'E') {
// song end
if (file.stream().eof()) {
LOG4CXX_WARN(log, "End marker found in line " << line_number <<
@@ -158,30 +158,31 @@ namespace usdx
return false;
}
- else if (type == '-') {
+ else if (type == L'-') {
parse_newline(song, linestream, line_number);
}
- else if (type == 'B') {
+ else if (type == L'B') {
parse_bpm(song, linestream, line_number);
}
- else if (type == ':' || type == 'F' || type == '*') {
+ else if (type == L':' || type == L'F' || type == L'*') {
parse_note(song, type, linestream, line_number);
}
else {
- LOG4CXX_WARN(log, "Unknown line in song: '" << line <<
- "' in file: " << song->get_filename() <<
- " at line " << line_number);
+ LOG4CXX_WARN(log, L"Unknown line in song: '" << line <<
+ L"' in file: " << std::wstring(song->get_filename().begin(),
+ song->get_filename().end()) <<
+ L" at line " << line_number);
}
}
catch (std::exception &e) {
- LOG4CXX_WARN(log, "Error in song file at line " <<
- line_number << ": " << e.what());
+ LOG4CXX_WARN(log, L"Error in song file at line " <<
+ line_number << L": " << e.what());
}
return true;
}
- void SongloadingStrategyTxt::parse_newline(Song *song, std::istringstream& linestream, const int line_number)
+ void SongloadingStrategyTxt::parse_newline(Song *song, std::wistringstream& linestream, const int line_number)
{
// line break
int line_out, line_in = -1;
@@ -189,63 +190,63 @@ namespace usdx
linestream >> line_out;
if (linestream.good()) {
linestream >> line_in;
- LOG4CXX_DEBUG(log, "Found newline in line " <<
- line_number << " with out of last line with "
- << line_out << " and in of next line " << line_in);
+ LOG4CXX_DEBUG(log, L"Found newline in line " <<
+ line_number << L" with out of last line with " <<
+ line_out << L" and in of next line " << line_in);
}
else {
- LOG4CXX_DEBUG(log, "Found newline in line " <<
- line_number << " with out of last line with "
- << line_out);
+ LOG4CXX_DEBUG(log, L"Found newline in line " <<
+ line_number << L" with out of last line with " <<
+ line_out);
}
song->new_line(line_out, line_in);
}
- void SongloadingStrategyTxt::parse_bpm(Song *song, std::istringstream& linestream, const int line_number)
+ void SongloadingStrategyTxt::parse_bpm(Song *song, std::wistringstream& linestream, const int line_number)
{
// new bpm
int beat;
LocaleIndependentFloat new_bpm;
linestream >> beat >> new_bpm;
- LOG4CXX_DEBUG(log, "Found new bpm in line " <<
- line_number << " starting at beat: " <<
- beat << " and new bpm of " << new_bpm.get_value());
+ LOG4CXX_DEBUG(log, L"Found new bpm in line " <<
+ line_number << L" starting at beat: " <<
+ beat << L" and new bpm of " << new_bpm.get_value());
song->new_bpm(beat, new_bpm.get_value());
}
- void SongloadingStrategyTxt::parse_note(Song *song, char type, std::istringstream& linestream, const int line_number)
+ void SongloadingStrategyTxt::parse_note(Song *song, wchar_t type, std::wistringstream& linestream, const int line_number)
{
// normal line
int beat, length, height;
- std::string lyric;
+ std::wstring lyric;
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 <<
- " at height: " << height);
+ LOG4CXX_DEBUG(log, L"Found lyric: '" << lyric << L"' at line: " << line_number <<
+ L" at beat: " << beat << L" with length: " << length <<
+ L" at height: " << height);
song->new_note(type, beat, length, height, lyric);
}
Song* SongloadingStrategyTxt::load_header(const std::string& filename)
{
File file(filename);
- std::string line;
- std::map<std::string, std::string> header_fields;
+ std::wstring line;
+ std::map<std::wstring, std::wstring> header_fields;
bool header = true, notes_found = false;
while (file.stream().good()) {
std::getline(file.stream(), line);
trim(line);
- LOG4CXX_DEBUG(log, "Line: " << line);
+ LOG4CXX_DEBUG(log, L"Line: " << line);
- if (header && line[0] == '#') {
+ if (header && line[0] == L'#') {
// header
header_fields.insert(split_header_field(line));
@@ -256,7 +257,7 @@ namespace usdx
header = false;
}
- if (line[0] == ':' || line[0] == '*' || line[0] == 'F') {
+ if (line[0] == L':' || line[0] == L'*' || line[0] == L'F') {
notes_found = true;
break;
}
diff --git a/src/base/songloading/songloading_strategy_txt.hpp b/src/base/songloading/songloading_strategy_txt.hpp
index 0f9fd23d..097f35cf 100644
--- a/src/base/songloading/songloading_strategy_txt.hpp
+++ b/src/base/songloading/songloading_strategy_txt.hpp
@@ -42,37 +42,37 @@ namespace usdx
/**
* Split the header field in name and value.
*/
- std::pair<std::string, std::string> split_header_field(std::string &line);
+ std::pair<std::wstring, std::wstring> split_header_field(std::wstring &line);
/**
* Removes whitespaces in front of the string.
*/
- std::string& ltrim(std::string& line);
+ std::wstring& ltrim(std::wstring& line);
/**
* Removes whitespaces behind the string.
*/
- std::string& rtrim(std::string& line);
+ std::wstring& rtrim(std::wstring& line);
/**
* Removes ''\r'' and ''\n'' in front of the string.
*/
- std::string& ltrim_newlines(std::string& line);
+ std::wstring& ltrim_newlines(std::wstring& line);
/**
* Removes ''\r'' and ''\n'' behind the string.
*/
- std::string& rtrim_newlines(std::string& line);
+ std::wstring& rtrim_newlines(std::wstring& line);
/**
* Removes whitespaces in front of the string and behind it.
*/
- std::string& trim(std::string& line);
+ std::wstring& trim(std::wstring& line);
bool parse_line(Song* song, File& file, const int line_number);
- void parse_newline(Song* song, std::istringstream& linestream, const int line_number);
- void parse_bpm(Song* song, std::istringstream& linestream, const int line_number);
- void parse_note(Song* song, char type, std::istringstream& linestream, 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);
+ void parse_note(Song* song, wchar_t type, std::wistringstream& linestream, const int line_number);
public: