]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/memory.cpp
Fix Memory::getline
[libs/core.git] / source / io / memory.cpp
index 6ccf84654764cbe8086a3ac841330580d302dcd1..274f6bae91c1a6a1d53f67be3872319bdae85bc2 100644 (file)
@@ -51,7 +51,7 @@ unsigned Memory::do_read(char *buf, unsigned size)
 {
        if(pos==end)
        {
-               eof_flag = true;
+               set_eof();
                return 0;
        }
 
@@ -70,18 +70,23 @@ unsigned Memory::put(char c)
 
 bool Memory::getline(string &line)
 {
+       if(pos==end)
+       {
+               set_eof();
+               return false;
+       }
+
        char *nl = find(pos, end, '\n');
        line.assign(pos, nl);
-       bool result = (nl!=pos);
-       pos = nl;
-       return result;
+       pos = (nl==end ? end : nl+1);
+       return true;
 }
 
 int Memory::get()
 {
        if(pos==end)
        {
-               eof_flag = true;
+               set_eof();
                return -1;
        }