Make GingerBill happy #96

Merged
MartinFouilleul merged 3 commits from flip_oc_str8 into main 2023-09-11 12:21:35 +00:00
6 changed files with 29 additions and 28 deletions

View File

@ -629,15 +629,15 @@ oc_str32 oc_font_get_glyph_indices_from_font_data(oc_font_data* fontData, oc_str
}
backing.ptr[i] = glyphIndex;
}
oc_str32 res = { .len = count, .ptr = backing.ptr };
oc_str32 res = {.ptr = backing.ptr , .len = count};
return (res);
}
u32 oc_font_get_glyph_index_from_font_data(oc_font_data* fontData, oc_utf32 codePoint)
{
u32 glyphIndex = 0;
oc_str32 codePoints = { 1, &codePoint };
oc_str32 backing = { 1, &glyphIndex };
oc_str32 codePoints = { .ptr = &codePoint, .len = 1 };
oc_str32 backing = { .ptr = &glyphIndex, 1 };
oc_font_get_glyph_indices_from_font_data(fontData, codePoints, backing);
return (glyphIndex);
}
@ -655,15 +655,15 @@ oc_str32 oc_font_get_glyph_indices(oc_font font, oc_str32 codePoints, oc_str32 b
oc_str32 oc_font_push_glyph_indices(oc_font font, oc_arena* arena, oc_str32 codePoints)
{
u32* buffer = oc_arena_push_array(arena, u32, codePoints.len);
oc_str32 backing = { codePoints.len, buffer };
oc_str32 backing = { .ptr = buffer, .len = codePoints.len };
return (oc_font_get_glyph_indices(font, codePoints, backing));
}
u32 oc_font_get_glyph_index(oc_font font, oc_utf32 codePoint)
{
u32 glyphIndex = 0;
oc_str32 codePoints = { 1, &codePoint };
oc_str32 backing = { 1, &glyphIndex };
oc_str32 codePoints = { .ptr = &codePoint, .len = 1 };
oc_str32 backing = { .ptr = &glyphIndex, .len = 1 };
oc_font_get_glyph_indices(font, codePoints, backing);
return (glyphIndex);
}
@ -783,7 +783,7 @@ oc_text_metrics oc_font_text_metrics_utf32(oc_font font, f32 fontSize, oc_str32
if(missingGlyphIndex)
{
oc_font_get_glyph_metrics_from_font_data(fontData, (oc_str32){ 1, &missingGlyphIndex }, &missingGlyphMetrics);
oc_font_get_glyph_metrics_from_font_data(fontData, (oc_str32){ .ptr = &missingGlyphIndex, .len = 1 }, &missingGlyphMetrics);
}
else
{
@ -793,7 +793,7 @@ oc_text_metrics oc_font_text_metrics_utf32(oc_font font, f32 fontSize, oc_str32
missingGlyphIndex = oc_font_get_glyph_index_from_font_data(fontData, 'X');
if(missingGlyphIndex)
{
oc_font_get_glyph_metrics_from_font_data(fontData, (oc_str32){ 1, &missingGlyphIndex }, &missingGlyphMetrics);
oc_font_get_glyph_metrics_from_font_data(fontData, (oc_str32){ .ptr = &missingGlyphIndex, .len = 1 }, &missingGlyphMetrics);
}
else
{
@ -1428,7 +1428,7 @@ oc_rect oc_glyph_outlines_from_font_data(oc_font_data* fontData, oc_str32 glyphI
if(missingGlyphIndex)
{
oc_font_get_glyph_metrics_from_font_data(fontData, (oc_str32){ .len = 1, .ptr = &missingGlyphIndex }, &missingGlyphMetrics);
oc_font_get_glyph_metrics_from_font_data(fontData, (oc_str32){.ptr = &missingGlyphIndex , .len = 1}, &missingGlyphMetrics);
}
else
{

View File

@ -72,8 +72,8 @@ void oc_wasm_list_push_back(oc_wasm_list* list, oc_wasm_list_elt* elt);
typedef struct oc_wasm_str8
{
u64 len;
u32 ptr;
u32 len; //NOTE: size_t is 4 bytes on wasm32
} oc_wasm_str8;
typedef struct oc_wasm_str8_elt

View File

@ -111,7 +111,8 @@ inline T oc_cube(T a)
#define oc_tga_variants(def, ...) \
def(u8, ##__VA_ARGS__) def(i8, ##__VA_ARGS__) def(u16, ##__VA_ARGS__) def(i16, ##__VA_ARGS__) \
def(u32, ##__VA_ARGS__) def(i32, ##__VA_ARGS__) def(u64, ##__VA_ARGS__) def(i64, ##__VA_ARGS__) \
def(f32, ##__VA_ARGS__) def(f64, ##__VA_ARGS__)
def(size_t, ##__VA_ARGS__) \
def(f32, ##__VA_ARGS__) def(f64, ##__VA_ARGS__)
// This macro generates one _Generic association between a type and its variant
#define oc_tga_association(type, name) , type : OC_CAT3(name, _, type)

View File

@ -14,13 +14,13 @@
oc_str8 oc_str8_from_buffer(u64 len, char* buffer)
{
return ((oc_str8){ .len = len, .ptr = buffer });
return ((oc_str8){.ptr = buffer , .len = len});
}
oc_str8 oc_str8_slice(oc_str8 s, u64 start, u64 end)
{
OC_ASSERT(start <= end && start <= s.len && end <= s.len);
return ((oc_str8){ .len = end - start, .ptr = s.ptr + start });
return ((oc_str8){.ptr = s.ptr + start , .len = end - start});
}
oc_str8 oc_str8_push_buffer(oc_arena* arena, u64 len, char* buffer)
@ -158,7 +158,7 @@ oc_str8 oc_str8_list_collate(oc_arena* arena, oc_str8_list list, oc_str8 prefix,
oc_str8 oc_str8_list_join(oc_arena* arena, oc_str8_list list)
{
oc_str8 empty = { .len = 0, .ptr = 0 };
oc_str8 empty = {.ptr = 0 , .len = 0};
return (oc_str8_list_collate(arena, list, empty, empty, empty));
}
@ -221,13 +221,13 @@ oc_str8_list oc_str8_split(oc_arena* arena, oc_str8 str, oc_str8_list separators
//----------------------------------------------------------------------------------
oc_str16 oc_str16_from_buffer(u64 len, u16* buffer)
{
return ((oc_str16){ .len = len, .ptr = buffer });
return ((oc_str16){.ptr = buffer , .len = len});
}
oc_str16 oc_str16_slice(oc_str16 s, u64 start, u64 end)
{
OC_ASSERT(start <= end && start <= s.len && end <= s.len);
return ((oc_str16){ .len = end - start, .ptr = s.ptr + start });
return ((oc_str16){.ptr = s.ptr + start , .len = end - start});
}
oc_str16 oc_str16_push_buffer(oc_arena* arena, u64 len, u16* buffer)
@ -298,7 +298,7 @@ oc_str16 oc_str16_list_collate(oc_arena* arena, oc_str16_list list, oc_str16 pre
oc_str16 oc_str16_list_join(oc_arena* arena, oc_str16_list list)
{
oc_str16 empty = { .len = 0, .ptr = 0 };
oc_str16 empty = {.ptr = 0 , .len = 0};
return (oc_str16_list_collate(arena, list, empty, empty, empty));
}
@ -307,13 +307,13 @@ oc_str16 oc_str16_list_join(oc_arena* arena, oc_str16_list list)
//----------------------------------------------------------------------------------
oc_str32 oc_str32_from_buffer(u64 len, u32* buffer)
{
return ((oc_str32){ .len = len, .ptr = buffer });
return ((oc_str32){.ptr = buffer , .len = len});
}
oc_str32 oc_str32_slice(oc_str32 s, u64 start, u64 end)
{
OC_ASSERT(start <= end && start <= s.len && end <= s.len);
return ((oc_str32){ .len = end - start, .ptr = s.ptr + start });
return ((oc_str32){.ptr = s.ptr + start , .len = end - start});
}
oc_str32 oc_str32_push_buffer(oc_arena* arena, u64 len, u32* buffer)
@ -384,6 +384,6 @@ oc_str32 oc_str32_list_collate(oc_arena* arena, oc_str32_list list, oc_str32 pre
oc_str32 oc_str32_list_join(oc_arena* arena, oc_str32_list list)
{
oc_str32 empty = { .len = 0, .ptr = 0 };
oc_str32 empty = {.ptr = 0 , .len = 0};
return (oc_str32_list_collate(arena, list, empty, empty, empty));
}

View File

@ -34,16 +34,16 @@ extern "C" {
//----------------------------------------------------------------------------------
typedef struct oc_str8
{
u64 len;
char* ptr;
size_t len;
} oc_str8;
#define OC_STR8(s) ((oc_str8){ .len = (s) ? strlen(s) : 0, .ptr = (char*)s })
#define OC_STR8(s) ((oc_str8){.ptr = (char*)s , .len = (s) ? strlen(s) : 0})
//NOTE: this only works with string literals, but is sometimes necessary to generate compile-time constants
#define OC_STR8_LIT(s) \
{ \
sizeof(s) - 1, s \
s, sizeof(s) - 1 \
}
#define oc_str8_lp(s) ((s).len), ((s).ptr)
@ -92,8 +92,8 @@ ORCA_API oc_str8_list oc_str8_split(oc_arena* arena, oc_str8 str, oc_str8_list s
//----------------------------------------------------------------------------------
typedef struct oc_str16
{
u64 len;
u16* ptr;
size_t len;
} oc_str16;
ORCA_API oc_str16 oc_str16_from_buffer(u64 len, u16* buffer);
@ -125,8 +125,8 @@ ORCA_API oc_str16_list oc_str16_split(oc_arena* arena, oc_str16 str, oc_str16_li
//----------------------------------------------------------------------------------
typedef struct oc_str32
{
u64 len;
u32* ptr;
size_t len;
} oc_str32;
ORCA_API oc_str32 oc_str32_from_buffer(u64 len, u32* buffer);

View File

@ -225,7 +225,7 @@ oc_str8 oc_utf8_encode(char* dest, oc_utf32 codePoint)
dest[3] = (codePoint & 0x3F) | 0x80;
sz = 4;
}
oc_str8 res = { .len = sz, .ptr = dest };
oc_str8 res = {.ptr = dest , .len = sz};
return (res);
}
@ -239,7 +239,7 @@ oc_str32 oc_utf8_to_codepoints(u64 maxCount, oc_utf32* backing, oc_str8 string)
backing[codePointIndex] = decode.codepoint;
byteOffset += decode.size;
}
oc_str32 res = { .len = codePointIndex, .ptr = backing };
oc_str32 res = {.ptr = backing , .len = codePointIndex};
return (res);
}
@ -257,7 +257,7 @@ oc_str8 oc_utf8_from_codepoints(u64 maxBytes, char* backing, oc_str32 codePoints
oc_utf8_encode(backing + byteOffset, codePoint);
byteOffset += byteCount;
}
oc_str8 res = { .len = byteOffset, .ptr = backing };
oc_str8 res = {.ptr = backing , .len = byteOffset};
return (res);
}