mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-13 07:52:22 -07:00
c11.refactor (base should be mapped)
This commit is contained in:
@@ -82,7 +82,7 @@ cmd_line_insert_opt_alloc(AllocatorInfo ainfo, CmdLine* cmd_line, String8 string
|
||||
var = alloc_array(ainfo, CmdLineOpt, 1);
|
||||
var->hash_next = *slot;
|
||||
var->hash = cmd_line_hash_from_string(string);
|
||||
var->string = str8_copy(ainfo, string);
|
||||
var->string = alloc_str8_copy(ainfo, string);
|
||||
var->value_strings = values;
|
||||
|
||||
StringJoin join = {0};
|
||||
|
||||
+1
-1
@@ -8,6 +8,6 @@
|
||||
|
||||
void
|
||||
set_thread_name(String8 string) {
|
||||
ProfThreadName("%.*s", str8_varg(string));
|
||||
prof_thread_name("%.*s", str8_varg(string));
|
||||
os_set_thread_name(string);
|
||||
}
|
||||
|
||||
+55
-106
@@ -4,73 +4,20 @@
|
||||
# include "debug.h"
|
||||
# include "strings.h"
|
||||
# include "thread_context.h"
|
||||
////////////////////////////////
|
||||
//~ rjf: Third Party Includes
|
||||
#if !BUILD_SUPPLEMENTARY_UNIT
|
||||
# define STB_SPRINTF_IMPLEMENTATION
|
||||
# define STB_SPRINTF_STATIC
|
||||
# include "third_party/stb/stb_sprintf.h"
|
||||
// Note(Ed): We should inject when generating the library segmented or singleheader
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Third Party Includes
|
||||
|
||||
// #if !BUILD_SUPPLEMENTARY_UNIT
|
||||
// # define STB_SPRINTF_IMPLEMENTATION
|
||||
// # define STB_SPRINTF_STATIC
|
||||
// # include "third_party/stb/stb_sprintf.h"
|
||||
// #endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ NOTE(allen): String <-> Integer Tables
|
||||
|
||||
MD_API_C read_only global U8 integer_symbols[16] = {
|
||||
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',
|
||||
};
|
||||
|
||||
// NOTE(allen): Includes reverses for uppercase and lowercase hex.
|
||||
MD_API_C read_only global U8 integer_symbol_reverse[128] = {
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
};
|
||||
|
||||
MD_API_C read_only global U8 base64[64] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'_', '$',
|
||||
};
|
||||
|
||||
MD_API_C read_only global U8 base64_reverse[128] = {
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
|
||||
0xFF,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,
|
||||
0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0xFF,0xFF,0xFF,0xFF,0x3E,
|
||||
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,
|
||||
0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Character Classification & Conversion Functions
|
||||
|
||||
B32 char_is_digit(U8 c, U32 base) {
|
||||
B32 result = 0;
|
||||
if (0 < base && base <= 16) {
|
||||
U8 val = integer_symbol_reverse[c];
|
||||
if (val < base) {
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String Matching
|
||||
|
||||
@@ -140,6 +87,20 @@ str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags
|
||||
return(result);
|
||||
}
|
||||
|
||||
U64
|
||||
str8_find_needle_reverse(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags) {
|
||||
U64 result = 0;
|
||||
for (S64 i = string.size - start_pos - needle.size; i >= 0; --i)
|
||||
{
|
||||
String8 haystack = str8_substr(string, rng_1u64(i, i + needle.size));
|
||||
if (str8_match(haystack, needle, flags)) {
|
||||
result = (U64)i + needle.size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String Slicing
|
||||
|
||||
@@ -174,7 +135,7 @@ push_str8_cat(Arena* arena, String8 s1, String8 s2)
|
||||
str.str[str.size] = 0;
|
||||
return(str);
|
||||
#else
|
||||
return str8_cat(arena_allocator(arena), s1, s2);
|
||||
return alloc_str8_cat(arena_allocator(arena), s1, s2);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -188,7 +149,7 @@ push_str8_copy(Arena* arena, String8 s){
|
||||
str.str[str.size] = 0;
|
||||
return(str);
|
||||
#else
|
||||
return str8_copy(arena_allocator(arena), s);
|
||||
return alloc_str8_copy(arena_allocator(arena), s);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -205,12 +166,12 @@ push_str8fv(Arena* arena, char* fmt, va_list args){
|
||||
va_end(args2);
|
||||
return(result);
|
||||
#else
|
||||
return str8fv(arena_allocator(arena), fmt, args);
|
||||
return alloc_str8fv(arena_allocator(arena), fmt, args);
|
||||
#endif
|
||||
}
|
||||
|
||||
String8
|
||||
str8_cat(AllocatorInfo ainfo, String8 s1, String8 s2)
|
||||
alloc_str8_cat(AllocatorInfo ainfo, String8 s1, String8 s2)
|
||||
{
|
||||
String8 str;
|
||||
str.size = s1.size + s2.size;
|
||||
@@ -222,7 +183,7 @@ str8_cat(AllocatorInfo ainfo, String8 s1, String8 s2)
|
||||
}
|
||||
|
||||
String8
|
||||
str8_copy(AllocatorInfo ainfo, String8 s)
|
||||
alloc_str8_copy(AllocatorInfo ainfo, String8 s)
|
||||
{
|
||||
String8 str;
|
||||
str.size = s.size;
|
||||
@@ -233,7 +194,7 @@ str8_copy(AllocatorInfo ainfo, String8 s)
|
||||
}
|
||||
|
||||
String8
|
||||
str8fv(AllocatorInfo ainfo, char *fmt, va_list args){
|
||||
alloc_str8fv(AllocatorInfo ainfo, char *fmt, va_list args){
|
||||
va_list args2;
|
||||
va_copy(args2, args);
|
||||
U32 needed_bytes = md_vsnprintf(0, 0, fmt, args) + 1;
|
||||
@@ -278,7 +239,7 @@ str8_is_integer(String8 string, U32 radix){
|
||||
result = 1;
|
||||
for (U64 i = 0; i < string.size; i += 1) {
|
||||
U8 c = string.str[i];
|
||||
if ( ! (c < 0x80) || integer_symbol_reverse[c] >= radix){
|
||||
if ( ! (c < 0x80) || integer_symbol_reverse(c) >= radix){
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
@@ -287,18 +248,6 @@ str8_is_integer(String8 string, U32 radix){
|
||||
return(result);
|
||||
}
|
||||
|
||||
U64
|
||||
u64_from_str8(String8 string, U32 radix) {
|
||||
U64 x = 0;
|
||||
if (1 < radix && radix <= 16) {
|
||||
for (U64 i = 0; i < string.size; i += 1) {
|
||||
x *= radix;
|
||||
x += integer_symbol_reverse[string.str[i]&0x7F];
|
||||
}
|
||||
}
|
||||
return(x);
|
||||
}
|
||||
|
||||
B32
|
||||
try_u64_from_str8_c_rules(String8 string, U64 *x)
|
||||
{
|
||||
@@ -364,16 +313,16 @@ String8
|
||||
str8_from_allocator_size(AllocatorInfo ainfo, U64 z) {
|
||||
String8 result = {0};
|
||||
if (z < KB(1)) {
|
||||
result = str8f(ainfo, "%llu b", z);
|
||||
result = alloc_str8f(ainfo, "%llu b", z);
|
||||
}
|
||||
else if (z < MB(1)) {
|
||||
result = str8f(ainfo, "%llu.%02llu Kb", z/KB(1), ((100*z)/KB(1))%100);
|
||||
result = alloc_str8f(ainfo, "%llu.%02llu Kb", z/KB(1), ((100*z)/KB(1))%100);
|
||||
}
|
||||
else if (z < GB(1)) {
|
||||
result = str8f(ainfo, "%llu.%02llu Mb", z/MB(1), ((100*z)/MB(1))%100);
|
||||
result = alloc_str8f(ainfo, "%llu.%02llu Mb", z/MB(1), ((100*z)/MB(1))%100);
|
||||
}
|
||||
else{
|
||||
result = str8f(ainfo, "%llu.%02llu Gb", z/GB(1), ((100*z)/GB(1))%100);
|
||||
result = alloc_str8f(ainfo, "%llu.%02llu Gb", z/GB(1), ((100*z)/GB(1))%100);
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
@@ -423,8 +372,8 @@ str8_from_u64(Arena* arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_se
|
||||
U64 needed_separators = 0;
|
||||
if (digit_group_separator != 0)
|
||||
{
|
||||
needed_separators = (needed_digits+needed_leading_0s)/digit_group_size;
|
||||
if(needed_separators > 0 && (needed_digits+needed_leading_0s)%digit_group_size == 0)
|
||||
needed_separators = (needed_digits + needed_leading_0s) / digit_group_size;
|
||||
if(needed_separators > 0 && (needed_digits + needed_leading_0s) % digit_group_size == 0)
|
||||
{
|
||||
needed_separators -= 1;
|
||||
}
|
||||
@@ -442,10 +391,10 @@ str8_from_u64(Arena* arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_se
|
||||
{
|
||||
if(digits_until_separator == 0 && digit_group_separator != 0) {
|
||||
result.str[result.size - idx - 1] = digit_group_separator;
|
||||
digits_until_separator = digit_group_size+1;
|
||||
digits_until_separator = digit_group_size + 1;
|
||||
}
|
||||
else {
|
||||
result.str[result.size - idx - 1] = char_to_lower(integer_symbols[u64_reduce%radix]);
|
||||
result.str[result.size - idx - 1] = char_to_lower(integer_symbols(u64_reduce % radix));
|
||||
u64_reduce /= radix;
|
||||
}
|
||||
digits_until_separator -= 1;
|
||||
@@ -515,8 +464,8 @@ str8_from_allocator_u64(AllocatorInfo ainfo, U64 u64, U32 radix, U8 min_digits,
|
||||
U64 needed_separators = 0;
|
||||
if (digit_group_separator != 0)
|
||||
{
|
||||
needed_separators = (needed_digits+needed_leading_0s)/digit_group_size;
|
||||
if(needed_separators > 0 && (needed_digits+needed_leading_0s)%digit_group_size == 0)
|
||||
needed_separators = (needed_digits + needed_leading_0s) / digit_group_size;
|
||||
if(needed_separators > 0 && (needed_digits + needed_leading_0s) % digit_group_size == 0)
|
||||
{
|
||||
needed_separators -= 1;
|
||||
}
|
||||
@@ -534,10 +483,10 @@ str8_from_allocator_u64(AllocatorInfo ainfo, U64 u64, U32 radix, U8 min_digits,
|
||||
{
|
||||
if(digits_until_separator == 0 && digit_group_separator != 0) {
|
||||
result.str[result.size - idx - 1] = digit_group_separator;
|
||||
digits_until_separator = digit_group_size+1;
|
||||
digits_until_separator = digit_group_size + 1;
|
||||
}
|
||||
else {
|
||||
result.str[result.size - idx - 1] = char_to_lower(integer_symbols[u64_reduce%radix]);
|
||||
result.str[result.size - idx - 1] = char_to_lower(integer_symbols(u64_reduce % radix));
|
||||
u64_reduce /= radix;
|
||||
}
|
||||
digits_until_separator -= 1;
|
||||
@@ -588,12 +537,12 @@ str8_from_alloctor_s64(AllocatorInfo ainfo, S64 s64, U32 radix, U8 min_digits, U
|
||||
if(s64 < 0) {
|
||||
// TODO(Ed): Review, we should just keep using thread scratch arenas (and provide them to teh context)
|
||||
U8 bytes[KB(8)];
|
||||
FArena scratch = farena_from_memory(bytes, size_of(bytes));
|
||||
FArena scratch = farena_from_memory(bytes, size_of(bytes));
|
||||
String8 numeric_part = str8_from_allocator_u64(farena_allocator(scratch), (U64)(-s64), radix, min_digits, digit_group_separator);
|
||||
result = str8f(ainfo, "-%S", numeric_part);
|
||||
result = alloc_str8f(ainfo, "-%S", numeric_part);
|
||||
}
|
||||
else {
|
||||
result = str8__from_allocator_u64(ainfo, (U64)s64, radix, min_digits, digit_group_separator);
|
||||
result = str8_from_allocator_u64(ainfo, (U64)s64, radix, min_digits, digit_group_separator);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -743,7 +692,7 @@ str8_list_alloc_copy(AllocatorInfo ainfo, String8List* list) {
|
||||
String8List result = {0};
|
||||
for (String8Node* node = list->first; node != 0; node = node->next) {
|
||||
String8Node* new_node = alloc_array_no_zero(ainfo, String8Node, 1);
|
||||
String8 new_string = str8_copy(ainfo, node->string);
|
||||
String8 new_string = alloc_str8_copy(ainfo, node->string);
|
||||
str8_list_push_node_set_string(&result, new_node, new_string);
|
||||
}
|
||||
return(result);
|
||||
@@ -1313,7 +1262,7 @@ str8_from_16(AllocatorInfo ainfo, String16 in) {
|
||||
size += utf8_encode(str + size, consume.codepoint);
|
||||
}
|
||||
str[size] = 0;
|
||||
resize(ainfo, str, (cap - size));
|
||||
resize(ainfo, str, cap + 1, (cap - size));
|
||||
return(str8(str, size));
|
||||
}
|
||||
|
||||
@@ -1330,7 +1279,7 @@ str16_from_8(AllocatorInfo ainfo, String8 in) {
|
||||
size += utf16_encode(str + size, consume.codepoint);
|
||||
}
|
||||
str[size] = 0;
|
||||
resize(ainfo, str, (cap - size));
|
||||
resize(ainfo, str, cap + 1, (cap - size));
|
||||
return(str16(str, size));
|
||||
}
|
||||
|
||||
@@ -1345,7 +1294,7 @@ str8_from_32(AllocatorInfo ainfo, String32 in){
|
||||
size += utf8_encode(str + size, *ptr);
|
||||
}
|
||||
str[size] = 0;
|
||||
resize(ainfo, str, (cap - size));
|
||||
resize(ainfo, str, cap + 1, (cap - size));
|
||||
return(str8(str, size));
|
||||
}
|
||||
|
||||
@@ -1363,7 +1312,7 @@ str32_from_8(AllocatorInfo ainfo, String8 in){
|
||||
size += 1;
|
||||
}
|
||||
str[size] = 0;
|
||||
resize(ainfo, str, (cap - size));
|
||||
resize(ainfo, str, cap + 1, (cap - size));
|
||||
return(str32(str, size));
|
||||
}
|
||||
|
||||
@@ -1481,7 +1430,7 @@ alloc_date_time_string(AllocatorInfo ainfo, DateTime* date_time) {
|
||||
ampm = "pm";
|
||||
}
|
||||
|
||||
String8 result = str8f(ainfo,
|
||||
String8 result = alloc_str8f(ainfo,
|
||||
"%d %s %d, %02d:%02d:%02d %s",
|
||||
date_time->day, mon_str, date_time->year,
|
||||
adjusted_hour, date_time->min, date_time->sec, ampm
|
||||
@@ -1493,7 +1442,7 @@ String8
|
||||
alloc_file_name_date_time_string(AllocatorInfo ainfo, DateTime* date_time) {
|
||||
char* mon_str = (char*)string_from_month(date_time->month).str;
|
||||
|
||||
String8 result = str8f(ainfo,
|
||||
String8 result = alloc_str8f(ainfo,
|
||||
"%d-%s-%0d--%02d-%02d-%02d",
|
||||
date_time->year, mon_str, date_time->day,
|
||||
date_time->hour, date_time->min, date_time->sec
|
||||
@@ -1976,7 +1925,7 @@ wrapped_lines_from_string_alloc(AllocatorInfo ainfo, String8 string, U64 first_l
|
||||
{
|
||||
String8 line = str8_substr(string, line_range);
|
||||
if (wrapped_indent_level > 0){
|
||||
line = str8f(ainfo, "%.*s%S", wrapped_indent_level, spaces, line);
|
||||
line = alloc_str8f(ainfo, "%.*s%S", wrapped_indent_level, spaces, line);
|
||||
}
|
||||
str8_list_alloc(ainfo, &list, line);
|
||||
line_range = r1u64(line_range.max + 1, candidate_line_range.max);
|
||||
@@ -1990,7 +1939,7 @@ wrapped_lines_from_string_alloc(AllocatorInfo ainfo, String8 string, U64 first_l
|
||||
if (line_range.min < string.size && line_range.max > line_range.min) {
|
||||
String8 line = str8_substr(string, line_range);
|
||||
if (wrapped_indent_level > 0) {
|
||||
line = str8f(ainfo, "%.*s%S", wrapped_indent_level, spaces, line);
|
||||
line = alloc_str8f(ainfo, "%.*s%S", wrapped_indent_level, spaces, line);
|
||||
}
|
||||
str8_list_alloc(ainfo, &list, line);
|
||||
}
|
||||
@@ -2197,7 +2146,7 @@ str8_serial_push_size(Arena* arena, String8List* srl, U64 size) {
|
||||
}
|
||||
return result;
|
||||
#else
|
||||
return str8_serial_alloc_size(arena_allocator(arena, srl, size));
|
||||
return str8_serial_alloc_size(arena_allocator(arena), srl, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
+233
-69
@@ -11,17 +11,16 @@
|
||||
# include "math.h"
|
||||
# include "toolchain.h"
|
||||
# include "time.h"
|
||||
////////////////////////////////
|
||||
//~ rjf: Third Party Includes
|
||||
# define STB_SPRINTF_DECORATE(name) md_##name
|
||||
# include "third_party/stb/stb_sprintf.h"
|
||||
// Note(Ed): We should inject when generating the library segmented or singleheader
|
||||
#endif
|
||||
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Third Party Includes
|
||||
|
||||
#define STB_SPRINTF_DECORATE(name) md_##name
|
||||
#include "third_party/stb/stb_sprintf.h"
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String Types
|
||||
|
||||
@@ -150,6 +149,65 @@ struct FuzzyMatchRangeList
|
||||
U64 total_dim;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ NOTE(allen): String <-> Integer Tables
|
||||
|
||||
inline U8
|
||||
integer_symbols(U8 value) {
|
||||
read_only local_persist thread_local
|
||||
U8 lookup_table[16] = {
|
||||
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',
|
||||
};
|
||||
return lookup_table[value];
|
||||
}
|
||||
|
||||
inline U8
|
||||
base64(U8 value) {
|
||||
read_only local_persist thread_local
|
||||
U8 lookup_table[64] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'_', '$',
|
||||
};
|
||||
return lookup_table[value];
|
||||
}
|
||||
|
||||
inline U8
|
||||
base64_reverse(U8 value) {
|
||||
read_only local_persist thread_local
|
||||
U8 lookup_table[128] = {
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
|
||||
0xFF,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,
|
||||
0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0xFF,0xFF,0xFF,0xFF,0x3E,
|
||||
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,
|
||||
0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
};
|
||||
return lookup_table[value];
|
||||
}
|
||||
|
||||
// NOTE(allen): Includes reverses for uppercase and lowercase hex.
|
||||
inline U8
|
||||
integer_symbol_reverse(U8 value) {
|
||||
read_only local_persist thread_local
|
||||
lookup_table[128] = {
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
};
|
||||
return lookup_table[value];
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Character Classification & Conversion Functions
|
||||
|
||||
@@ -162,7 +220,17 @@ inline U8 char_to_lower (U8 c) { if (char_is_upper(c)) { c += ('a' - 'A'
|
||||
inline U8 char_to_upper (U8 c) { if (char_is_lower(c)) { c += ('A' - 'a'); } return(c); }
|
||||
inline U8 char_to_correct_slash(U8 c) { if (char_is_slash(c)) { c = '/'; } return(c); }
|
||||
|
||||
B32 char_is_digit(U8 c, U32 base);
|
||||
inline B32
|
||||
char_is_digit(U8 c, U32 base) {
|
||||
B32 result = 0;
|
||||
if (0 < base && base <= 16) {
|
||||
U8 val = integer_symbol_reverse(c);
|
||||
if (val < base) {
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: C-String Measurement
|
||||
@@ -171,6 +239,8 @@ inline U64 cstring8_length (U8* c) { U8* p = c; for (; *p != 0; p += 1); retur
|
||||
inline U64 cstring16_length(U16* c) { U16* p = c; for (; *p != 0; p += 1); return(p - c); }
|
||||
inline U64 cstring32_length(U32 *c) { U32* p = c; for (; *p != 0; p += 1); return(p - c); }
|
||||
|
||||
#define cstring_length(c) _Generic(c, U8: cstring8_length, U16: cstring16_length, U32: cstring32_length)(c)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String Constructors
|
||||
|
||||
@@ -195,18 +265,49 @@ inline String8 str8_cstring (char* c) { String8 result
|
||||
inline String16 str16_cstring(U16* c) { String16 result = {(U16*)c, cstring16_length((U16*)c)}; return(result); }
|
||||
inline String32 str32_cstring(U32* c) { String32 result = {(U32*)c, cstring32_length((U32*)c)}; return(result); }
|
||||
|
||||
// TODO(Ed): review these
|
||||
internal String16 str16_cstring_capped(void *cstr, void *cap);
|
||||
internal String8 str8_cstring_capped_reverse(void *raw_start, void *raw_cap);
|
||||
#define str_range(str, one_past_last) _Generic(str, U8: str8_range, U16: str16_range, U32: str32_range )(str, one_past_last)
|
||||
#define str_cstring(c) _Generic(c, U8: str8_cstring, U16: str16_cstring, U32: str32_cstring)(c)
|
||||
|
||||
String8 str8_cstring_capped (void* cstr, void* cap);
|
||||
String16 str16_cstring_capped (void* cstr, void* cap);
|
||||
String8 str8_cstring_capped_reverse(void* raw_start, void* raw_cap);
|
||||
|
||||
inline String8
|
||||
str8_cstring_capped(void *cstr, void *cap) {
|
||||
char *ptr = (char*)cstr;
|
||||
char *opl = (char*)cap;
|
||||
for (;ptr < opl && *ptr != 0; ptr += 1);
|
||||
U64 size = (U64)(ptr - (char *)cstr);
|
||||
String8 result = {(U8*)cstr, size};
|
||||
return(result);
|
||||
str8_cstring_capped(void* cstr, void* cap) {
|
||||
char* ptr = (char*)cstr;
|
||||
char* opl = (char*)cap;
|
||||
for (;ptr < opl && *ptr != 0; ptr += 1);
|
||||
U64 size = (U64)(ptr - (char *)cstr);
|
||||
String8 result = {(U8*)cstr, size};
|
||||
return result;
|
||||
}
|
||||
|
||||
inline String16
|
||||
str16_cstring_capped(void* cstr, void* cap)
|
||||
{
|
||||
U16* ptr = (U16*)cstr;
|
||||
U16* opl = (U16*)cap;
|
||||
for (;ptr < opl && *ptr != 0; ptr += 1);
|
||||
U64 size = (U64)(ptr - (U16 *)cstr);
|
||||
String16 result = str16(cstr, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline String8
|
||||
str8_cstring_capped_reverse(void* raw_start, void* raw_cap)
|
||||
{
|
||||
U8* start = raw_start;
|
||||
U8* ptr = raw_cap;
|
||||
for (; ptr > start; )
|
||||
{
|
||||
ptr -= 1;
|
||||
if (*ptr == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
U64 size = (U64)(ptr - start);
|
||||
String8 result = str8(start, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -216,9 +317,9 @@ inline String8 upper_from_str8 (Arena* arena, String8 string) { string = pu
|
||||
inline String8 lower_from_str8 (Arena* arena, String8 string) { string = push_str8_copy(arena, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_lower(string.str[idx]); } return string; }
|
||||
inline String8 backslashed_from_str8(Arena *arena, String8 string) { string = push_str8_copy(arena, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_is_slash(string.str[idx]) ? '\\' : string.str[idx]; } return string; }
|
||||
|
||||
inline String8 upper_from_str8_alloc (AllocatorInfo ainfo, String8 string) { string = str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_upper(string.str[idx]); } return string; }
|
||||
inline String8 lower_from_str8_alloc (AllocatorInfo ainfo, String8 string) { string = str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_lower(string.str[idx]); } return string; }
|
||||
inline String8 backslashed_from_str8_alloc(AllocatorInfo ainfo, String8 string) { string = str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_is_slash(string.str[idx]) ? '\\' : string.str[idx]; } return string; }
|
||||
inline String8 upper_from_str8_alloc (AllocatorInfo ainfo, String8 string) { string = alloc_str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_upper(string.str[idx]); } return string; }
|
||||
inline String8 lower_from_str8_alloc (AllocatorInfo ainfo, String8 string) { string = alloc_str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_lower(string.str[idx]); } return string; }
|
||||
inline String8 backslashed_from_str8_alloc(AllocatorInfo ainfo, String8 string) { string = alloc_str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_is_slash(string.str[idx]) ? '\\' : string.str[idx]; } return string; }
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String Matching
|
||||
@@ -227,17 +328,16 @@ inline String8 backslashed_from_str8_alloc(AllocatorInfo ainfo, String8 string)
|
||||
#define str8_match_cstr(a_cstr, b, flags) str8_match(str8_cstring(a_cstr), (b), (flags))
|
||||
#define str8_ends_with_lit(string, end_lit, flags) str8_ends_with((string), str8_lit(end_lit), (flags))
|
||||
|
||||
MD_API B32 str8_match (String8 a, String8 b, StringMatchFlags flags);
|
||||
MD_API U64 str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
|
||||
B32 str8_ends_with (String8 string, String8 end, StringMatchFlags flags);
|
||||
|
||||
internal U64 str8_find_needle_reverse(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
|
||||
MD_API B32 str8_match (String8 a, String8 b, StringMatchFlags flags);
|
||||
MD_API U64 str8_find_needle (String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
|
||||
MD_API U64 str8_find_needle_reverse(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
|
||||
B32 str8_ends_with (String8 string, String8 end, StringMatchFlags flags);
|
||||
|
||||
inline B32
|
||||
str8_ends_with(String8 string, String8 end, StringMatchFlags flags) {
|
||||
String8 postfix = str8_postfix(string, end.size);
|
||||
B32 is_match = str8_match(end, postfix, flags);
|
||||
return is_match;
|
||||
String8 postfix = str8_postfix(string, end.size);
|
||||
B32 is_match = str8_match(end, postfix, flags);
|
||||
return is_match;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -253,40 +353,40 @@ String8 str8_chop (String8 str, U64 amt);
|
||||
|
||||
inline String8
|
||||
str8_substr(String8 str, Rng1U64 range){
|
||||
range.min = clamp_top(range.min, str.size);
|
||||
range.max = clamp_top(range.max, str.size);
|
||||
str.str += range.min;
|
||||
str.size = dim_1u64(range);
|
||||
return(str);
|
||||
range.min = clamp_top(range.min, str.size);
|
||||
range.max = clamp_top(range.max, str.size);
|
||||
str.str += range.min;
|
||||
str.size = dim_1u64(range);
|
||||
return(str);
|
||||
}
|
||||
|
||||
inline String8
|
||||
str8_prefix(String8 str, U64 size){
|
||||
str.size = clamp_top(size, str.size);
|
||||
return(str);
|
||||
str.size = clamp_top(size, str.size);
|
||||
return(str);
|
||||
}
|
||||
|
||||
inline String8
|
||||
str8_skip(String8 str, U64 amt){
|
||||
amt = clamp_top(amt, str.size);
|
||||
str.str += amt;
|
||||
str.size -= amt;
|
||||
return(str);
|
||||
amt = clamp_top(amt, str.size);
|
||||
str.str += amt;
|
||||
str.size -= amt;
|
||||
return(str);
|
||||
}
|
||||
|
||||
inline String8
|
||||
str8_postfix(String8 str, U64 size){
|
||||
size = clamp_top(size, str.size);
|
||||
str.str = (str.str + str.size) - size;
|
||||
str.size = size;
|
||||
return(str);
|
||||
size = clamp_top(size, str.size);
|
||||
str.str = (str.str + str.size) - size;
|
||||
str.size = size;
|
||||
return(str);
|
||||
}
|
||||
|
||||
inline String8
|
||||
str8_chop(String8 str, U64 amt){
|
||||
amt = clamp_top(amt, str.size);
|
||||
str.size -= amt;
|
||||
return(str);
|
||||
amt = clamp_top(amt, str.size);
|
||||
str.size -= amt;
|
||||
return(str);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -297,10 +397,10 @@ MD_API String8 push_str8_copy(Arena* arena, String8 s);
|
||||
MD_API String8 push_str8fv (Arena* arena, char* fmt, va_list args);
|
||||
String8 push_str8f (Arena* arena, char* fmt, ...);
|
||||
|
||||
MD_API String8 str8_cat (AllocatorInfo ainfo, String8 s1, String8 s2);
|
||||
MD_API String8 str8_copy(AllocatorInfo ainfo, String8 s);
|
||||
MD_API String8 str8fv (AllocatorInfo ainfo, char* fmt, va_list args);
|
||||
String8 str8f (AllocatorInfo ainfo, char* fmt, ...);
|
||||
MD_API String8 alloc_str8_cat (AllocatorInfo ainfo, String8 s1, String8 s2);
|
||||
MD_API String8 alloc_str8_copy(AllocatorInfo ainfo, String8 s);
|
||||
MD_API String8 alloc_str8fv (AllocatorInfo ainfo, char* fmt, va_list args);
|
||||
String8 alloc_str8f (AllocatorInfo ainfo, char* fmt, ...);
|
||||
|
||||
inline String8
|
||||
push_str8f(Arena *arena, char *fmt, ...){
|
||||
@@ -312,10 +412,10 @@ push_str8f(Arena *arena, char *fmt, ...){
|
||||
}
|
||||
|
||||
inline String8
|
||||
str8f(AllocatorInfo ainfo, char *fmt, ...){
|
||||
alloc_str8f(AllocatorInfo ainfo, char *fmt, ...){
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
String8 result = str8fv(ainfo, fmt, args);
|
||||
String8 result = alloc_str8fv(ainfo, fmt, args);
|
||||
va_end(args);
|
||||
return(result);
|
||||
}
|
||||
@@ -324,26 +424,23 @@ str8f(AllocatorInfo ainfo, char *fmt, ...){
|
||||
//~ rjf: String <=> Integer Conversions
|
||||
|
||||
//- rjf: string -> integer
|
||||
MD_API S64 sign_from_str8 (String8 string, String8* string_tail);
|
||||
MD_API B32 str8_is_integer (String8 string, U32 radix);
|
||||
MD_API U64 u64_from_str8 (String8 string, U32 radix);
|
||||
S64 s64_from_str8 (String8 string, U32 radix);
|
||||
MD_API S64 sign_from_str8 (String8 string, String8* string_tail);
|
||||
MD_API B32 str8_is_integer(String8 string, U32 radix);
|
||||
U64 u64_from_str8 (String8 string, U32 radix);
|
||||
S64 s64_from_str8 (String8 string, U32 radix);
|
||||
U32 u32_from_str8 (String8 string, U32 radix);
|
||||
S32 s32_from_str8 (String8 string, U32 radix);
|
||||
|
||||
// TODO(Ed): review these
|
||||
internal U32 u32_from_str8(String8 string, U32 radix);
|
||||
internal S32 s32_from_str8(String8 string, U32 radix);
|
||||
|
||||
MD_API B32 try_u64_from_str8_c_rules(String8 string, U64* x);
|
||||
B32 try_s64_from_str8_c_rules(String8 string, S64* x);
|
||||
MD_API B32 try_u64_from_str8_c_rules(String8 string, U64* x);
|
||||
B32 try_s64_from_str8_c_rules(String8 string, S64* x);
|
||||
|
||||
//- rjf: integer -> string
|
||||
MD_API String8 str8_from_memory_size(Arena* arena, U64 z);
|
||||
MD_API String8 str8_from_u64 (Arena* arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator);
|
||||
MD_API String8 str8_from_s64 (Arena* arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator);
|
||||
|
||||
// TODO(Ed): review these
|
||||
internal String8 str8_from_bits_u32(Arena *arena, U32 x);
|
||||
internal String8 str8_from_bits_u64(Arena *arena, U64 x);
|
||||
String8 str8_from_bits_u32(Arena* arena, U32 x);
|
||||
String8 str8_from_bits_u64(Arena* arena, U64 x);
|
||||
|
||||
MD_API String8 str8_from_allocator_size(AllocatorInfo ainfo, U64 z);
|
||||
MD_API String8 str8_from_allocator_u64 (AllocatorInfo ainfo, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator);
|
||||
@@ -356,8 +453,34 @@ s64_from_str8(String8 string, U32 radix) {
|
||||
return(x);
|
||||
}
|
||||
|
||||
inline U64
|
||||
u64_from_str8(String8 string, U32 radix) {
|
||||
U64 x = 0;
|
||||
if (1 < radix && radix <= 16) {
|
||||
for (U64 i = 0; i < string.size; i += 1) {
|
||||
x *= radix;
|
||||
x += integer_symbol_reverse(string.str[i]&0x7F);
|
||||
}
|
||||
}
|
||||
return(x);
|
||||
}
|
||||
|
||||
inline U32
|
||||
u32_from_str8(String8 string, U32 radix) {
|
||||
U64 x64 = u64_from_str8(string, radix);
|
||||
U32 x32 = safe_cast_u32(x64);
|
||||
return x32;
|
||||
}
|
||||
|
||||
inline S32
|
||||
s32_from_str8(String8 string, U32 radix) {
|
||||
S64 x64 = s64_from_str8(string, radix);
|
||||
S32 x32 = safe_cast_s32(x64);
|
||||
return x32;
|
||||
}
|
||||
|
||||
inline B32
|
||||
try_s64_from_str8_c_rules(String8 string, S64 *x) {
|
||||
try_s64_from_str8_c_rules(String8 string, S64* x) {
|
||||
String8 string_tail = {0};
|
||||
S64 sign = sign_from_str8(string, &string_tail);
|
||||
U64 x_u64 = 0;
|
||||
@@ -366,6 +489,47 @@ try_s64_from_str8_c_rules(String8 string, S64 *x) {
|
||||
return(is_integer);
|
||||
}
|
||||
|
||||
inline String8
|
||||
str8_from_bits_u32(Arena* arena, U32 x)
|
||||
{
|
||||
U8 c0 = 'a' + ((x >> 28) & 0xf);
|
||||
U8 c1 = 'a' + ((x >> 24) & 0xf);
|
||||
U8 c2 = 'a' + ((x >> 20) & 0xf);
|
||||
U8 c3 = 'a' + ((x >> 16) & 0xf);
|
||||
U8 c4 = 'a' + ((x >> 12) & 0xf);
|
||||
U8 c5 = 'a' + ((x >> 8) & 0xf);
|
||||
U8 c6 = 'a' + ((x >> 4) & 0xf);
|
||||
U8 c7 = 'a' + ((x >> 0) & 0xf);
|
||||
String8 result = push_str8f(arena, "%c%c%c%c%c%c%c%c", c0, c1, c2, c3, c4, c5, c6, c7);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline String8
|
||||
str8_from_bits_u64(Arena* arena, U64 x)
|
||||
{
|
||||
U8 c0 = 'a' + ((x >> 60) & 0xf);
|
||||
U8 c1 = 'a' + ((x >> 56) & 0xf);
|
||||
U8 c2 = 'a' + ((x >> 52) & 0xf);
|
||||
U8 c3 = 'a' + ((x >> 48) & 0xf);
|
||||
U8 c4 = 'a' + ((x >> 44) & 0xf);
|
||||
U8 c5 = 'a' + ((x >> 40) & 0xf);
|
||||
U8 c6 = 'a' + ((x >> 36) & 0xf);
|
||||
U8 c7 = 'a' + ((x >> 32) & 0xf);
|
||||
U8 c8 = 'a' + ((x >> 28) & 0xf);
|
||||
U8 c9 = 'a' + ((x >> 24) & 0xf);
|
||||
U8 ca = 'a' + ((x >> 20) & 0xf);
|
||||
U8 cb = 'a' + ((x >> 16) & 0xf);
|
||||
U8 cc = 'a' + ((x >> 12) & 0xf);
|
||||
U8 cd = 'a' + ((x >> 8) & 0xf);
|
||||
U8 ce = 'a' + ((x >> 4) & 0xf);
|
||||
U8 cf = 'a' + ((x >> 0) & 0xf);
|
||||
String8 result = push_str8f(arena,
|
||||
"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
|
||||
c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, ca, cb, cc, cd, ce, cf
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String <=> Float Conversions
|
||||
|
||||
@@ -492,7 +656,7 @@ inline String8Node*
|
||||
str8_list_allocf(AllocatorInfo ainfo, String8List* list, char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
String8 string = str8fv(ainfo, fmt, args);
|
||||
String8 string = alloc_str8fv(ainfo, fmt, args);
|
||||
String8Node* result = str8_list_alloc(ainfo, list, string);
|
||||
va_end(args);
|
||||
return(result);
|
||||
@@ -502,7 +666,7 @@ inline String8Node*
|
||||
str8_list_alloc_frontf(AllocatorInfo ainfo, String8List* list, char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
String8 string = str8fv(ainfo, fmt, args);
|
||||
String8 string = alloc_str8fv(ainfo, fmt, args);
|
||||
String8Node* result = str8_list_alloc_front(ainfo, list, string);
|
||||
va_end(args);
|
||||
return(result);
|
||||
@@ -861,7 +1025,7 @@ MD_API String8List wrapped_lines_from_string_alloc(AllocatorInfo ainfo, String8
|
||||
//~ rjf: String <-> Color
|
||||
|
||||
inline String8 hex_string_from_rgba_4f32 (Arena* arena, Vec4F32 rgba) { String8 hex_string = push_str8f(arena, "%02x%02x%02x%02x", (U8)(rgba.x*255.f), (U8)(rgba.y*255.f), (U8)(rgba.z*255.f), (U8)(rgba.w*255.f)); return hex_string; }
|
||||
inline String8 hex_string_from_rgba_4f32_alloc(AllocatorInfo ainfo, Vec4F32 rgba) { String8 hex_string = str8f(ainfo, "%02x%02x%02x%02x", (U8)(rgba.x*255.f), (U8)(rgba.y*255.f), (U8)(rgba.z*255.f), (U8)(rgba.w*255.f)); return hex_string; }
|
||||
inline String8 hex_string_from_rgba_4f32_alloc(AllocatorInfo ainfo, Vec4F32 rgba) { String8 hex_string = alloc_str8f(ainfo, "%02x%02x%02x%02x", (U8)(rgba.x*255.f), (U8)(rgba.y*255.f), (U8)(rgba.z*255.f), (U8)(rgba.w*255.f)); return hex_string; }
|
||||
|
||||
MD_API Vec4F32 rgba_from_hex_string_4f32(String8 hex_string);
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ os_full_path_from_path_alloc(AllocatorInfo ainfo, String8 path)
|
||||
realpath((char *)path_copy.str, buffer);
|
||||
}
|
||||
scratch_end(scratch);
|
||||
String8 result = str8_copy(ainfo, str8_cstring(buffer));
|
||||
String8 result = alloc_str8_copy(ainfo, str8_cstring(buffer));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ os_get_current_path(Arena* arena) {
|
||||
inline String8
|
||||
os_get_current_path(AllocatorInfo ainfo) {
|
||||
char* cwdir = getcwd(0, 0);
|
||||
String8 string = str8_copy(ainfo, str8_cstring(cwdir));
|
||||
String8 string = alloc_str8_copy(ainfo, str8_cstring(cwdir));
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -315,7 +315,7 @@ os_string_from_guid(Arena* arena, OS_Guid guid) {
|
||||
|
||||
inline String8
|
||||
os_string_from_guid(AllocatorInfo ainfo, OS_Guid guid) {
|
||||
String8 result = str8f(ainfo,
|
||||
String8 result = alloc_str8f(ainfo,
|
||||
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
|
||||
guid.data1,
|
||||
guid.data2,
|
||||
|
||||
Reference in New Issue
Block a user