diff --git a/core/file.cpp b/core/file.cpp index 2441a82e..95869fb4 100644 --- a/core/file.cpp +++ b/core/file.cpp @@ -75,7 +75,7 @@ static bool __file_open_read(struct file *file) return false; *file >> file->f_prev; - file->getline(); + file_readl(file); return true; } @@ -108,15 +108,15 @@ void file_close(struct file *file) file->f_mode = NOT_OPEN; } -std::string file :: getline() +std::string file_readl(struct file *file) { char c; std::string res; /* Ignore leading whitespace */ - while (peek() == ' ') - read(&c, 1); + while (file->peek() == ' ') + file->read(&c, 1); - std::getline(*static_cast(this), res); + std::getline(*static_cast(file), res); return res; } diff --git a/core/tags/generic.cpp b/core/tags/generic.cpp index 58cc5ded..564fa243 100644 --- a/core/tags/generic.cpp +++ b/core/tags/generic.cpp @@ -30,7 +30,7 @@ void GenericTag :: read(file &file) { gchar *g_lc; - _name = file.getline(); + _name = file_readl(&file); g_lc = string_lowercase(_name.c_str()); _lower = g_lc; g_free(g_lc); diff --git a/core/tags/library.cpp b/core/tags/library.cpp index b8b63a1c..5b7f8a44 100644 --- a/core/tags/library.cpp +++ b/core/tags/library.cpp @@ -25,7 +25,7 @@ const std::string Library :: primary_key() const void Library :: read(file &file) { file >> _enabled; - _path = file.getline(); + _path = file_readl(&file); } void Library :: write(file &file) diff --git a/core/tags/track.cpp b/core/tags/track.cpp index 668c5baf..5f215e88 100644 --- a/core/tags/track.cpp +++ b/core/tags/track.cpp @@ -125,7 +125,7 @@ void Track :: read(file &file) file >> _count >> _length; GenericTag :: read(file); - _path = file.getline(); + _path = file_readl(&file); _library = tags :: get_library(library_id); _artist = tags :: get_artist(artist_id); diff --git a/include/core/file.h b/include/core/file.h index 4a41d441..ea57f6ff 100644 --- a/include/core/file.h +++ b/include/core/file.h @@ -47,15 +47,6 @@ struct file : public std::fstream { unsigned int f_version; /* The file's current data version. */ unsigned int f_prev; /* The file's on-disk data version. */ std::string f_name; /* The file's basename. */ - - /** - * Read an entire line from the file and return it to the caller. - * In theory a return value optimization will occur so returning - * a string by value won't be a performance problem. - * - * @return A string containing the rest of the line. - */ - std::string getline(); }; @@ -91,5 +82,7 @@ bool file_open(struct file *, OpenMode); /* Close an open file, setting file->mode to NOT_OPEN. */ void file_close(struct file *); +/* Read an entire line from the file and return it to the caller. */ +std::string file_readl(struct file *); #endif /* OCARINA_CORE_FILE_H */ diff --git a/tests/core/file.cpp b/tests/core/file.cpp index 3afbf1ad..7d3e1876 100644 --- a/tests/core/file.cpp +++ b/tests/core/file.cpp @@ -84,7 +84,7 @@ static void test_io() test_equal(res, (std::string)"ABCDE"); b >> res; test_equal(res, (std::string)"FGHIJ"); - res = b.getline(); + res = file_readl(&b); test_equal(res, (std::string)"KLMNO PQRST UVWXYZ"); file_close(&b); }