mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Some updates to builtin checking.
This commit is contained in:
committed by
Christoffer Lerno
parent
a95710c93f
commit
5c7d859fdb
@@ -307,6 +307,8 @@ fn usz! utf32to8(Char32[] utf32, String utf8_buffer)
|
||||
len -= used;
|
||||
ptr += used;
|
||||
}
|
||||
// Zero terminate if there is space.
|
||||
if (len > 0) ptr[0] = 0;
|
||||
return utf8_buffer.len - len;
|
||||
}
|
||||
|
||||
@@ -331,6 +333,8 @@ fn usz! utf8to32(String utf8, Char32[] utf32_buffer)
|
||||
i += width;
|
||||
ptr[len32++] = uc;
|
||||
}
|
||||
// Zero terminate if possible
|
||||
if (len32 + 1 < buf_len) ptr[len32] = 0;
|
||||
return len32;
|
||||
}
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ fn usz utf8_codepoints(String utf8)
|
||||
return len;
|
||||
}
|
||||
|
||||
fn Char32[]! utf8to32(String utf8, Allocator* allocator = mem::current_allocator)
|
||||
fn Char32[]! utf8to32(String utf8, Allocator* allocator = mem::current_allocator())
|
||||
{
|
||||
usz codepoints = conv::utf8_codepoints(utf8);
|
||||
Char32* data = allocator.alloc(Char32.sizeof * (codepoints + 1))?;
|
||||
@@ -297,7 +297,7 @@ fn Char32[]! utf8to32(String utf8, Allocator* allocator = mem::current_allocator
|
||||
return data[:codepoints];
|
||||
}
|
||||
|
||||
fn String utf32to8(Char32[] utf32, Allocator* allocator = mem::current_allocator)
|
||||
fn String utf32to8(Char32[] utf32, Allocator* allocator = mem::current_allocator())
|
||||
{
|
||||
usz len = conv::utf8len_for_utf32(utf32);
|
||||
char* data = allocator.alloc(len + 1)!!;
|
||||
@@ -321,6 +321,7 @@ fn String! utf16to8(Char16[] utf16, Allocator* allocator = mem::current_allocato
|
||||
usz len = conv::utf8len_for_utf16(utf16);
|
||||
char* data = allocator.alloc(len + 1)?;
|
||||
conv::utf16to8_unsafe(utf16, data)?;
|
||||
data[len] = 0;
|
||||
return data[:len];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user