Fix struct function ordering in c files
This commit is contained in:
@@ -10,51 +10,44 @@ UTF32_Result :: struct
|
||||
out_str: U32
|
||||
advance: S64
|
||||
error : S64
|
||||
UTF16_Result :: struct
|
||||
out_str: [2]U16
|
||||
len : S64
|
||||
error : S64
|
||||
|
||||
|
||||
utf8_to_utf32 :: (c: *U8, max_advance: S64): UTF32_Result
|
||||
result: UTF32_Result
|
||||
utf8_to_utf32 :: (c: *U8, max_advance: S64): U32, S64
|
||||
out_str: U32
|
||||
advance: S64
|
||||
if (c[0] & 0b10000000) == 0
|
||||
if max_advance >= 1
|
||||
c0 := c[0]->U32
|
||||
result.out_str = c0
|
||||
result.advance = 1
|
||||
else;; result.error = 1
|
||||
out_str = c0
|
||||
advance = 1
|
||||
|
||||
elif (c[0] & 0b11100000) == 0b11000000
|
||||
if (c[1] & 0b11000000) == 0b10000000 // Continuation byte required
|
||||
if max_advance >= 2
|
||||
c0 := c[0]->U32; c1 := c[1]->U32
|
||||
result.out_str = (c0 & 0b00011111) << 6 | (c1 & 0b00111111)
|
||||
result.advance = 2
|
||||
else;; result.error = 2
|
||||
else;; result.error = 2
|
||||
out_str = (c0 & 0b00011111) << 6 | (c1 & 0b00111111)
|
||||
advance = 2
|
||||
|
||||
elif (c[0] & 0b11110000) == 0b11100000
|
||||
if (c[1] & 0b11000000) == 0b10000000 && (c[2] & 0b11000000) == 0b10000000 // Two continuation bytes required
|
||||
if max_advance >= 3
|
||||
c0 := c[0]->U32; c1 := c[1]->U32; c2 := c[2]->U32
|
||||
result.out_str = (c0 & 0b00001111) << 12 | (c1 & 0b00111111) << 6 | (c2 & 0b00111111)
|
||||
result.advance = 3
|
||||
else;; result.error = 3
|
||||
else;; result.error = 3
|
||||
out_str = (c0 & 0b00001111) << 12 | (c1 & 0b00111111) << 6 | (c2 & 0b00111111)
|
||||
advance = 3
|
||||
|
||||
elif (c[0] & 0b11111000) == 0b11110000
|
||||
if (c[1] & 0b11000000) == 0b10000000 && (c[2] & 0b11000000) == 0b10000000 && (c[3] & 0b11000000) == 0b10000000 // Three continuation bytes required
|
||||
if max_advance >= 4
|
||||
c0 := c[0]->U32; c1 := c[1]->U32; c2 := c[2]->U32; c3 := c[3]->U32
|
||||
result.out_str = (c0 & 0b00001111) << 18 | (c1 & 0b00111111) << 12 | (c2 & 0b00111111) << 6 | (c3 & 0b00111111)
|
||||
result.advance = 4
|
||||
else;; result.error = 4
|
||||
else;; result.error = 4
|
||||
else;; result.error = 4
|
||||
out_str = (c0 & 0b00001111) << 18 | (c1 & 0b00111111) << 12 | (c2 & 0b00111111) << 6 | (c3 & 0b00111111)
|
||||
advance = 4
|
||||
|
||||
return result
|
||||
return out_str, advance
|
||||
|
||||
UTF16_Result :: struct
|
||||
out_str: [2]U16
|
||||
len : S64
|
||||
error : S64
|
||||
utf32_to_utf16 :: (codepoint: U32): [2]U16, S64
|
||||
str: [2]U16
|
||||
len := 0
|
||||
@@ -81,10 +74,10 @@ string_to_string16 :: (in: String): String16
|
||||
alloc_size := (length_of(in)*2)+1
|
||||
result := String16{str = allocate(alloc_size->U64)->*U16}
|
||||
for i := 0, i < length_of(in)
|
||||
decode := utf8_to_utf32(in_str + i, length_of(in) - i)
|
||||
if !decode.error
|
||||
i += decode.advance
|
||||
s16, s16_len := utf32_to_utf16(decode.out_str)
|
||||
s32, s32_len := utf8_to_utf32(in_str + i, length_of(in) - i)
|
||||
if s32_len != 0
|
||||
i += s32_len
|
||||
s16, s16_len := utf32_to_utf16(s32)
|
||||
if s16_len != 0
|
||||
for j := 0, j < s16_len, j++
|
||||
result.str[result.len++] = s16[j]
|
||||
@@ -103,14 +96,14 @@ test_unicode :: ()
|
||||
string_result := string_to_string16(string)
|
||||
print(string_result)
|
||||
|
||||
result := utf8_to_utf32(&"A"[0], 1)
|
||||
assert(result.out_str == 'A, "Invalid decode") // '
|
||||
s32, s32_len := utf8_to_utf32(&"A"[0], 1)
|
||||
assert(s32 == 'A, "Invalid decode") // '
|
||||
|
||||
result = utf8_to_utf32(&"ć"[0], 2)
|
||||
assert(result.out_str == 0x107, "Invalid decode")
|
||||
s32_2, s32_len_2 := utf8_to_utf32(&"ć"[0], 2)
|
||||
assert(s32_2 == 0x107, "Invalid decode")
|
||||
|
||||
result = utf8_to_utf32(&"ó"[0], 2)
|
||||
assert(result.out_str == 0xF3, "Invalid decode")
|
||||
s32_3, s32_len_3 := utf8_to_utf32(&"ó"[0], 2)
|
||||
assert(s32_3 == 0xF3, "Invalid decode")
|
||||
|
||||
Vec2I :: struct;; x: S64; y: S64
|
||||
Vec2 :: struct;; x: F32; y: F32
|
||||
|
||||
Reference in New Issue
Block a user