Skip to content

Commit

Permalink
Convert tabs to spaces internally before parsing MML, fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
superctr committed Jan 2, 2021
1 parent 7ee43e0 commit 5ff8880
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/song_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void Song_Manager::compile_job(std::unique_lock<std::mutex>& lock, std::string b
std::stringstream stream(buffer);
for(; std::getline(stream, str);)
{
input.read_line(str, line);
input.read_line(tabs_to_spaces(str), line);
temp_lines.get()->insert({line, input.get_track_map()});
line++;
}
Expand Down Expand Up @@ -450,3 +450,29 @@ void Song_Manager::compile_job(std::unique_lock<std::mutex>& lock, std::string b
error_reference = ref;
}

//! Convert all tabs to spaces in a string.
/*!
* Currently tabstop is hardcoded to 4 to match the editor.
*/
std::string Song_Manager::tabs_to_spaces(const std::string& str) const
{
const unsigned int tabstop = 4;
std::string out = "";
for(char i : str)
{
if(i == '\t')
{
do
{
out.push_back(' ');
}
while(out.size() % tabstop != 0);
}
else
{
out.push_back(i);
}
}
return out;
}

1 change: 1 addition & 0 deletions src/song_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Song_Manager
private:
void worker();
void compile_job(std::unique_lock<std::mutex>& lock, std::string buffer, std::string filename);
std::string tabs_to_spaces(const std::string& str) const;

// song status
const static int max_channels;
Expand Down

0 comments on commit 5ff8880

Please sign in to comment.