Why does File.byLine() return char[] and not string
Meta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Oct 18 10:53:36 PDT 2015
On Sunday, 18 October 2015 at 15:03:22 UTC, Suliman wrote:
> Sorry, but could you explain more simply? I reread all
> information, bit can't understand about what buffer you are
> talking.
This is more or less how byLine works, simplified:
struct ByLine
{
File file;
char[] line;
char[] buffer;
char terminator;
bool empty() { return line is null; }
char[] front() { return line; }
void popFront()
{
line = buffer;
file.readLine(line, terminator); //This overwrites the
current contents of line
if (line.length > buffer.length)
{
buffer = line;
}
if (line.empty) line = null;
}
}
auto byLine(string fileName, char terminator = '\n')
{
return ByLine(File(fileName), terminator);
}
> And what is "signal"? How it's working?
It's just an expression that means "to convey information". So
when ByLine.front returns char[], a mutable array of char, it's
meant to convey to the programmer that since the return value is
mutable, it could change and they should make a copy.
More information about the Digitalmars-d-learn
mailing list