core/file: Move file_readl() out of the file struct
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
074339040b
commit
3b220d3f3a
|
@ -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<std::fstream *>(this), res);
|
||||
std::getline(*static_cast<std::fstream *>(file), res);
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue