Some updates to builtin checking.

This commit is contained in:
Christoffer Lerno
2023-01-26 14:50:41 +01:00
committed by Christoffer Lerno
parent a95710c93f
commit 5c7d859fdb
5 changed files with 165 additions and 112 deletions

View File

@@ -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;
}

View File

@@ -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];
}