Added some to_string.

This commit is contained in:
Christoffer Lerno
2023-06-26 16:21:07 +02:00
parent 83f8bbb91b
commit fc054dad81
6 changed files with 70 additions and 2 deletions

View File

@@ -24,6 +24,16 @@ fn Type Range.get(Range* range, usz index) @operator([])
return range.start + (Type)index;
}
fn String Range.to_string(Range* list, Allocator* using = mem::heap()) @dynamic
{
return string::printf("[%s..%s]", list.start, list.end);
}
fn void! Range.to_format(Range* list, Formatter* formatter) @dynamic
{
formatter.printf("[%s..%s]", list.start, list.end)!;
}
struct ExclusiveRange
{
Type start;
@@ -36,6 +46,16 @@ fn usz ExclusiveRange.len(ExclusiveRange* range) @operator(len)
return (usz)(range.end - range.start);
}
fn void! ExclusiveRange.to_format(ExclusiveRange* list, Formatter* formatter) @dynamic
{
formatter.printf("[%s..<%s]", list.start, list.end)!;
}
fn String ExclusiveRange.to_string(ExclusiveRange* list, Allocator* using = mem::heap()) @dynamic
{
return string::printf("[%s..<%s]", list.start, list.end);
}
/**
* @require index < range.len() : "Can't index into an empty range"
**/