mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
De-macro readline.
This commit is contained in:
@@ -57,6 +57,11 @@ faultdef
|
||||
@return `The string containing the data read.`
|
||||
*>
|
||||
macro String? readline(Allocator allocator, stream = io::stdin())
|
||||
{
|
||||
return readline_impl{$typeof(stream)}(allocator, stream);
|
||||
}
|
||||
|
||||
fn String? readline_impl(Allocator allocator, Stream stream) <Stream> @private
|
||||
{
|
||||
if (allocator == tmem)
|
||||
{
|
||||
@@ -99,16 +104,21 @@ macro String? treadline(stream = io::stdin())
|
||||
*>
|
||||
macro usz? readline_to_stream(out_stream, in_stream = io::stdin())
|
||||
{
|
||||
bool $is_stream = $typeof(in_stream) == InStream;
|
||||
return readline_to_stream_impl{$typeof(in_stream), $typeof(out_stream)}(out_stream, in_stream);
|
||||
}
|
||||
|
||||
fn usz? readline_to_stream_impl(OStream out_stream, IStream in_stream) <IStream, OStream> @private
|
||||
{
|
||||
bool $is_stream = IStream == InStream;
|
||||
$if $is_stream:
|
||||
var func = &in_stream.read_byte;
|
||||
var func @safeinfer = &in_stream.read_byte;
|
||||
char val = func((void*)in_stream)!;
|
||||
$else
|
||||
char val = in_stream.read_byte()!;
|
||||
$endif
|
||||
bool $is_out_stream = $typeof(out_stream) == OutStream;
|
||||
bool $is_out_stream = OStream == OutStream;
|
||||
$if $is_out_stream:
|
||||
var out_func = &out_stream.write_byte;
|
||||
var out_func @safeinfer = &out_stream.write_byte;
|
||||
$endif
|
||||
|
||||
if (val == '\n') return 0;
|
||||
|
||||
Reference in New Issue
Block a user