mirror of https://github.com/buggins/dlangui.git
63 lines
2.2 KiB
HTML
63 lines
2.2 KiB
HTML
<html><head>
|
|
<META http-equiv="content-type" content="text/html; charset=utf-8">
|
|
<title>dlangui.core.linestream</title>
|
|
</head><body>
|
|
<h1>dlangui.core.linestream</h1>
|
|
<!-- Generated by Ddoc from src/dlangui/core/linestream.d -->
|
|
DLANGUI library.
|
|
<br><br>
|
|
This module contains text file reader implementation.
|
|
<br><br>
|
|
|
|
Support utf8, utf16, utf32 be and le encodings, and line endings - according to D language source file specification.
|
|
<br><br>
|
|
|
|
Low resource consuming. Doesn't flood with GC allocations. Dup line if you want to store it somewhere.
|
|
<br><br>
|
|
|
|
Tracks line number.
|
|
<br><br>
|
|
|
|
|
|
<br><br>
|
|
<b>Synopsis:</b><br>
|
|
<pre class="d_code"><font color=blue>import</font> dlangui.core.<u>linestream</u>;
|
|
|
|
<font color=blue>import</font> std.stdio;
|
|
<font color=blue>import</font> std.conv;
|
|
<font color=blue>import</font> std.utf;
|
|
string fname = <font color=red>"somefile.d"</font>;
|
|
writeln(<font color=red>"opening file"</font>);
|
|
std.stream.File f = <font color=blue>new</font> std.stream.File(fname);
|
|
<font color=blue>scope</font>(exit) { f.close(); }
|
|
<font color=blue>try</font> {
|
|
LineStream lines = LineStream.create(f, fname);
|
|
<font color=blue>for</font> (;;) {
|
|
<font color=blue>dchar</font>[] s = lines.readLine();
|
|
<font color=blue>if</font> (s <font color=blue>is</font> <font color=blue>null</font>)
|
|
<font color=blue>break</font>;
|
|
writeln(<font color=red>"line "</font> ~ to!string(lines.line()) ~ <font color=red>":"</font> ~ toUTF8(s));
|
|
}
|
|
<font color=blue>if</font> (lines.errorCode != 0) {
|
|
writeln(<font color=red>"Error "</font>, lines.errorCode, <font color=red>" "</font>, lines.errorMessage, <font color=red>" -- at line "</font>, lines.errorLine, <font color=red>" position "</font>, lines.errorPos);
|
|
} <font color=blue>else</font> {
|
|
writeln(<font color=red>"EOF reached"</font>);
|
|
}
|
|
} <font color=blue>catch</font> (Exception e) {
|
|
writeln(<font color=red>"Exception "</font> ~ e.toString);
|
|
}
|
|
|
|
</pre>
|
|
|
|
<br><br>
|
|
<b>License:</b><br>
|
|
Boost License 1.0
|
|
<br><br>
|
|
<b>Authors:</b><br>
|
|
Vadim Lopatin, coolreader.org@gmail.com<br><br>
|
|
|
|
|
|
<hr><small>Page generated by <a href="http://dlang.org/ddoc.html">Ddoc</a>. Vadim Lopatin, 2014
|
|
</small>
|
|
</body></html>
|