mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Upgrade of mingw in CI. Fix problems using reflection on interface types #1203. Improved debug information on defer. $foreach doesn't create an implicit syntactic scope. Error if `@if` depends on `@if`. Updated Linux stacktrace. Fix of default argument stacktrace. Allow linking libraries directly by file path. Improve inlining warning messages. Added `index_of_char_from`. Compiler crash using enum nameof from different module #1205. Removed unused fields in find_msvc. Use vswhere to find msvc. Update tests for LLVM 19
64 lines
1.2 KiB
C
64 lines
1.2 KiB
C
module std::encoding::csv;
|
|
import std::io;
|
|
|
|
struct CsvReader
|
|
{
|
|
InStream stream;
|
|
String separator;
|
|
}
|
|
|
|
fn void CsvReader.init(&self, InStream stream, String separator = ",")
|
|
{
|
|
self.stream = stream;
|
|
self.separator = separator;
|
|
}
|
|
|
|
fn String[]! CsvReader.read_new_row(self, Allocator allocator = allocator::heap())
|
|
{
|
|
return self.read_new_row_with_allocator(allocator::temp()) @inline;
|
|
}
|
|
|
|
fn String[]! CsvReader.read_new_row_with_allocator(self, Allocator allocator = allocator::heap())
|
|
{
|
|
@pool(allocator)
|
|
{
|
|
return io::treadline(self.stream).split(self.separator, .allocator = allocator);
|
|
};
|
|
}
|
|
|
|
fn String[]! CsvReader.read_temp_row(self)
|
|
{
|
|
return self.read_new_row_with_allocator(allocator::temp()) @inline;
|
|
}
|
|
|
|
fn void! CsvReader.skip_row(self) @maydiscard
|
|
{
|
|
@pool()
|
|
{
|
|
(void)io::treadline(self.stream);
|
|
};
|
|
}
|
|
|
|
macro CsvReader.@each_row(self, int rows = int.max; @body(String[] row))
|
|
{
|
|
InputStream* stream = self.stream;
|
|
String sep = self.separator;
|
|
while (rows--)
|
|
{
|
|
@stack_mem(512; Allocator mem)
|
|
{
|
|
String[] parts;
|
|
@pool()
|
|
{
|
|
String! s = stream.treadline();
|
|
if (catch err = s)
|
|
{
|
|
if (err == IoError.EOF) return;
|
|
return err?;
|
|
}
|
|
parts = s.split(sep, .allocator = mem);
|
|
};
|
|
@body(parts);
|
|
};
|
|
}
|
|
} |