Update to .count for strings
This commit is contained in:
+663
-639
File diff suppressed because it is too large
Load Diff
+180
-164
@@ -1,4 +1,4 @@
|
||||
// Generated by the DN single header generator 2026-06-23 23:16:53
|
||||
// Generated by the DN single header generator 2026-06-25 21:37:26
|
||||
|
||||
#if !defined(DN_H)
|
||||
#define DN_H
|
||||
@@ -6,19 +6,12 @@
|
||||
// NOTE: DN
|
||||
|
||||
// NOTE: Getting Started
|
||||
// Include this mega header `dn.h` and define the following symbols to `1` to conditionally
|
||||
// enable the interfaces for those features. Additionally in the same or different translation
|
||||
// unit, include `dn.cpp` with the same symbols defined to enable the implementation of these
|
||||
// features.
|
||||
//
|
||||
// See the configuration section for more information on other symbols that can be defined.
|
||||
//
|
||||
// The following is a single translation unit example:
|
||||
// - Copy the entire DN folder to your project and include `dn.h` alongside your headers and
|
||||
// include `dn.cpp` in one of your implementation files that has `dn.h` included in its scope,
|
||||
// an example. There are #defines to selectively enable features of the library (see the
|
||||
// configuration section for more info), example:
|
||||
/*
|
||||
#define DN_WITH_OS 1
|
||||
#define DN_WITH_NET 0
|
||||
#define DN_WITH_NET_CURL 0
|
||||
#define DN_WITH_NET_EMSCRIPTEN 0
|
||||
#define DN_WITH_OS 1 // Enable OS features (like virtual mem, TLS, file system, threads)
|
||||
#include "dn.h"
|
||||
|
||||
#define DN_CPP_WITH_TESTS 1
|
||||
@@ -31,14 +24,8 @@
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
// - The base layer (dn_base.h) which provides primitives that do not require a host operating
|
||||
// system (e.g. freestanding) such as string manipulation, compiler intrinsics and containers.
|
||||
// This layer is unconditionallly always available by compiling with this library.
|
||||
//
|
||||
// - The OS layer (dn_os.h) which provides primitives that use the OS such as file IO, threading
|
||||
// synchronisation, memory allocation. This layer is OPTIONAL.
|
||||
//
|
||||
// - Extra layer provides helper utilities that are opt-in. These layers are OPTIONAL.
|
||||
// - `DN/Standalone` contains utilities that are self-contained and can be used without `dn.h` in
|
||||
// a similar manner, typically a single header and single implementation file.
|
||||
|
||||
// NOTE: Configuration
|
||||
|
||||
@@ -775,7 +762,7 @@ enum DN_ZMem
|
||||
struct DN_Str8
|
||||
{
|
||||
char *data; // The bytes of the string
|
||||
DN_USize size; // The number of bytes in the string
|
||||
DN_USize count; // The number of bytes in the string
|
||||
};
|
||||
|
||||
struct DN_Str8Slice
|
||||
@@ -784,18 +771,18 @@ struct DN_Str8Slice
|
||||
DN_USize count;
|
||||
};
|
||||
|
||||
struct DN_Str8x16 { char data[16]; DN_USize size; };
|
||||
struct DN_Str8x32 { char data[32]; DN_USize size; };
|
||||
struct DN_Str8x64 { char data[64]; DN_USize size; };
|
||||
struct DN_Str8x128 { char data[128]; DN_USize size; };
|
||||
struct DN_Str8x256 { char data[256]; DN_USize size; };
|
||||
struct DN_Str8x512 { char data[512]; DN_USize size; };
|
||||
struct DN_Str8x1024 { char data[1024]; DN_USize size; };
|
||||
struct DN_Str8x16 { char data[16]; DN_USize count; };
|
||||
struct DN_Str8x32 { char data[32]; DN_USize count; };
|
||||
struct DN_Str8x64 { char data[64]; DN_USize count; };
|
||||
struct DN_Str8x128 { char data[128]; DN_USize count; };
|
||||
struct DN_Str8x256 { char data[256]; DN_USize count; };
|
||||
struct DN_Str8x512 { char data[512]; DN_USize count; };
|
||||
struct DN_Str8x1024 { char data[1024]; DN_USize count; };
|
||||
|
||||
struct DN_Str16 // A pointer and length style string that holds slices to UTF16 bytes.
|
||||
{
|
||||
wchar_t *data; // The UTF16 bytes of the string
|
||||
DN_USize size; // The number of characters in the string
|
||||
DN_USize count; // The number of characters in the string
|
||||
};
|
||||
|
||||
struct DN_Str16Slice
|
||||
@@ -910,14 +897,14 @@ struct DN_TicketMutex
|
||||
};
|
||||
|
||||
|
||||
struct DN_Hex32 { char data[32 + 1]; DN_USize size; };
|
||||
struct DN_Hex64 { char data[64 + 1]; DN_USize size; };
|
||||
struct DN_Hex128 { char data[128 + 1]; DN_USize size; };
|
||||
struct DN_Hex32 { char data[32 + 1]; DN_USize count; };
|
||||
struct DN_Hex64 { char data[64 + 1]; DN_USize count; };
|
||||
struct DN_Hex128 { char data[128 + 1]; DN_USize count; };
|
||||
|
||||
struct DN_HexU64
|
||||
{
|
||||
char data[(sizeof(DN_U64) * 2) + 1 /*null-terminator*/];
|
||||
DN_U8 size;
|
||||
DN_U8 count;
|
||||
};
|
||||
|
||||
enum DN_HexFromU64Type
|
||||
@@ -1110,11 +1097,11 @@ enum DN_MemFuncsType
|
||||
DN_MemFuncsType_Virtual,
|
||||
};
|
||||
|
||||
typedef void *(DN_MemHeapAllocFunc)(DN_USize size);
|
||||
typedef void *(DN_MemHeapAllocFunc)(DN_USize count);
|
||||
typedef void (DN_MemHeapDeallocFunc)(void *ptr);
|
||||
typedef void *(DN_MemVirtualReserveFunc)(DN_USize size, DN_MemCommit commit, DN_MemPage page_flags);
|
||||
typedef bool (DN_MemVirtualCommitFunc)(void *ptr, DN_USize size, DN_U32 page_flags);
|
||||
typedef void (DN_MemVirtualReleaseFunc)(void *ptr, DN_USize size);
|
||||
typedef void *(DN_MemVirtualReserveFunc)(DN_USize count, DN_MemCommit commit, DN_MemPage page_flags);
|
||||
typedef bool (DN_MemVirtualCommitFunc)(void *ptr, DN_USize count, DN_U32 page_flags);
|
||||
typedef void (DN_MemVirtualReleaseFunc)(void *ptr, DN_USize count);
|
||||
struct DN_MemFuncs
|
||||
{
|
||||
DN_MemFuncsType type;
|
||||
@@ -1387,7 +1374,7 @@ struct DN_Str8TruncResult
|
||||
{
|
||||
bool truncated;
|
||||
DN_Str8 str8;
|
||||
DN_USize size_req; // Not including null-terminator
|
||||
DN_USize count_req; // Not including null-terminator
|
||||
};
|
||||
|
||||
struct DN_Str8SplitResult
|
||||
@@ -1669,7 +1656,7 @@ struct DN_LogDate
|
||||
|
||||
struct DN_LogPrefixSize
|
||||
{
|
||||
DN_USize size;
|
||||
DN_USize count;
|
||||
DN_USize padding;
|
||||
};
|
||||
|
||||
@@ -1832,7 +1819,7 @@ struct DN_ArrayEraseResult
|
||||
// The next index your for-index should be set to such that you can continue
|
||||
// to iterate the remainder of the array, e.g:
|
||||
//
|
||||
// for (DN_USize index = 0; index < array.size; index++) {
|
||||
// for (DN_USize index = 0; index < array.count; index++) {
|
||||
// if (erase)
|
||||
// index = DN_FArray_EraseRange(&array, index, -3, DN_ArrayErase_Unstable);
|
||||
// }
|
||||
@@ -2574,7 +2561,7 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback,
|
||||
{
|
||||
DN_Str8 str8 = va_arg(va, DN_Str8);
|
||||
s = (char *)str8.data;
|
||||
l = (uint32_t)str8.size;
|
||||
l = (uint32_t)str8.count;
|
||||
lead[0] = 0;
|
||||
tail[0] = 0;
|
||||
pr = 0;
|
||||
@@ -4224,9 +4211,9 @@ DN_API bool DN_VerifyArgs
|
||||
#define DN_VSPrintF(...) STB_SPRINTF_DECORATE(vsprintf)(__VA_ARGS__)
|
||||
#define DN_VSNPrintF(...) STB_SPRINTF_DECORATE(vsnprintf)(__VA_ARGS__)
|
||||
|
||||
DN_API bool DN_MemStartsWith (void const *lhs, DN_USize lhs_size, void const *rhs, DN_USize rhs_size);
|
||||
DN_API bool DN_MemEq (void const *lhs, DN_USize lhs_size, void const *rhs, DN_USize rhs_size);
|
||||
DN_API bool DN_MemEqUnsafe (void const *lhs, void const *rhs, DN_USize size);
|
||||
DN_API bool DN_MemStartsWith (void const *lhs, DN_USize lhs_count, void const *rhs, DN_USize rhs_count);
|
||||
DN_API bool DN_MemEq (void const *lhs, DN_USize lhs_count, void const *rhs, DN_USize rhs_count);
|
||||
DN_API bool DN_MemEqUnsafe (void const *lhs, void const *rhs, DN_USize count);
|
||||
#if defined(__cplusplus)
|
||||
template <typename T> T* DN_MemCopyObjT (T *dest, T const *src, DN_USize count);
|
||||
#define DN_MemCopyObj(dest, src, count) DN_MemCopyObjT(dest, src, count)
|
||||
@@ -4359,12 +4346,14 @@ DN_API void DN_ASanUnpoisonMemoryRegion
|
||||
DN_API DN_F32 DN_EpsilonClampF32 (DN_F32 value, DN_F32 target, DN_F32 epsilon);
|
||||
|
||||
DN_API DN_MemStats DN_MemStatsSum (DN_MemStats lhs, DN_MemStats rhs);
|
||||
DN_API DN_MemStats DN_MemStatsSumArray (DN_MemStats const *array, DN_USize size);
|
||||
DN_API DN_MemStats DN_MemStatsSumArray (DN_MemStats const *array, DN_USize count);
|
||||
|
||||
// NOTE: `MemList` is an implementation of a classical `Arena` (e.g. bump allocator, can dynamically
|
||||
// grow, frees by bumping pointer back, sub-divides a block of memory). The term `Arena` is reserved
|
||||
// as a thin-layer over the functionality here to provide some use-after-free protection. See
|
||||
// `Arena` for more info.
|
||||
// NOTE: MemList
|
||||
// Overview
|
||||
// `MemList` is an implementation of a classical `Arena` (e.g. bump allocator, can dynamically
|
||||
// grow, frees by bumping pointer back, sub-divides a block of memory). The term `Arena` is
|
||||
// reserved as a thin-layer over the functionality here to provide some use-after-free protection.
|
||||
// See `Arena` for more info.
|
||||
DN_API DN_MemList DN_MemListFromBuffer (void *buffer, DN_USize size, DN_MemFlags flags);
|
||||
DN_API DN_MemList DN_MemListFromMemFuncs (DN_U64 reserve, DN_U64 commit, DN_MemFlags flags, DN_MemFuncs mem_funcs);
|
||||
DN_API void DN_MemListDeinit (DN_MemList *mem);
|
||||
@@ -4529,7 +4518,7 @@ DN_API DN_I64FromResult DN_I64FromPtr
|
||||
DN_API DN_I64 DN_I64FromPtrUnsafe (void const *data, DN_USize size, char separator);
|
||||
|
||||
DN_API bool DN_U8x32Eq (DN_U8x32 const *lhs, DN_U8x32 const *rhs);
|
||||
DN_API DN_U8x32 DN_U8x32FromBytesLeftPadZ (DN_U8 const *ptr, DN_USize count);
|
||||
DN_API DN_U8x32 DN_U8x32FromBytesLeftPadZ (DN_U8 const *ptr, DN_USize size);
|
||||
DN_API DN_U8x32 DN_U8x32FromHexUnsafe (DN_Str8 hex_32b);
|
||||
DN_API DN_U8x32FromResult DN_U8x32FromHex (DN_Str8 hex_32b);
|
||||
DN_API DN_U8x32FromResult DN_U8x32FromDecimalStr8 (DN_Str8 decimal); // Write decimal string (e.g. "12345") as big-endian 256-bit value
|
||||
@@ -4537,33 +4526,33 @@ DN_API DN_U8x32FromResult DN_U8x32FromDecimalStr8
|
||||
DN_API DN_Allocator DN_AllocatorFromMemList (DN_MemList *mem);
|
||||
DN_API DN_Allocator DN_AllocatorFromArena (DN_Arena *arena);
|
||||
DN_API DN_Allocator DN_AllocatorFromPool (DN_Pool *pool);
|
||||
DN_API void* DN_AllocatorAlloc (DN_Allocator allocator, DN_USize size, DN_U8 align, DN_ZMem z_mem);
|
||||
DN_API void* DN_AllocatorAlloc (DN_Allocator allocator, DN_USize count, DN_U8 align, DN_ZMem z_mem);
|
||||
|
||||
DN_API DN_USize DN_FmtVSize (DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_USize DN_FmtSize (DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_USize DN_FmtVCount (DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_USize DN_FmtCount (DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_FmtAppendResult DN_FmtVAppend (char *buf, DN_USize *buf_size, DN_USize buf_max, char const *fmt, va_list args);
|
||||
DN_API DN_FmtAppendResult DN_FmtAppend (char *buf, DN_USize *buf_size, DN_USize buf_max, char const *fmt, ...);
|
||||
DN_API DN_FmtAppendResult DN_FmtAppendTruncate (char *buf, DN_USize *buf_size, DN_USize buf_max, DN_Str8 truncator, char const *fmt, ...);
|
||||
DN_API DN_USize DN_CStr8Size (char const *src);
|
||||
DN_API DN_USize DN_CStr16Size (wchar_t const *src);
|
||||
DN_API DN_USize DN_CStr8Count (char const *src);
|
||||
DN_API DN_USize DN_CStr16Count (wchar_t const *src);
|
||||
|
||||
#define DN_Str16Lit(string) DN_Str16{(wchar_t *)(string), sizeof(string)/sizeof(string[0]) - 1}
|
||||
#define DN_Str16FromPtr(data, size) DN_Literal(DN_Str16){(wchar_t *)(data), (DN_USize)(size)}
|
||||
#define DN_Str16FromPtr(data, count) DN_Literal(DN_Str16){(wchar_t *)(data), (DN_USize)(count)}
|
||||
|
||||
#define DN_Str8Lit(c_str) DN_Literal(DN_Str8){(char *)(c_str), sizeof(c_str) - 1}
|
||||
#define DN_Str8PrintFmt(string) (int)((string).size), (string).data
|
||||
#define DN_Str8PrintFmt(string) (int)((string).count), (string).data
|
||||
|
||||
#define DN_Str8FromPtr(data, size) DN_Literal(DN_Str8){(char *)(data), (DN_USize)(size)}
|
||||
#define DN_Str8FromStruct(ptr) DN_Str8FromPtr((ptr)->data, (ptr)->size)
|
||||
#define DN_Str8FromPtr(data, count) DN_Literal(DN_Str8){(char *)(data), (DN_USize)(count)}
|
||||
#define DN_Str8FromStruct(ptr) DN_Str8FromPtr((ptr)->data, (ptr)->count)
|
||||
#define DN_Str8FromLitArray(c_array) DN_Str8FromPtr(c_array, DN_ArrayCountU(c_array))
|
||||
DN_API DN_Str8 DN_Str8AllocAllocator (DN_USize size, DN_ZMem z_mem, DN_Allocator allocator);
|
||||
DN_API DN_Str8 DN_Str8AllocArena (DN_USize size, DN_ZMem z_mem, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8AllocPool (DN_USize size, DN_Pool *pool);
|
||||
DN_API DN_Str8 DN_Str8AllocAllocator (DN_USize count, DN_ZMem z_mem, DN_Allocator allocator);
|
||||
DN_API DN_Str8 DN_Str8AllocArena (DN_USize count, DN_ZMem z_mem, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8AllocPool (DN_USize count, DN_Pool *pool);
|
||||
|
||||
DN_API DN_Str8 DN_Str8FromCStr8 (char const *src);
|
||||
DN_API DN_Str8 DN_Str8FromCStr8Arena (char const *src, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromPtrArena (void const *data, DN_USize size, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromPtrPool (void const *data, DN_USize size, DN_Pool *pool);
|
||||
DN_API DN_Str8 DN_Str8FromPtrArena (void const *data, DN_USize count, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromPtrPool (void const *data, DN_USize count, DN_Pool *pool);
|
||||
DN_API DN_Str8 DN_Str8FromStr8Allocator (DN_Str8 string, DN_Allocator allocator);
|
||||
DN_API DN_Str8 DN_Str8FromStr8Arena (DN_Str8 string, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromStr8Pool (DN_Str8 string, DN_Pool *pool);
|
||||
@@ -4606,7 +4595,7 @@ DN_API void DN_Str8x1024AppendFmtV
|
||||
DN_API DN_Str8x32 DN_Str8x32FromU64 (DN_U64 val, char separator);
|
||||
DN_API bool DN_Str8IsAll (DN_Str8 string, DN_Str8IsAllType is_all);
|
||||
DN_API char * DN_Str8End (DN_Str8 string);
|
||||
DN_API DN_Str8 DN_Str8Subset (DN_Str8 string, DN_USize offset, DN_USize size);
|
||||
DN_API DN_Str8 DN_Str8Subset (DN_Str8 string, DN_USize offset, DN_USize count);
|
||||
DN_API DN_Str8 DN_Str8Advance (DN_Str8 string, DN_USize amount);
|
||||
DN_API DN_Str8 DN_Str8NextLine (DN_Str8 string);
|
||||
DN_API DN_Str8BSplitResult DN_Str8BSplitArray (DN_Str8 string, DN_Str8 const *find, DN_USize find_size);
|
||||
@@ -4646,7 +4635,7 @@ DN_API DN_Str8 DN_Str8AppendF
|
||||
DN_API DN_Str8 DN_Str8AppendFV (DN_Arena *arena, DN_Str8 string, char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FillF (DN_Arena *arena, DN_USize count, char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FillFV (DN_Arena *arena, DN_USize count, char const *fmt, va_list args);
|
||||
DN_API void DN_Str8Remove (DN_Str8 *string, DN_USize offset, DN_USize size);
|
||||
DN_API void DN_Str8Remove (DN_Str8 *string, DN_USize offset, DN_USize count);
|
||||
DN_API DN_Str8TruncResult DN_Str8TruncMiddlePtr (DN_Str8 str8, DN_USize side_size, DN_Str8 truncator, char *dest, DN_USize dest_max);
|
||||
DN_API DN_Str8TruncResult DN_Str8TruncMiddle (DN_Str8 str8, DN_USize side_size, DN_Str8 truncator, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8Lower (DN_Str8 string, DN_Arena *arena);
|
||||
@@ -4679,28 +4668,28 @@ DN_API DN_Str16 DN_Str16SliceRender
|
||||
DN_API DN_Str16 DN_Str16RenderSpaceSep (DN_Str16Slice array, DN_Arena *arena);
|
||||
|
||||
DN_API DN_Str8Builder DN_Str8BuilderFromArena (DN_Arena *arena);
|
||||
DN_API DN_Str8Builder DN_Str8BuilderFromStr8PtrRef (DN_Arena *arena, DN_Str8 const *strings, DN_USize size);
|
||||
DN_API DN_Str8Builder DN_Str8BuilderFromStr8PtrCopy (DN_Arena *arena, DN_Str8 const *strings, DN_USize size);
|
||||
DN_API DN_Str8Builder DN_Str8BuilderFromStr8PtrRef (DN_Arena *arena, DN_Str8 const *strings, DN_USize count);
|
||||
DN_API DN_Str8Builder DN_Str8BuilderFromStr8PtrCopy (DN_Arena *arena, DN_Str8 const *strings, DN_USize count);
|
||||
DN_API DN_Str8Builder DN_Str8BuilderFromBuilder (DN_Arena *arena, DN_Str8Builder const *builder);
|
||||
DN_API bool DN_Str8BuilderAddArrayRef (DN_Str8Builder *builder, DN_Str8 const *strings, DN_USize size, DN_Str8BuilderAdd add);
|
||||
DN_API bool DN_Str8BuilderAddArrayCopy (DN_Str8Builder *builder, DN_Str8 const *strings, DN_USize size, DN_Str8BuilderAdd add);
|
||||
DN_API bool DN_Str8BuilderAddArrayRef (DN_Str8Builder *builder, DN_Str8 const *strings, DN_USize count, DN_Str8BuilderAdd add);
|
||||
DN_API bool DN_Str8BuilderAddArrayCopy (DN_Str8Builder *builder, DN_Str8 const *strings, DN_USize count, DN_Str8BuilderAdd add);
|
||||
DN_API bool DN_Str8BuilderAddFV (DN_Str8Builder *builder, DN_Str8BuilderAdd add, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
#define DN_Str8BuilderAppendArrayRef(builder, strings, size) DN_Str8BuilderAddArrayRef(builder, strings, size, DN_Str8BuilderAdd_Append)
|
||||
#define DN_Str8BuilderAppendArrayCopy(builder, strings, size) DN_Str8BuilderAddArrayCopy(builder, strings, size, DN_Str8BuilderAdd_Append)
|
||||
#define DN_Str8BuilderAppendSliceRef(builder, slice) DN_Str8BuilderAddArrayRef(builder, slice.data, slice.size, DN_Str8BuilderAdd_Append)
|
||||
#define DN_Str8BuilderAppendSliceCopy(builder, slice) DN_Str8BuilderAddArrayCopy(builder, slice.data, slice.size, DN_Str8BuilderAdd_Append)
|
||||
#define DN_Str8BuilderAppendSliceRef(builder, slice) DN_Str8BuilderAddArrayRef(builder, slice.data, slice.count, DN_Str8BuilderAdd_Append)
|
||||
#define DN_Str8BuilderAppendSliceCopy(builder, slice) DN_Str8BuilderAddArrayCopy(builder, slice.data, slice.count, DN_Str8BuilderAdd_Append)
|
||||
DN_API bool DN_Str8BuilderAppendRef (DN_Str8Builder *builder, DN_Str8 string);
|
||||
DN_API bool DN_Str8BuilderAppendCopy (DN_Str8Builder *builder, DN_Str8 string);
|
||||
#define DN_Str8BuilderAppendFV(builder, fmt, args) DN_Str8BuilderAddFV(builder, DN_Str8BuilderAdd_Append, fmt, args)
|
||||
DN_API bool DN_Str8BuilderAppendF (DN_Str8Builder *builder, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API bool DN_Str8BuilderAppendBytesRef (DN_Str8Builder *builder, void const *ptr, DN_USize size);
|
||||
DN_API bool DN_Str8BuilderAppendBytesCopy (DN_Str8Builder *builder, void const *ptr, DN_USize size);
|
||||
DN_API bool DN_Str8BuilderAppendBytesRef (DN_Str8Builder *builder, void const *ptr, DN_USize count);
|
||||
DN_API bool DN_Str8BuilderAppendBytesCopy (DN_Str8Builder *builder, void const *ptr, DN_USize count);
|
||||
DN_API bool DN_Str8BuilderAppendBuilderRef (DN_Str8Builder *dest, DN_Str8Builder const *src);
|
||||
DN_API bool DN_Str8BuilderAppendBuilderCopy (DN_Str8Builder *dest, DN_Str8Builder const *src);
|
||||
#define DN_Str8BuilderPrependArrayRef(builder, strings, size) DN_Str8BuilderAddArrayRef(builder, strings, size, DN_Str8BuilderAdd_Prepend)
|
||||
#define DN_Str8BuilderPrependArrayCopy(builder, strings, size) DN_Str8BuilderAddArrayCopy(builder, strings, size, DN_Str8BuilderAdd_Prepend)
|
||||
#define DN_Str8BuilderPrependSliceRef(builder, slice) DN_Str8BuilderAddArrayRef(builder, slice.data, slice.size, DN_Str8BuilderAdd_Prepend)
|
||||
#define DN_Str8BuilderPrependSliceCopy(builder, slice) DN_Str8BuilderAddArrayCopy(builder, slice.data, slice.size, DN_Str8BuilderAdd_Prepend)
|
||||
#define DN_Str8BuilderPrependSliceRef(builder, slice) DN_Str8BuilderAddArrayRef(builder, slice.data, slice.count, DN_Str8BuilderAdd_Prepend)
|
||||
#define DN_Str8BuilderPrependSliceCopy(builder, slice) DN_Str8BuilderAddArrayCopy(builder, slice.data, slice.count, DN_Str8BuilderAdd_Prepend)
|
||||
DN_API bool DN_Str8BuilderPrependRef (DN_Str8Builder *builder, DN_Str8 string);
|
||||
DN_API bool DN_Str8BuilderPrependCopy (DN_Str8Builder *builder, DN_Str8 string);
|
||||
#define DN_Str8BuilderPrependFV(builder, fmt, args) DN_Str8BuilderAddFV(builder, DN_Str8BuilderAdd_Prepend, fmt, args)
|
||||
@@ -4843,8 +4832,8 @@ DN_API void DN_PCG32Advance
|
||||
#define DN_FNV1A64_SEED 14695981039346656037ULL
|
||||
#endif
|
||||
|
||||
DN_API DN_U32 DN_FNV1AHashU32FromBytes (void const *bytes, DN_USize size, DN_U32 seed);
|
||||
DN_API DN_U64 DN_FNV1AHashU64FromBytes (void const *bytes, DN_USize size, DN_U64 seed);
|
||||
DN_API DN_U32 DN_FNV1AHashU32FromBytes (void const *bytes, DN_USize count, DN_U32 seed);
|
||||
DN_API DN_U64 DN_FNV1AHashU64FromBytes (void const *bytes, DN_USize count, DN_U64 seed);
|
||||
|
||||
DN_API DN_U32 DN_MurmurHash3HashU32FromBytesX86 (void const *bytes, int len, DN_U32 seed);
|
||||
DN_API DN_MurmurHash3 DN_MurmurHash3HashU128FromBytesX64 (void const *bytes, int len, DN_U32 seed);
|
||||
@@ -5402,7 +5391,7 @@ DN_API DN_RaycastV2 DN_RaycastLineIntersectV2
|
||||
// API
|
||||
// ResizeFrom: Resizes the array to `new_max` erase elements if resizing to a smaller size
|
||||
// GrowFrom: Expands the capacity of the array if `new_max > array.max` otherwise no-op
|
||||
// GrowIfNeeded: Expands the capacity of the array if `array.size + add_count > array.max` otherwise no-op
|
||||
// GrowIfNeeded: Expands the capacity of the array if `array.count + add_count > array.max` otherwise no-op
|
||||
//
|
||||
// Variants
|
||||
// PArray => Pointer (to) Array
|
||||
@@ -5412,7 +5401,7 @@ DN_API DN_RaycastV2 DN_RaycastLineIntersectV2
|
||||
// automatically using DN_ArrayCountU(l_array).
|
||||
//
|
||||
// MyStruct buffer[TB_ASType_Count] = {};
|
||||
// DN_USize size = 0;
|
||||
// DN_USize count = 0;
|
||||
// MyStruct *item_0 = DN_PArrayMake(buffer, &size, DN_ArrayCountU(buffer), DN_ZMem_No);
|
||||
// MyStruct *item_1 = DN_LArrayMake(buffer, &size, DN_ZMem_No);
|
||||
//
|
||||
@@ -5590,44 +5579,44 @@ DN_API DN_RaycastV2 DN_RaycastLineIntersectV2
|
||||
#define DN_ISliceAllocArena(slice_ptr, count_, zmem, arena) (DN_CppDeclType(&((slice_ptr)->data[0])))DN_SliceAllocArena((void **)&((slice_ptr)->data), &((slice_ptr)->count), count_, sizeof((slice_ptr)->data[0]), alignof(DN_CppDeclType((slice_ptr)->data[0])), zmem, arena)
|
||||
|
||||
|
||||
DN_API void* DN_SliceAllocArena (void **data, DN_USize *slice_size_field, DN_USize size, DN_USize elem_size, DN_U8 align, DN_ZMem zmem, DN_Arena *arena);
|
||||
DN_API void* DN_SliceAllocArena (void **data, DN_USize *slice_size_field, DN_USize count, DN_USize elem_size, DN_U8 align, DN_ZMem zmem, DN_Arena *arena);
|
||||
|
||||
DN_API DN_ArrayFindResult DN_ArrayFind (void *data, DN_USize size, DN_USize elem_size, void const *find, DN_ArrayFindEqFunc *eq_func);
|
||||
DN_API DN_ArrayFindResult DN_ArrayFindMemEq (void *data, DN_USize size, DN_USize elem_size, void const *find);
|
||||
DN_API void* DN_ArrayInsertArray (void *data, DN_USize *size, DN_USize max, DN_USize elem_size, DN_USize index, void const *items, DN_USize count);
|
||||
DN_API void* DN_ArrayPopFront (void *data, DN_USize *size, DN_USize elem_size, DN_USize count);
|
||||
DN_API void* DN_ArrayPopBack (void *data, DN_USize *size, DN_USize elem_size, DN_USize count);
|
||||
DN_API DN_ArrayEraseResult DN_ArrayEraseRange (void *data, DN_USize *size, DN_USize elem_size, DN_USize begin_index, DN_ISize count, DN_ArrayErase erase);
|
||||
DN_API void* DN_ArrayMakeArray (void *data, DN_USize *size, DN_USize max, DN_USize elem_size, DN_USize make_count, DN_ZMem z_mem);
|
||||
DN_API void* DN_ArrayMakeArrayAssert (void *data, DN_USize *size, DN_USize max, DN_USize elem_size, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site);
|
||||
DN_API void* DN_ArrayAddArray (void *data, DN_USize *size, DN_USize max, DN_USize elem_size, void const *elems, DN_USize elems_count, DN_ArrayAdd add);
|
||||
DN_API void* DN_ArrayAddArrayAssert (void *data, DN_USize *size, DN_USize max, DN_USize elem_size, void const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site);
|
||||
DN_API bool DN_ArrayResizeFromPool (void **data, DN_USize *size, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max);
|
||||
DN_API bool DN_ArrayResizeFromArena (void **data, DN_USize *size, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize new_max);
|
||||
DN_API bool DN_ArrayGrowFromPool (void **data, DN_USize size, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max);
|
||||
DN_API bool DN_ArrayGrowFromArena (void **data, DN_USize size, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize new_max);
|
||||
DN_API bool DN_ArrayGrowIfNeededFromPool (void **data, DN_USize size, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize add_count);
|
||||
DN_API bool DN_ArrayGrowIfNeededFromArena (void **data, DN_USize size, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize add_count);
|
||||
DN_API DN_ArrayFindResult DN_ArrayFind (void *data, DN_USize count, DN_USize elem_size, void const *find, DN_ArrayFindEqFunc *eq_func);
|
||||
DN_API DN_ArrayFindResult DN_ArrayFindMemEq (void *data, DN_USize count, DN_USize elem_size, void const *find);
|
||||
DN_API void* DN_ArrayInsertArray (void *data, DN_USize *count, DN_USize max, DN_USize elem_size, DN_USize index, void const *items, DN_USize items_count);
|
||||
DN_API void* DN_ArrayPopFront (void *data, DN_USize *count, DN_USize elem_size, DN_USize pop_count);
|
||||
DN_API void* DN_ArrayPopBack (void *data, DN_USize *count, DN_USize elem_size, DN_USize pop_count);
|
||||
DN_API DN_ArrayEraseResult DN_ArrayEraseRange (void *data, DN_USize *count, DN_USize elem_size, DN_USize begin_index, DN_ISize erase_count, DN_ArrayErase erase);
|
||||
DN_API void* DN_ArrayMakeArray (void *data, DN_USize *count, DN_USize max, DN_USize elem_size, DN_USize make_count, DN_ZMem z_mem);
|
||||
DN_API void* DN_ArrayMakeArrayAssert (void *data, DN_USize *count, DN_USize max, DN_USize elem_size, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site);
|
||||
DN_API void* DN_ArrayAddArray (void *data, DN_USize *count, DN_USize max, DN_USize elem_size, void const *elems, DN_USize elems_count, DN_ArrayAdd add);
|
||||
DN_API void* DN_ArrayAddArrayAssert (void *data, DN_USize *count, DN_USize max, DN_USize elem_size, void const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site);
|
||||
DN_API bool DN_ArrayResizeFromPool (void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max);
|
||||
DN_API bool DN_ArrayResizeFromArena (void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize new_max);
|
||||
DN_API bool DN_ArrayGrowFromPool (void **data, DN_USize count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max);
|
||||
DN_API bool DN_ArrayGrowFromArena (void **data, DN_USize count, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize new_max);
|
||||
DN_API bool DN_ArrayGrowIfNeededFromPool (void **data, DN_USize count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize add_count);
|
||||
DN_API bool DN_ArrayGrowIfNeededFromArena (void **data, DN_USize count, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize add_count);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
template <typename T> DN_ArrayFindResult DN_TArrayFind (T *data, DN_USize size, void const *find, DN_ArrayFindEqFunc *eq_func);
|
||||
template <typename T> DN_ArrayFindResult DN_TArrayFindMemEq (T *data, DN_USize size, void const *find, DN_ArrayFindEqFunc *eq_func);
|
||||
template <typename T> T* DN_TArrayInsertArray (T *data, DN_USize *size, DN_USize max, DN_USize index, void const *items, DN_USize count);
|
||||
template <typename T> T* DN_TArrayPopFront (T *data, DN_USize *size, DN_USize count);
|
||||
template <typename T> T* DN_TArrayPopBack (T *data, DN_USize *size, DN_USize count);
|
||||
template <typename T> DN_ArrayEraseResult DN_TArrayEraseRange (T *data, DN_USize *size, DN_USize begin_index, DN_ISize count, DN_ArrayErase erase);
|
||||
template <typename T> T* DN_TArrayMakeArray (T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_ZMem z_mem);
|
||||
template <typename T> T* DN_TArrayMakeArrayAssert (T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site);
|
||||
template <typename T> T* DN_TArrayMakeArrayAssertZ (T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_CallSite call_site);
|
||||
template <typename T> T* DN_TArrayMakeArrayAssertNoZ (T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_CallSite call_site);
|
||||
template <typename T> T* DN_TArrayAddArray (T *data, DN_USize *size, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add);
|
||||
template <typename T> T* DN_TArrayAddArrayAssert (T *data, DN_USize *size, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site);
|
||||
template <typename T> bool DN_TArrayResizeFromPool (T **data, DN_USize *size, DN_USize *max, DN_Pool *pool, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayResizeFromArena (T **data, DN_USize *size, DN_USize *max, DN_Arena *arena, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayGrowFromPool (T **data, DN_USize size, DN_USize *max, DN_Pool *pool, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayGrowFromArena (T **data, DN_USize size, DN_USize *max, DN_Pool *pool, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayGrowIfNeededFromPool (T **data, DN_USize size, DN_USize *max, DN_Pool *pool, DN_USize add_count);
|
||||
template <typename T> bool DN_TArrayGrowIfNeededFromArena (T **data, DN_USize size, DN_USize *max, DN_Arena *pool, DN_USize add_count);
|
||||
template <typename T> DN_ArrayFindResult DN_TArrayFind (T *data, DN_USize count, void const *find, DN_ArrayFindEqFunc *eq_func);
|
||||
template <typename T> DN_ArrayFindResult DN_TArrayFindMemEq (T *data, DN_USize count, void const *find, DN_ArrayFindEqFunc *eq_func);
|
||||
template <typename T> T* DN_TArrayInsertArray (T *data, DN_USize *count, DN_USize max, DN_USize index, void const *items, DN_USize pop_count);
|
||||
template <typename T> T* DN_TArrayPopFront (T *data, DN_USize *count, DN_USize pop_count);
|
||||
template <typename T> T* DN_TArrayPopBack (T *data, DN_USize *count, DN_USize pop_count);
|
||||
template <typename T> DN_ArrayEraseResult DN_TArrayEraseRange (T *data, DN_USize *count, DN_USize begin_index, DN_ISize erase_count, DN_ArrayErase erase);
|
||||
template <typename T> T* DN_TArrayMakeArray (T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_ZMem z_mem);
|
||||
template <typename T> T* DN_TArrayMakeArrayAssert (T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site);
|
||||
template <typename T> T* DN_TArrayMakeArrayAssertZ (T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_CallSite call_site);
|
||||
template <typename T> T* DN_TArrayMakeArrayAssertNoZ (T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_CallSite call_site);
|
||||
template <typename T> T* DN_TArrayAddArray (T *data, DN_USize *count, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add);
|
||||
template <typename T> T* DN_TArrayAddArrayAssert (T *data, DN_USize *count, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site);
|
||||
template <typename T> bool DN_TArrayResizeFromPool (T **data, DN_USize *count, DN_USize *max, DN_Pool *pool, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayResizeFromArena (T **data, DN_USize *count, DN_USize *max, DN_Arena *arena, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayGrowFromPool (T **data, DN_USize count, DN_USize *max, DN_Pool *pool, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayGrowFromArena (T **data, DN_USize count, DN_USize *max, DN_Pool *pool, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayGrowIfNeededFromPool (T **data, DN_USize count, DN_USize *max, DN_Pool *pool, DN_USize add_count);
|
||||
template <typename T> bool DN_TArrayGrowIfNeededFromArena (T **data, DN_USize count, DN_USize *max, DN_Arena *pool, DN_USize add_count);
|
||||
#endif
|
||||
|
||||
DN_API void* DN_SinglyLLDetach (void **link, void **next);
|
||||
@@ -5660,8 +5649,8 @@ template <typename T> bool DN_DSMapResize (DN_DSMap
|
||||
template <typename T> bool DN_DSMapErase (DN_DSMap<T> *map, DN_DSMapKey key);
|
||||
template <typename T> bool DN_DSMapEraseKeyU64 (DN_DSMap<T> *map, DN_U64 key);
|
||||
template <typename T> bool DN_DSMapEraseKeyStr8 (DN_DSMap<T> *map, DN_Str8 key);
|
||||
template <typename T> DN_DSMapKey DN_DSMapKeyBuffer (DN_DSMap<T> const *map, void const *data, DN_USize size);
|
||||
template <typename T> DN_DSMapKey DN_DSMapKeyBufferAsU64NoHash (DN_DSMap<T> const *map, void const *data, DN_USize size);
|
||||
template <typename T> DN_DSMapKey DN_DSMapKeyBuffer (DN_DSMap<T> const *map, void const *data, DN_USize count);
|
||||
template <typename T> DN_DSMapKey DN_DSMapKeyBufferAsU64NoHash (DN_DSMap<T> const *map, void const *data, DN_USize count);
|
||||
template <typename T> DN_DSMapKey DN_DSMapKeyU64 (DN_DSMap<T> const *map, DN_U64 u64);
|
||||
template <typename T> DN_DSMapKey DN_DSMapKeyStr8 (DN_DSMap<T> const *map, DN_Str8 string);
|
||||
#define DN_DSMapKeyCStr8(map, string) DN_DSMapKeyBuffer(map, string, sizeof((string))/sizeof((string)[0]) - 1)
|
||||
@@ -5881,19 +5870,19 @@ DN_API DN_Arena DN_ArenaFromHeap (D
|
||||
DN_API DN_Arena DN_ArenaFromVMem (DN_U64 reserve, DN_U64 commit, DN_MemFlags flags);
|
||||
|
||||
DN_API DN_Str8 DN_Str8FromHeapF (DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FromHeap (DN_USize size, DN_ZMem z_mem);
|
||||
DN_API DN_Str8 DN_Str8FromHeap (DN_USize count, DN_ZMem z_mem);
|
||||
DN_API DN_Str8 DN_Str8BuilderBuildFromHeap (DN_Str8Builder const *builder);
|
||||
|
||||
DN_API void DN_OS_LogPrint (DN_LogTypeParam type, void *user_data, DN_CallSite call_site, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API void DN_OS_SetLogPrintFuncToOS ();
|
||||
|
||||
DN_API void * DN_OS_MemReserve (DN_USize size, DN_MemCommit commit, DN_MemPage page_flags);
|
||||
DN_API bool DN_OS_MemCommit (void *ptr, DN_USize size, DN_U32 page_flags);
|
||||
DN_API void DN_OS_MemDecommit (void *ptr, DN_USize size);
|
||||
DN_API void DN_OS_MemRelease (void *ptr, DN_USize size);
|
||||
DN_API int DN_OS_MemProtect (void *ptr, DN_USize size, DN_U32 page_flags);
|
||||
DN_API void * DN_OS_MemReserve (DN_USize count, DN_MemCommit commit, DN_MemPage page_flags);
|
||||
DN_API bool DN_OS_MemCommit (void *ptr, DN_USize count, DN_U32 page_flags);
|
||||
DN_API void DN_OS_MemDecommit (void *ptr, DN_USize count);
|
||||
DN_API void DN_OS_MemRelease (void *ptr, DN_USize count);
|
||||
DN_API int DN_OS_MemProtect (void *ptr, DN_USize count, DN_U32 page_flags);
|
||||
|
||||
DN_API void * DN_OS_MemAlloc (DN_USize size, DN_ZMem z_mem);
|
||||
DN_API void * DN_OS_MemAlloc (DN_USize count, DN_ZMem z_mem);
|
||||
DN_API void DN_OS_MemDealloc (void *ptr);
|
||||
|
||||
DN_API DN_Date DN_OS_DateLocalTimeNow ();
|
||||
@@ -5931,8 +5920,8 @@ DN_API bool DN_OS_FileCopy (D
|
||||
DN_API bool DN_OS_FileMove (DN_Str8 src, DN_Str8 dest, bool overwrite, DN_ErrSink *err);
|
||||
|
||||
DN_API DN_OSFile DN_OS_FileOpen (DN_Str8 path, DN_OSFileOpen open_mode, DN_OSFileAccess access, DN_ErrSink *err);
|
||||
DN_API DN_OSFileRead DN_OS_FileRead (DN_OSFile *file, void *buffer, DN_USize size, DN_ErrSink *err);
|
||||
DN_API bool DN_OS_FileWritePtr (DN_OSFile *file, void const *data, DN_USize size, DN_ErrSink *err);
|
||||
DN_API DN_OSFileRead DN_OS_FileRead (DN_OSFile *file, void *buffer, DN_USize count, DN_ErrSink *err);
|
||||
DN_API bool DN_OS_FileWritePtr (DN_OSFile *file, void const *data, DN_USize count, DN_ErrSink *err);
|
||||
DN_API bool DN_OS_FileWrite (DN_OSFile *file, DN_Str8 buffer, DN_ErrSink *err);
|
||||
DN_API bool DN_OS_FileWriteFV (DN_OSFile *file, DN_ErrSink *err, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API bool DN_OS_FileWriteF (DN_OSFile *file, DN_ErrSink *err, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
@@ -6155,128 +6144,128 @@ template <typename T> T *DN_MemCopyObjT(T *dest, T const *src, DN_USize count)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DN_ArrayFindResult DN_TArrayFind(T *data, DN_USize size, void const *find, DN_ArrayFindEqFunc *eq_func)
|
||||
DN_ArrayFindResult DN_TArrayFind(T *data, DN_USize count, void const *find, DN_ArrayFindEqFunc *eq_func)
|
||||
{
|
||||
DN_ArrayFindResult result = DN_ArrayFind(data, size, sizeof(*data), find, eq_func);
|
||||
DN_ArrayFindResult result = DN_ArrayFind(data, count, sizeof(*data), find, eq_func);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DN_ArrayFindResult DN_TArrayFindMemEq(T *data, DN_USize size, void const *find)
|
||||
DN_ArrayFindResult DN_TArrayFindMemEq(T *data, DN_USize count, void const *find)
|
||||
{
|
||||
DN_ArrayFindResult result = DN_ArrayFindMemEq(data, size, sizeof(*data), find);
|
||||
DN_ArrayFindResult result = DN_ArrayFindMemEq(data, count, sizeof(*data), find);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayInsertArray(T *data, DN_USize *size, DN_USize max, DN_USize index, T const *items, DN_USize count)
|
||||
T *DN_TArrayInsertArray(T *data, DN_USize *count, DN_USize max, DN_USize index, T const *items, DN_USize items_count)
|
||||
{
|
||||
T *result = DN_Cast(T *)DN_ArrayInsertArray(data, size, max, sizeof(*data), index, items, count);
|
||||
T *result = DN_Cast(T *)DN_ArrayInsertArray(data, count, max, sizeof(*data), index, items, items_count);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayPopFront(T *data, DN_USize *size, DN_USize count)
|
||||
T *DN_TArrayPopFront(T *data, DN_USize *count, DN_USize pop_count)
|
||||
{
|
||||
T *result = DN_Cast(T *)DN_ArrayPopFront(data, size, sizeof(*data), count);
|
||||
T *result = DN_Cast(T *)DN_ArrayPopFront(data, count, sizeof(*data), pop_count);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayPopBack(T *data, DN_USize *size, DN_USize count)
|
||||
T *DN_TArrayPopBack(T *data, DN_USize *count, DN_USize pop_count)
|
||||
{
|
||||
T *result = DN_Cast(T *)DN_ArrayPopBack(data, size, sizeof(*data), count);
|
||||
T *result = DN_Cast(T *)DN_ArrayPopBack(data, count, sizeof(*data), pop_count);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DN_ArrayEraseResult DN_TArrayEraseRange(T *data, DN_USize *size, DN_USize begin_index, DN_ISize count, DN_ArrayErase erase)
|
||||
DN_ArrayEraseResult DN_TArrayEraseRange(T *data, DN_USize *count, DN_USize begin_index, DN_ISize erase_count, DN_ArrayErase erase)
|
||||
{
|
||||
DN_ArrayEraseResult result = DN_ArrayEraseRange(data, size, sizeof(*data), begin_index, count, erase);
|
||||
DN_ArrayEraseResult result = DN_ArrayEraseRange(data, count, sizeof(*data), begin_index, erase_count, erase);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayMakeArray(T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_ZMem z_mem)
|
||||
T *DN_TArrayMakeArray(T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_ZMem z_mem)
|
||||
{
|
||||
T *result = DN_Cast(T *)DN_ArrayMakeArray(data, size, max, sizeof(*data), make_count, z_mem);
|
||||
T *result = DN_Cast(T *)DN_ArrayMakeArray(data, count, max, sizeof(*data), make_count, z_mem);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayMakeArrayAssert(T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site)
|
||||
T *DN_TArrayMakeArrayAssert(T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site)
|
||||
{
|
||||
T *result = DN_Cast(T *)DN_ArrayMakeArrayAssert(data, size, max, sizeof(*data), make_count, z_mem, call_site);
|
||||
T *result = DN_Cast(T *)DN_ArrayMakeArrayAssert(data, count, max, sizeof(*data), make_count, z_mem, call_site);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayMakeArrayAssertZ(T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_CallSite call_site)
|
||||
T *DN_TArrayMakeArrayAssertZ(T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_CallSite call_site)
|
||||
{
|
||||
T* result = DN_TArrayMakeArrayAssert(data, size, max, make_count, DN_ZMem_Yes, call_site);
|
||||
T* result = DN_TArrayMakeArrayAssert(data, count, max, make_count, DN_ZMem_Yes, call_site);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayMakeArrayAssertNoZ(T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_CallSite call_site)
|
||||
T *DN_TArrayMakeArrayAssertNoZ(T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_CallSite call_site)
|
||||
{
|
||||
T* result = DN_TArrayMakeArrayAssert(data, size, max, make_count, DN_ZMem_No, call_site);
|
||||
T* result = DN_TArrayMakeArrayAssert(data, count, max, make_count, DN_ZMem_No, call_site);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayAddArray(T *data, DN_USize *size, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add)
|
||||
T *DN_TArrayAddArray(T *data, DN_USize *count, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add)
|
||||
{
|
||||
T* result = DN_Cast(T *)DN_ArrayAddArray(data, size, max, sizeof(*elems), elems, elems_count, add);
|
||||
T* result = DN_Cast(T *)DN_ArrayAddArray(data, count, max, sizeof(*elems), elems, elems_count, add);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayAddArrayAssert(T *data, DN_USize *size, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site)
|
||||
T *DN_TArrayAddArrayAssert(T *data, DN_USize *count, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site)
|
||||
{
|
||||
T* result = DN_Cast(T *)DN_ArrayAddArrayAssert(data, size, max, sizeof(*elems), elems, elems_count, add, call_site);
|
||||
T* result = DN_Cast(T *)DN_ArrayAddArrayAssert(data, count, max, sizeof(*elems), elems, elems_count, add, call_site);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DN_TArrayResizeFromPool(T **data, DN_USize *size, DN_USize *max, DN_Pool *pool, DN_USize new_max)
|
||||
bool DN_TArrayResizeFromPool(T **data, DN_USize *count, DN_USize *max, DN_Pool *pool, DN_USize new_max)
|
||||
{
|
||||
bool result = DN_ArrayResizeFromPool(DN_Cast(void **)data, size, max, sizeof(**data), pool, new_max);
|
||||
bool result = DN_ArrayResizeFromPool(DN_Cast(void **)data, count, max, sizeof(**data), pool, new_max);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DN_TArrayResizeFromArena(T **data, DN_USize *size, DN_USize *max, DN_Arena *arena, DN_USize new_max)
|
||||
bool DN_TArrayResizeFromArena(T **data, DN_USize *count, DN_USize *max, DN_Arena *arena, DN_USize new_max)
|
||||
{
|
||||
bool result = DN_ArrayResizeFromArena(DN_Cast(void **)data, size, max, sizeof(**data), arena, new_max);
|
||||
bool result = DN_ArrayResizeFromArena(DN_Cast(void **)data, count, max, sizeof(**data), arena, new_max);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DN_TArrayGrowFromPool(T **data, DN_USize size, DN_USize *max, DN_Pool *pool, DN_USize new_max)
|
||||
bool DN_TArrayGrowFromPool(T **data, DN_USize count, DN_USize *max, DN_Pool *pool, DN_USize new_max)
|
||||
{
|
||||
bool result = DN_ArrayGrowFromPool(DN_Cast(void **)data, size, max, sizeof(**data), pool, new_max);
|
||||
bool result = DN_ArrayGrowFromPool(DN_Cast(void **)data, count, max, sizeof(**data), pool, new_max);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DN_TArrayGrowFromArena(T **data, DN_USize size, DN_USize *max, DN_Arena *arena, DN_USize new_max)
|
||||
bool DN_TArrayGrowFromArena(T **data, DN_USize count, DN_USize *max, DN_Arena *arena, DN_USize new_max)
|
||||
{
|
||||
bool result = DN_ArrayGrowFromArena(DN_Cast(void **)data, size, max, sizeof(**data), arena, new_max);
|
||||
bool result = DN_ArrayGrowFromArena(DN_Cast(void **)data, count, max, sizeof(**data), arena, new_max);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DN_TArrayGrowIfNeededFromPool(T **data, DN_USize size, DN_USize *max, DN_Pool *pool, DN_USize add_count)
|
||||
bool DN_TArrayGrowIfNeededFromPool(T **data, DN_USize count, DN_USize *max, DN_Pool *pool, DN_USize add_count)
|
||||
{
|
||||
bool result = DN_ArrayGrowIfNeededFromPool(DN_Cast(void **)data, size, max, sizeof(**data), pool, add_count);
|
||||
bool result = DN_ArrayGrowIfNeededFromPool(DN_Cast(void **)data, count, max, sizeof(**data), pool, add_count);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DN_TArrayGrowIfNeededFromArena(T **data, DN_USize size, DN_USize *max, DN_Arena *arena, DN_USize add_count)
|
||||
bool DN_TArrayGrowIfNeededFromArena(T **data, DN_USize count, DN_USize *max, DN_Arena *arena, DN_USize add_count)
|
||||
{
|
||||
bool result = DN_ArrayGrowIfNeededFromArena(DN_Cast(void **)data, size, max, sizeof(**data), arena, add_count);
|
||||
bool result = DN_ArrayGrowIfNeededFromArena(DN_Cast(void **)data, count, max, sizeof(**data), arena, add_count);
|
||||
return result;
|
||||
}
|
||||
#endif // defined(__cplusplus)
|
||||
@@ -6311,10 +6300,12 @@ enum DN_NETWSSend
|
||||
DN_NETWSSend_Pong,
|
||||
};
|
||||
|
||||
enum DN_NETDoHTTPFlags
|
||||
typedef DN_U32 DN_NETDoHTTPFlags;
|
||||
enum DN_NETDoHTTPFlags_
|
||||
{
|
||||
DN_NETDoHTTPFlags_Nil = 0,
|
||||
DN_NETDoHTTPFlags_BasicAuth = 1 << 0,
|
||||
DN_NETDoHTTPFlags_DisableSSLVerify = 1 << 1,
|
||||
};
|
||||
|
||||
struct DN_NETDoHTTPArgs
|
||||
@@ -6338,6 +6329,8 @@ struct DN_NETRequestHandle
|
||||
|
||||
struct DN_NETResponse
|
||||
{
|
||||
// NOTE: When filling these fields, all their values are copied internally in the library so the
|
||||
// values do not need to persist past the initial invocation of the HTTP/WS request.
|
||||
// NOTE: Common to WS and HTTP responses
|
||||
DN_NETRequestType type;
|
||||
DN_NETResponseState state;
|
||||
@@ -6396,10 +6389,24 @@ struct DN_NETCore
|
||||
DN_NETInterface api;
|
||||
};
|
||||
|
||||
// NOTE: NET
|
||||
// Overview
|
||||
// Defines a multi-threaded interface for doing network requests (via the `DN_NETInterface`
|
||||
// object) in the core struct. On top of this is a asynchronous API provided to the caller along
|
||||
// the lines of, do http/ws followed to dispatch a request followed by a blocking wait for
|
||||
// response function.
|
||||
//
|
||||
// API
|
||||
// DN_NET_ResponseHasFailed
|
||||
// After a response has been dispatched via do http/ws the returned handle's status can be
|
||||
// queried using this function. A request has failed if the `state` has returned
|
||||
// `DN_NETResponseState_Error`, or the returned HTTP status code was `>= 400`.
|
||||
DN_Str8 DN_NET_Str8FromResponseState (DN_NETResponseState state);
|
||||
DN_NETRequest * DN_NET_RequestFromHandle (DN_NETRequestHandle handle);
|
||||
DN_NETRequestHandle DN_NET_HandleFromRequest (DN_NETRequest *request);
|
||||
bool DN_NET_ResponseHasFailed (DN_NETResponse const* resp);
|
||||
bool DN_NET_ResponseHasSucceeded (DN_NETResponse const* resp);
|
||||
bool DN_NET_ResponseIsReady (DN_NETResponse const* resp);
|
||||
DN_Str8 DN_NET_Str8DiagnosticFromResponse(DN_NETResponse const* resp, DN_Arena *arena);
|
||||
|
||||
// NOTE: Internal functions for different networking implementations to use
|
||||
@@ -6409,6 +6416,15 @@ void DN_NET_EndFinishedRequest (DN_NETRequest *request);
|
||||
#endif
|
||||
|
||||
#if DN_WITH_NET_CURL
|
||||
#if defined(DN_COMPILER_MSVC) || defined(DN_COMPILER_CLANG_CL)
|
||||
#pragma comment(lib, "advapi32")
|
||||
#pragma comment(lib, "ws2_32")
|
||||
#pragma comment(lib, "wldap32")
|
||||
#pragma comment(lib, "crypt32")
|
||||
#pragma comment(lib, "secur32")
|
||||
#pragma comment(lib, "Iphlpapi")
|
||||
#endif
|
||||
|
||||
#if !DN_WITH_OS || !DN_WITH_NET
|
||||
#error "NET API with CURL requires #define DN_WITH_NET 1 and #define DN_WITH_OS 1"
|
||||
#endif
|
||||
|
||||
Vendored
+1
-1
@@ -614,7 +614,7 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback,
|
||||
{
|
||||
DN_Str8 str8 = va_arg(va, DN_Str8);
|
||||
s = (char *)str8.data;
|
||||
l = (uint32_t)str8.size;
|
||||
l = (uint32_t)str8.count;
|
||||
lead[0] = 0;
|
||||
tail[0] = 0;
|
||||
pr = 0;
|
||||
|
||||
+53
-53
@@ -319,13 +319,13 @@ static DN_UTCore DN_TST_Base()
|
||||
for (DN_UT_Test(&result, "Age from U64: 1001 converts to 1s 1ms (seconds and ms)")) {
|
||||
DN_Str8x128 str8 = DN_AgeStr8FromMsU64(1001, DN_AgeUnit_Sec | DN_AgeUnit_Ms);
|
||||
DN_Str8 expect = DN_Str8Lit("1s 1ms");
|
||||
DN_UT_AssertF(&result, DN_MemEq(str8.data, str8.size, expect.data, expect.size), "str8=%.*s, expect=%.*s", DN_Str8PrintFmt(str8), DN_Str8PrintFmt(expect));
|
||||
DN_UT_AssertF(&result, DN_MemEq(str8.data, str8.count, expect.data, expect.count), "str8=%.*s, expect=%.*s", DN_Str8PrintFmt(str8), DN_Str8PrintFmt(expect));
|
||||
}
|
||||
|
||||
for (DN_UT_Test(&result, "Age from U64: 1001 converts to 1.001s (fractional)")) {
|
||||
DN_Str8x128 str8 = DN_AgeStr8FromMsU64(1001, DN_AgeUnit_FractionalSec);
|
||||
DN_Str8 expect = DN_Str8Lit("1.001s");
|
||||
DN_UT_AssertF(&result, DN_MemEq(str8.data, str8.size, expect.data, expect.size), "str8=%.*s, expect=%.*s", DN_Str8PrintFmt(str8), DN_Str8PrintFmt(expect));
|
||||
DN_UT_AssertF(&result, DN_MemEq(str8.data, str8.count, expect.data, expect.count), "str8=%.*s, expect=%.*s", DN_Str8PrintFmt(str8), DN_Str8PrintFmt(expect));
|
||||
}
|
||||
|
||||
for (DN_UT_Test(&result, "FmtAppendTruncate: String truncates with 3 dots")) {
|
||||
@@ -665,12 +665,12 @@ static DN_UTCore DN_TST_BaseBytesHex()
|
||||
DN_UT_AssertF(&test,
|
||||
DN_Str8Eq(bytes, DN_Str8Lit("\xf6\xed\x00")),
|
||||
"number_hex=%.*s",
|
||||
DN_Str8PrintFmt(DN_HexFromPtrBytesArena(bytes.data, bytes.size, &scratch.arena, DN_TrimLeadingZero_No)));
|
||||
DN_Str8PrintFmt(DN_HexFromPtrBytesArena(bytes.data, bytes.count, &scratch.arena, DN_TrimLeadingZero_No)));
|
||||
}
|
||||
|
||||
for (DN_UT_Test(&test, "Convert empty bytes to string", number)) {
|
||||
DN_Str8 bytes = DN_Str8Lit("");
|
||||
DN_Str8 as_hex = DN_HexFromPtrBytesArena(bytes.data, bytes.size, &scratch.arena, DN_TrimLeadingZero_No);
|
||||
DN_Str8 as_hex = DN_HexFromPtrBytesArena(bytes.data, bytes.count, &scratch.arena, DN_TrimLeadingZero_No);
|
||||
DN_UT_AssertF(&test, DN_Str8Eq(as_hex, DN_Str8Lit("")), "as_hex=%.*s", DN_Str8PrintFmt(as_hex));
|
||||
}
|
||||
}
|
||||
@@ -1541,13 +1541,13 @@ DN_Str8 const DN_UT_HASH_STRING_[] =
|
||||
void DN_TST_KeccakDispatch_(DN_UTCore *test, int hash_type, DN_Str8 input)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str8 input_hex = DN_HexFromPtrBytesArena(input.data, input.size, &scratch.arena, DN_TrimLeadingZero_No);
|
||||
DN_Str8 input_hex = DN_HexFromPtrBytesArena(input.data, input.count, &scratch.arena, DN_TrimLeadingZero_No);
|
||||
|
||||
switch (hash_type) {
|
||||
case Hash_SHA3_224: {
|
||||
DN_SHA3U8x28 hash = DN_SHA3Hash224b(input.data, input.size);
|
||||
DN_SHA3U8x28 hash = DN_SHA3Hash224b(input.data, input.count);
|
||||
DN_SHA3U8x28 expect;
|
||||
DN_RefImpl_FIPS202_SHA3_224_(DN_Cast(uint8_t *) input.data, input.size, (uint8_t *)expect.data);
|
||||
DN_RefImpl_FIPS202_SHA3_224_(DN_Cast(uint8_t *) input.data, input.count, (uint8_t *)expect.data);
|
||||
|
||||
DN_Str8 hash_hex = DN_HexFromPtrBytesArena(hash.data, DN_ArrayCountU(hash.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
DN_Str8 expect_hex = DN_HexFromPtrBytesArena(expect.data, DN_ArrayCountU(expect.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
@@ -1562,9 +1562,9 @@ void DN_TST_KeccakDispatch_(DN_UTCore *test, int hash_type, DN_Str8 input)
|
||||
} break;
|
||||
|
||||
case Hash_SHA3_256: {
|
||||
DN_SHA3U8x32 hash = DN_SHA3Hash256b(input.data, input.size);
|
||||
DN_SHA3U8x32 hash = DN_SHA3Hash256b(input.data, input.count);
|
||||
DN_SHA3U8x32 expect;
|
||||
DN_RefImpl_FIPS202_SHA3_256_(DN_Cast(uint8_t *) input.data, input.size, (uint8_t *)expect.data);
|
||||
DN_RefImpl_FIPS202_SHA3_256_(DN_Cast(uint8_t *) input.data, input.count, (uint8_t *)expect.data);
|
||||
|
||||
DN_Str8 hash_hex = DN_HexFromPtrBytesArena(hash.data, DN_ArrayCountU(hash.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
DN_Str8 expect_hex = DN_HexFromPtrBytesArena(expect.data, DN_ArrayCountU(expect.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
@@ -1579,9 +1579,9 @@ void DN_TST_KeccakDispatch_(DN_UTCore *test, int hash_type, DN_Str8 input)
|
||||
} break;
|
||||
|
||||
case Hash_SHA3_384: {
|
||||
DN_SHA3U8x48 hash = DN_SHA3Hash384b(input.data, input.size);
|
||||
DN_SHA3U8x48 hash = DN_SHA3Hash384b(input.data, input.count);
|
||||
DN_SHA3U8x48 expect;
|
||||
DN_RefImpl_FIPS202_SHA3_384_(DN_Cast(uint8_t *) input.data, input.size, (uint8_t *)expect.data);
|
||||
DN_RefImpl_FIPS202_SHA3_384_(DN_Cast(uint8_t *) input.data, input.count, (uint8_t *)expect.data);
|
||||
|
||||
DN_Str8 hash_hex = DN_HexFromPtrBytesArena(hash.data, DN_ArrayCountU(hash.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
DN_Str8 expect_hex = DN_HexFromPtrBytesArena(expect.data, DN_ArrayCountU(expect.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
@@ -1596,9 +1596,9 @@ void DN_TST_KeccakDispatch_(DN_UTCore *test, int hash_type, DN_Str8 input)
|
||||
} break;
|
||||
|
||||
case Hash_SHA3_512: {
|
||||
DN_SHA3U8x64 hash = DN_SHA3Hash512b(input.data, input.size);
|
||||
DN_SHA3U8x64 hash = DN_SHA3Hash512b(input.data, input.count);
|
||||
DN_SHA3U8x64 expect;
|
||||
DN_RefImpl_FIPS202_SHA3_512_(DN_Cast(uint8_t *) input.data, input.size, (uint8_t *)expect.data);
|
||||
DN_RefImpl_FIPS202_SHA3_512_(DN_Cast(uint8_t *) input.data, input.count, (uint8_t *)expect.data);
|
||||
|
||||
DN_Str8 hash_hex = DN_HexFromPtrBytesArena(hash.data, DN_ArrayCountU(hash.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
DN_Str8 expect_hex = DN_HexFromPtrBytesArena(expect.data, DN_ArrayCountU(expect.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
@@ -1613,9 +1613,9 @@ void DN_TST_KeccakDispatch_(DN_UTCore *test, int hash_type, DN_Str8 input)
|
||||
} break;
|
||||
|
||||
case Hash_Keccak_224: {
|
||||
DN_SHA3U8x28 hash = DN_KeccakHash224b(input.data, input.size);
|
||||
DN_SHA3U8x28 hash = DN_KeccakHash224b(input.data, input.count);
|
||||
DN_SHA3U8x28 expect;
|
||||
DN_RefImpl_Keccak_(1152, 448, DN_Cast(uint8_t *) input.data, input.size, 0x01, (uint8_t *)expect.data, sizeof(expect));
|
||||
DN_RefImpl_Keccak_(1152, 448, DN_Cast(uint8_t *) input.data, input.count, 0x01, (uint8_t *)expect.data, sizeof(expect));
|
||||
|
||||
DN_Str8 hash_hex = DN_HexFromPtrBytesArena(hash.data, DN_ArrayCountU(hash.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
DN_Str8 expect_hex = DN_HexFromPtrBytesArena(expect.data, DN_ArrayCountU(expect.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
@@ -1630,9 +1630,9 @@ void DN_TST_KeccakDispatch_(DN_UTCore *test, int hash_type, DN_Str8 input)
|
||||
} break;
|
||||
|
||||
case Hash_Keccak_256: {
|
||||
DN_SHA3U8x32 hash = DN_KeccakHash256b(input.data, input.size);
|
||||
DN_SHA3U8x32 hash = DN_KeccakHash256b(input.data, input.count);
|
||||
DN_SHA3U8x32 expect;
|
||||
DN_RefImpl_Keccak_(1088, 512, DN_Cast(uint8_t *) input.data, input.size, 0x01, (uint8_t *)expect.data, sizeof(expect));
|
||||
DN_RefImpl_Keccak_(1088, 512, DN_Cast(uint8_t *) input.data, input.count, 0x01, (uint8_t *)expect.data, sizeof(expect));
|
||||
|
||||
DN_Str8 hash_hex = DN_HexFromPtrBytesArena(hash.data, DN_ArrayCountU(hash.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
DN_Str8 expect_hex = DN_HexFromPtrBytesArena(expect.data, DN_ArrayCountU(expect.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
@@ -1647,9 +1647,9 @@ void DN_TST_KeccakDispatch_(DN_UTCore *test, int hash_type, DN_Str8 input)
|
||||
} break;
|
||||
|
||||
case Hash_Keccak_384: {
|
||||
DN_SHA3U8x48 hash = DN_KeccakHash384b(input.data, input.size);
|
||||
DN_SHA3U8x48 hash = DN_KeccakHash384b(input.data, input.count);
|
||||
DN_SHA3U8x48 expect;
|
||||
DN_RefImpl_Keccak_(832, 768, DN_Cast(uint8_t *) input.data, input.size, 0x01, (uint8_t *)expect.data, sizeof(expect));
|
||||
DN_RefImpl_Keccak_(832, 768, DN_Cast(uint8_t *) input.data, input.count, 0x01, (uint8_t *)expect.data, sizeof(expect));
|
||||
|
||||
DN_Str8 hash_hex = DN_HexFromPtrBytesArena(hash.data, DN_ArrayCountU(hash.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
DN_Str8 expect_hex = DN_HexFromPtrBytesArena(expect.data, DN_ArrayCountU(expect.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
@@ -1664,9 +1664,9 @@ void DN_TST_KeccakDispatch_(DN_UTCore *test, int hash_type, DN_Str8 input)
|
||||
} break;
|
||||
|
||||
case Hash_Keccak_512: {
|
||||
DN_SHA3U8x64 hash = DN_KeccakHash512b(input.data, input.size);
|
||||
DN_SHA3U8x64 hash = DN_KeccakHash512b(input.data, input.count);
|
||||
DN_SHA3U8x64 expect;
|
||||
DN_RefImpl_Keccak_(576, 1024, DN_Cast(uint8_t *) input.data, input.size, 0x01, (uint8_t *)expect.data, sizeof(expect));
|
||||
DN_RefImpl_Keccak_(576, 1024, DN_Cast(uint8_t *) input.data, input.count, 0x01, (uint8_t *)expect.data, sizeof(expect));
|
||||
|
||||
DN_Str8 hash_hex = DN_HexFromPtrBytesArena(hash.data, DN_ArrayCountU(hash.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
DN_Str8 expect_hex = DN_HexFromPtrBytesArena(expect.data, DN_ArrayCountU(expect.data), &scratch.arena, DN_TrimLeadingZero_No);
|
||||
@@ -1701,7 +1701,7 @@ DN_UTCore DN_TST_Keccak()
|
||||
for (int hash_type = 0; hash_type < Hash_Count; hash_type++) {
|
||||
DN_PCG32 rng = DN_PCG32Init(0xd48e'be21'2af8'733d);
|
||||
for (DN_Str8 input : INPUTS) {
|
||||
DN_UT_BeginF(&result, "%.*s - Input: %.*s", DN_Str8PrintFmt(DN_UT_HASH_STRING_[hash_type]), DN_Cast(int) DN_Min(input.size, 54), input.data);
|
||||
DN_UT_BeginF(&result, "%.*s - Input: %.*s", DN_Str8PrintFmt(DN_UT_HASH_STRING_[hash_type]), DN_Cast(int) DN_Min(input.count, 54), input.data);
|
||||
DN_TST_KeccakDispatch_(&result, hash_type, input);
|
||||
DN_UT_End(&result);
|
||||
}
|
||||
@@ -1770,8 +1770,8 @@ static DN_UTCore DN_TST_OS()
|
||||
for (DN_UT_Test(&result, "Query executable directory")) {
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str8 os_result = DN_OS_EXEDir(&scratch.arena);
|
||||
DN_UT_Assert(&result, os_result.size);
|
||||
DN_UT_AssertF(&result, DN_OS_PathIsDir(os_result), "result(%zu): %.*s", os_result.size, DN_Str8PrintFmt(os_result));
|
||||
DN_UT_Assert(&result, os_result.count);
|
||||
DN_UT_AssertF(&result, DN_OS_PathIsDir(os_result), "result(%zu): %.*s", os_result.count, DN_Str8PrintFmt(os_result));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
}
|
||||
|
||||
@@ -1821,9 +1821,9 @@ static DN_UTCore DN_TST_OS()
|
||||
// NOTE: Read step
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str8 read_file = DN_OS_FileReadAllArena(&scratch.arena, SRC_FILE, nullptr);
|
||||
DN_UT_AssertF(&result, read_file.size, "Failed to load file");
|
||||
DN_UT_AssertF(&result, read_file.size == 4, "File read wrong amount of bytes (%zu)", read_file.size);
|
||||
DN_UT_AssertF(&result, DN_Str8Eq(read_file, DN_Str8Lit("1234")), "Read %zu bytes instead of the expected 4: '%.*s'", read_file.size, DN_Str8PrintFmt(read_file));
|
||||
DN_UT_AssertF(&result, read_file.count, "Failed to load file");
|
||||
DN_UT_AssertF(&result, read_file.count == 4, "File read wrong amount of bytes (%zu)", read_file.count);
|
||||
DN_UT_AssertF(&result, DN_Str8Eq(read_file, DN_Str8Lit("1234")), "Read %zu bytes instead of the expected 4: '%.*s'", read_file.count, DN_Str8PrintFmt(read_file));
|
||||
|
||||
// NOTE: Copy step
|
||||
DN_Str8 const COPY_FILE = DN_Str8Lit("dn_result_file_copy");
|
||||
@@ -2039,13 +2039,13 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
{
|
||||
for (DN_UT_Test(&result, "Str8 literal")) {
|
||||
DN_Str8 string = DN_Str8Lit("AB");
|
||||
DN_UT_AssertF(&result, string.size == 2, "size: %zu", string.size);
|
||||
DN_UT_AssertF(&result, string.count == 2, "size: %zu", string.count);
|
||||
DN_UT_AssertF(&result, string.data[0] == 'A', "string[0]: %c", string.data[0]);
|
||||
DN_UT_AssertF(&result, string.data[1] == 'B', "string[1]: %c", string.data[1]);
|
||||
}
|
||||
|
||||
for (DN_UT_Test(&result, "C-string length")) {
|
||||
DN_USize size = DN_CStr8Size("hello");
|
||||
DN_USize size = DN_CStr8Count("hello");
|
||||
DN_UT_AssertF(&result, size == 5, "size=%zu", size);
|
||||
}
|
||||
|
||||
@@ -2076,7 +2076,7 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
for (DN_UT_Test(&result, "Initialise with format string")) {
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str8 string = DN_Str8FromFmtArena(&scratch.arena, "%s", "AB");
|
||||
DN_UT_AssertF(&result, string.size == 2, "size: %zu", string.size);
|
||||
DN_UT_AssertF(&result, string.count == 2, "size: %zu", string.count);
|
||||
DN_UT_AssertF(&result, string.data[0] == 'A', "string[0]: %c", string.data[0]);
|
||||
DN_UT_AssertF(&result, string.data[1] == 'B', "string[1]: %c", string.data[1]);
|
||||
DN_UT_AssertF(&result, string.data[2] == 0, "string[2]: %c", string.data[2]);
|
||||
@@ -2087,7 +2087,7 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str8 string = DN_Str8Lit("AB");
|
||||
DN_Str8 copy = DN_Str8FromStr8Arena(string, &scratch.arena);
|
||||
DN_UT_AssertF(&result, copy.size == 2, "size: %zu", copy.size);
|
||||
DN_UT_AssertF(&result, copy.count == 2, "size: %zu", copy.count);
|
||||
DN_UT_AssertF(&result, copy.data[0] == 'A', "copy[0]: %c", copy.data[0]);
|
||||
DN_UT_AssertF(&result, copy.data[1] == 'B', "copy[1]: %c", copy.data[1]);
|
||||
DN_UT_AssertF(&result, copy.data[2] == 0, "copy[2]: %c", copy.data[2]);
|
||||
@@ -2102,7 +2102,7 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
for (DN_UT_Test(&result, "Allocate string from arena")) {
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str8 string = DN_Str8AllocArena(2, DN_ZMem_No, &scratch.arena);
|
||||
DN_UT_AssertF(&result, string.size == 2, "size: %zu", string.size);
|
||||
DN_UT_AssertF(&result, string.count == 2, "size: %zu", string.count);
|
||||
DN_TCScratchEnd(&scratch);
|
||||
}
|
||||
|
||||
@@ -2302,7 +2302,7 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
DN_UT_Assert(&result, !str_result.found);
|
||||
DN_UT_Assert(&result, str_result.index == 0);
|
||||
DN_UT_Assert(&result, str_result.match.data == nullptr);
|
||||
DN_UT_Assert(&result, str_result.match.size == 0);
|
||||
DN_UT_Assert(&result, str_result.match.count == 0);
|
||||
}
|
||||
|
||||
for (DN_UT_Test(&result, "Find: String (char) is in buffer")) {
|
||||
@@ -2343,7 +2343,7 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
char dest[64] = {};
|
||||
DN_Str8TruncResult res = DN_Str8TruncMiddlePtr(str, 5, trunc, dest, sizeof(dest));
|
||||
DN_UT_Assert(&result, !res.truncated);
|
||||
DN_UT_Assert(&result, res.size_req == 5);
|
||||
DN_UT_Assert(&result, res.count_req == 5);
|
||||
DN_UT_AssertF(&result, DN_Str8Eq(res.str8, DN_Str8Lit("Hello")), "%.*s", DN_Str8PrintFmt(res.str8));
|
||||
}
|
||||
|
||||
@@ -2353,7 +2353,7 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
char dest[64] = {};
|
||||
DN_Str8TruncResult res = DN_Str8TruncMiddlePtr(str, 5, trunc, dest, sizeof(dest));
|
||||
DN_UT_Assert(&result, !res.truncated);
|
||||
DN_UT_Assert(&result, res.size_req == 10);
|
||||
DN_UT_Assert(&result, res.count_req == 10);
|
||||
DN_UT_AssertF(&result, DN_Str8Eq(res.str8, DN_Str8Lit("HelloWorld")), "%.*s", DN_Str8PrintFmt(res.str8));
|
||||
}
|
||||
|
||||
@@ -2363,7 +2363,7 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
char dest[64] = {};
|
||||
DN_Str8TruncResult res = DN_Str8TruncMiddlePtr(str, 5, trunc, dest, sizeof(dest));
|
||||
DN_UT_Assert(&result, res.truncated);
|
||||
DN_UT_Assert(&result, res.size_req == 13); // 5 + 3 + 5
|
||||
DN_UT_Assert(&result, res.count_req == 13); // 5 + 3 + 5
|
||||
DN_UT_AssertF(&result, DN_Str8Eq(res.str8, DN_Str8Lit("Hello...World")), "%.*s", DN_Str8PrintFmt(res.str8));
|
||||
}
|
||||
|
||||
@@ -2373,7 +2373,7 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
char dest[64] = {};
|
||||
DN_Str8TruncResult res = DN_Str8TruncMiddlePtr(str, 5, trunc, dest, sizeof(dest));
|
||||
DN_UT_Assert(&result, res.truncated);
|
||||
DN_UT_Assert(&result, res.size_req == 10); // 5 + 0 + 5
|
||||
DN_UT_Assert(&result, res.count_req == 10); // 5 + 0 + 5
|
||||
DN_UT_AssertF(&result, DN_Str8Eq(res.str8, DN_Str8Lit("HelloWorld")), "%.*s", DN_Str8PrintFmt(res.str8));
|
||||
}
|
||||
|
||||
@@ -2383,7 +2383,7 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
char dest[64] = {};
|
||||
DN_Str8TruncResult res = DN_Str8TruncMiddlePtr(str, 0, trunc, dest, sizeof(dest));
|
||||
DN_UT_Assert(&result, res.truncated);
|
||||
DN_UT_Assert(&result, res.size_req == 3);
|
||||
DN_UT_Assert(&result, res.count_req == 3);
|
||||
DN_UT_AssertF(&result, DN_Str8Eq(res.str8, DN_Str8Lit("...")), "%.*s", DN_Str8PrintFmt(res.str8));
|
||||
}
|
||||
|
||||
@@ -2392,17 +2392,17 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
DN_Str8 trunc = DN_Str8Lit("...");
|
||||
DN_Str8TruncResult res = DN_Str8TruncMiddlePtr(str, 5, trunc, nullptr, 0);
|
||||
DN_UT_Assert(&result, res.truncated);
|
||||
DN_UT_Assert(&result, res.size_req == 13);
|
||||
DN_UT_Assert(&result, res.count_req == 13);
|
||||
DN_UT_Assert(&result, res.str8.data == nullptr);
|
||||
}
|
||||
|
||||
for (DN_UT_Test(&result, "TruncMiddlePtr: size_req is consistent between dry-run and actual")) {
|
||||
for (DN_UT_Test(&result, "TruncMiddlePtr: count_req is consistent between dry-run and actual")) {
|
||||
DN_Str8 str = DN_Str8Lit("HelloBeautifulWorld");
|
||||
DN_Str8 trunc = DN_Str8Lit("...");
|
||||
DN_Str8TruncResult dry = DN_Str8TruncMiddlePtr(str, 5, trunc, nullptr, 0);
|
||||
char dest[64] = {};
|
||||
DN_Str8TruncResult actual = DN_Str8TruncMiddlePtr(str, 5, trunc, dest, sizeof(dest));
|
||||
DN_UT_Assert(&result, dry.size_req == actual.size_req);
|
||||
DN_UT_Assert(&result, dry.count_req == actual.count_req);
|
||||
DN_UT_Assert(&result, dry.truncated == actual.truncated);
|
||||
}
|
||||
|
||||
@@ -2412,7 +2412,7 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
char dest[14] = {}; // Exactly 2*5 + 3 + 1
|
||||
DN_Str8TruncResult res = DN_Str8TruncMiddlePtr(str, 5, trunc, dest, sizeof(dest));
|
||||
DN_UT_Assert(&result, res.truncated);
|
||||
DN_UT_Assert(&result, res.size_req == 13);
|
||||
DN_UT_Assert(&result, res.count_req == 13);
|
||||
DN_UT_AssertF(&result, DN_Str8Eq(res.str8, DN_Str8Lit("Hello...World")), "%.*s", DN_Str8PrintFmt(res.str8));
|
||||
}
|
||||
|
||||
@@ -2422,7 +2422,7 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
char dest[64] = {};
|
||||
DN_Str8TruncResult res = DN_Str8TruncMiddlePtr(str, 1, trunc, dest, sizeof(dest));
|
||||
DN_UT_Assert(&result, res.truncated);
|
||||
DN_UT_Assert(&result, res.size_req == 5); // 1 + 3 + 1
|
||||
DN_UT_Assert(&result, res.count_req == 5); // 1 + 3 + 1
|
||||
DN_UT_AssertF(&result, DN_Str8Eq(res.str8, DN_Str8Lit("H...d")), "%.*s", DN_Str8PrintFmt(res.str8));
|
||||
}
|
||||
|
||||
@@ -2432,7 +2432,7 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
char dest[64] = {};
|
||||
DN_Str8TruncResult res = DN_Str8TruncMiddlePtr(str, 100, trunc, dest, sizeof(dest));
|
||||
DN_UT_Assert(&result, !res.truncated);
|
||||
DN_UT_Assert(&result, res.size_req == 5);
|
||||
DN_UT_Assert(&result, res.count_req == 5);
|
||||
DN_UT_AssertF(&result, DN_Str8Eq(res.str8, DN_Str8Lit("Hello")), "%.*s", DN_Str8PrintFmt(res.str8));
|
||||
}
|
||||
|
||||
@@ -2443,9 +2443,9 @@ static DN_UTCore DN_TST_BaseStrings()
|
||||
DN_Str8 trunc = DN_Str8Lit("...");
|
||||
DN_Str8TruncResult res = DN_Str8TruncMiddle(str, 5, trunc, &scratch.arena);
|
||||
DN_UT_Assert(&result, res.truncated);
|
||||
DN_UT_Assert(&result, res.size_req == 13);
|
||||
DN_UT_Assert(&result, res.count_req == 13);
|
||||
DN_UT_AssertF(&result, DN_Str8Eq(res.str8, DN_Str8Lit("Hello...World")), "%.*s", DN_Str8PrintFmt(res.str8));
|
||||
DN_UT_Assert(&result, res.str8.data[res.str8.size] == '\0');
|
||||
DN_UT_Assert(&result, res.str8.data[res.str8.count] == '\0');
|
||||
DN_TCScratchEnd(&scratch);
|
||||
}
|
||||
}
|
||||
@@ -2493,8 +2493,8 @@ static DN_UTCore DN_TST_Win()
|
||||
int size_returned = DN_OS_W32Str16ToStr8Buffer(input16, nullptr, 0);
|
||||
char const EXPECTED[] = {'S', 't', 'r', 'i', 'n', 'g', 0};
|
||||
|
||||
DN_UT_AssertF(&result, DN_Cast(int) string8.size == size_returned, "string_size: %d, result: %d", DN_Cast(int) string8.size, size_returned);
|
||||
DN_UT_AssertF(&result, DN_Cast(int) string8.size == DN_ArrayCountU(EXPECTED) - 1, "string_size: %d, expected: %zu", DN_Cast(int) string8.size, DN_ArrayCountU(EXPECTED) - 1);
|
||||
DN_UT_AssertF(&result, DN_Cast(int) string8.count == size_returned, "string_size: %d, result: %d", DN_Cast(int) string8.count, size_returned);
|
||||
DN_UT_AssertF(&result, DN_Cast(int) string8.count == DN_ArrayCountU(EXPECTED) - 1, "string_size: %d, expected: %zu", DN_Cast(int) string8.count, DN_ArrayCountU(EXPECTED) - 1);
|
||||
DN_UT_Assert(&result, DN_Memcmp(EXPECTED, string8.data, sizeof(EXPECTED)) == 0);
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
@@ -2517,7 +2517,7 @@ static DN_UTCore DN_TST_Net()
|
||||
label = DN_Str8Lit("CURL");
|
||||
#endif
|
||||
|
||||
if (label.size) {
|
||||
if (label.count) {
|
||||
DN_UT_LogF(&result, "DN_NET\n");
|
||||
|
||||
DN_MemList mem = DN_MemListFromHeap(DN_Megabytes(4), DN_MemFlags_Nil);
|
||||
@@ -2536,8 +2536,8 @@ static DN_UTCore DN_TST_Net()
|
||||
DN_NETResponse response = net_interface.wait_for_response(request, &arena, UINT32_MAX);
|
||||
DN_UT_AssertF(&result, response.http_status == 200, "http_status=%u", response.http_status);
|
||||
DN_UT_AssertF(&result, response.state == DN_NETResponseState_HTTP, "state=%u", response.state);
|
||||
DN_UT_AssertF(&result, response.error_str8.size == 0, "%.*s", DN_Str8PrintFmt(response.error_str8));
|
||||
DN_UT_Assert(&result, response.body.size);
|
||||
DN_UT_AssertF(&result, response.error_str8.count == 0, "%.*s", DN_Str8PrintFmt(response.error_str8));
|
||||
DN_UT_Assert(&result, response.body.count);
|
||||
}
|
||||
|
||||
for (DN_UT_Test(&result, "%.*s WaitForResponse HTTP POST request", DN_Str8PrintFmt(label))) {
|
||||
@@ -2545,8 +2545,8 @@ static DN_UTCore DN_TST_Net()
|
||||
DN_NETResponse response = net_interface.wait_for_any_response(&net, &arena, UINT32_MAX);
|
||||
DN_UT_AssertF(&result, response.http_status == 200, "http_status=%u", response.http_status);
|
||||
DN_UT_AssertF(&result, response.state == DN_NETResponseState_HTTP, "state=%u", response.state);
|
||||
DN_UT_AssertF(&result, response.error_str8.size == 0, "error=%.*s", DN_Str8PrintFmt(response.error_str8));
|
||||
DN_UT_Assert(&result, response.body.size);
|
||||
DN_UT_AssertF(&result, response.error_str8.count == 0, "error=%.*s", DN_Str8PrintFmt(response.error_str8));
|
||||
DN_UT_Assert(&result, response.body.count);
|
||||
}
|
||||
|
||||
for (DN_UT_Test(&result, "%.*s WaitForResponse WS request", DN_Str8PrintFmt(label))) {
|
||||
|
||||
+19
-19
@@ -441,7 +441,7 @@ DN_API DN_OSFile DN_OS_FileOpen(DN_Str8 path,
|
||||
DN_ErrSink *error)
|
||||
{
|
||||
DN_OSFile result = {};
|
||||
if (path.size == 0 || path.size <= 0)
|
||||
if (path.count == 0 || path.count <= 0)
|
||||
return result;
|
||||
|
||||
if ((access & ~(DN_OSFileAccess_All) || ((access & DN_OSFileAccess_All) == 0))) {
|
||||
@@ -568,7 +568,7 @@ DN_API void DN_OS_FileClose(DN_OSFile *file)
|
||||
DN_API DN_OSPathInfo DN_OS_PathInfo(DN_Str8 path)
|
||||
{
|
||||
DN_OSPathInfo result = {};
|
||||
if (path.size == 0)
|
||||
if (path.count == 0)
|
||||
return result;
|
||||
|
||||
struct stat file_stat;
|
||||
@@ -592,7 +592,7 @@ DN_API DN_OSPathInfo DN_OS_PathInfo(DN_Str8 path)
|
||||
DN_API bool DN_OS_PathDelete(DN_Str8 path)
|
||||
{
|
||||
bool result = false;
|
||||
if (path.size)
|
||||
if (path.count)
|
||||
result = remove(path.data) == 0;
|
||||
return result;
|
||||
}
|
||||
@@ -600,7 +600,7 @@ DN_API bool DN_OS_PathDelete(DN_Str8 path)
|
||||
DN_API bool DN_OS_PathIsFile(DN_Str8 path)
|
||||
{
|
||||
bool result = false;
|
||||
if (path.size == 0)
|
||||
if (path.count == 0)
|
||||
return result;
|
||||
|
||||
struct stat stat_result;
|
||||
@@ -612,7 +612,7 @@ DN_API bool DN_OS_PathIsFile(DN_Str8 path)
|
||||
DN_API bool DN_OS_PathIsDir(DN_Str8 path)
|
||||
{
|
||||
bool result = false;
|
||||
if (path.size == 0)
|
||||
if (path.count == 0)
|
||||
return result;
|
||||
|
||||
struct stat stat_result;
|
||||
@@ -632,8 +632,8 @@ DN_API bool DN_OS_PathMakeDir(DN_Str8 path)
|
||||
uint16_t path_indexes[64] = {};
|
||||
|
||||
DN_Str8 copy = DN_Str8FromStr8Arena(path, &scratch.arena);
|
||||
for (DN_USize index = copy.size - 1; index < copy.size; index--) {
|
||||
bool first_char = index == (copy.size - 1);
|
||||
for (DN_USize index = copy.count - 1; index < copy.count; index--) {
|
||||
bool first_char = index == (copy.count - 1);
|
||||
char ch = copy.data[index];
|
||||
if (ch == '/' || first_char) {
|
||||
char temp = copy.data[index];
|
||||
@@ -696,12 +696,12 @@ DN_API bool DN_OS_PathIterateDir(DN_Str8 path, DN_OSDirIterator *it)
|
||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
DN_USize name_size = DN_CStr8Size(entry->d_name);
|
||||
DN_USize clamped_size = DN_Min(sizeof(it->buffer) - 1, name_size);
|
||||
DN_AssertF(name_size == clamped_size, "name: %s, name_size: %zu, clamped_size: %zu", entry->d_name, name_size, clamped_size);
|
||||
DN_Memcpy(it->buffer, entry->d_name, clamped_size);
|
||||
it->buffer[clamped_size] = 0;
|
||||
it->file_name = DN_Str8FromPtr(it->buffer, clamped_size);
|
||||
DN_USize name_count = DN_CStr8Count(entry->d_name);
|
||||
DN_USize clamped_count = DN_Min(sizeof(it->buffer) - 1, name_count);
|
||||
DN_AssertF(name_count == clamped_count, "name: %s, name_size: %zu, clamped_size: %zu", entry->d_name, name_count, clamped_count);
|
||||
DN_Memcpy(it->buffer, entry->d_name, clamped_count);
|
||||
it->buffer[clamped_count] = 0;
|
||||
it->file_name = DN_Str8FromPtr(it->buffer, clamped_count);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -962,7 +962,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line,
|
||||
free(prev_working_dir);
|
||||
};
|
||||
|
||||
if (args->working_dir.size) {
|
||||
if (args->working_dir.count) {
|
||||
prev_working_dir = get_current_dir_name();
|
||||
DN_Str8 working_dir = DN_Str8FromStr8Arena(args->working_dir, &scratch.arena);
|
||||
if (chdir(working_dir.data) == -1) {
|
||||
@@ -1410,23 +1410,23 @@ DN_API DN_OSPosixProcSelfStatus DN_OS_PosixProcSelfStatus()
|
||||
for (DN_ForItSize(line_it, DN_Str8, lines.data, lines.count)) {
|
||||
DN_Str8 line = DN_Str8TrimWhitespaceAround(*line_it.data);
|
||||
if (DN_Str8StartsWith(line, NAME, DN_Str8EqCase_Insensitive)) {
|
||||
DN_Str8 str8 = DN_Str8TrimWhitespaceAround(DN_Str8Subset(line, NAME.size, line.size));
|
||||
result.name_size = DN_Min(str8.size, sizeof(result.name));
|
||||
DN_Str8 str8 = DN_Str8TrimWhitespaceAround(DN_Str8Subset(line, NAME.count, line.count));
|
||||
result.name_size = DN_Min(str8.count, sizeof(result.name));
|
||||
DN_Memcpy(result.name, str8.data, result.name_size);
|
||||
} else if (DN_Str8StartsWith(line, PID, DN_Str8EqCase_Insensitive)) {
|
||||
DN_Str8 str8 = DN_Str8TrimWhitespaceAround(DN_Str8Subset(line, PID.size, line.size));
|
||||
DN_Str8 str8 = DN_Str8TrimWhitespaceAround(DN_Str8Subset(line, PID.count, line.count));
|
||||
DN_U64FromResult to_u64 = DN_U64FromStr8(str8, 0);
|
||||
result.pid = to_u64.value;
|
||||
DN_Assert(to_u64.success);
|
||||
} else if (DN_Str8StartsWith(line, VM_SIZE, DN_Str8EqCase_Insensitive)) {
|
||||
DN_Str8 size_with_kb = DN_Str8TrimWhitespaceAround(DN_Str8Subset(line, VM_SIZE.size, line.size));
|
||||
DN_Str8 size_with_kb = DN_Str8TrimWhitespaceAround(DN_Str8Subset(line, VM_SIZE.count, line.count));
|
||||
DN_Assert(DN_Str8EndsWith(size_with_kb, DN_Str8Lit("kB")));
|
||||
DN_Str8 vm_size = DN_Str8BSplit(size_with_kb, DN_Str8Lit(" ")).lhs;
|
||||
DN_U64FromResult to_u64 = DN_U64FromStr8(vm_size, 0);
|
||||
result.vm_size = DN_Kilobytes(to_u64.value);
|
||||
DN_Assert(to_u64.success);
|
||||
} else if (DN_Str8StartsWith(line, VM_PEAK, DN_Str8EqCase_Insensitive)) {
|
||||
DN_Str8 size_with_kb = DN_Str8TrimWhitespaceAround(DN_Str8Subset(line, VM_PEAK.size, line.size));
|
||||
DN_Str8 size_with_kb = DN_Str8TrimWhitespaceAround(DN_Str8Subset(line, VM_PEAK.count, line.count));
|
||||
DN_Assert(DN_Str8EndsWith(size_with_kb, DN_Str8Lit("kB")));
|
||||
DN_Str8 vm_size = DN_Str8BSplit(size_with_kb, DN_Str8Lit(" ")).lhs;
|
||||
DN_U64FromResult to_u64 = DN_U64FromStr8(vm_size, 0);
|
||||
|
||||
+54
-54
@@ -336,7 +336,7 @@ DN_API bool DN_OS_FileMove(DN_Str8 src, DN_Str8 dest, bool overwrite, DN_ErrSink
|
||||
DN_API DN_OSFile DN_OS_FileOpen(DN_Str8 path, DN_OSFileOpen open_mode, DN_OSFileAccess access, DN_ErrSink *err)
|
||||
{
|
||||
DN_OSFile result = {};
|
||||
if (path.size == 0 || path.size <= 0)
|
||||
if (path.count == 0 || path.count <= 0)
|
||||
return result;
|
||||
|
||||
if ((access & ~DN_OSFileAccess_All) || ((access & DN_OSFileAccess_All) == 0)) {
|
||||
@@ -486,7 +486,7 @@ DN_API void DN_OS_FileClose(DN_OSFile *file)
|
||||
DN_API DN_OSPathInfo DN_OS_PathInfo(DN_Str8 path)
|
||||
{
|
||||
DN_OSPathInfo result = {};
|
||||
if (path.size == 0)
|
||||
if (path.count == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
@@ -522,12 +522,12 @@ DN_API DN_OSPathInfo DN_OS_PathInfo(DN_Str8 path)
|
||||
DN_API bool DN_OS_PathDelete(DN_Str8 path)
|
||||
{
|
||||
bool result = false;
|
||||
if (path.size == 0)
|
||||
if (path.count == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
if (path16.size) {
|
||||
if (path16.count) {
|
||||
result = DeleteFileW(path16.data);
|
||||
if (!result)
|
||||
result = RemoveDirectoryW(path16.data);
|
||||
@@ -539,12 +539,12 @@ DN_API bool DN_OS_PathDelete(DN_Str8 path)
|
||||
DN_API bool DN_OS_PathIsFile(DN_Str8 path)
|
||||
{
|
||||
bool result = false;
|
||||
if (path.size == 0)
|
||||
if (path.count == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
if (path16.size) {
|
||||
if (path16.count) {
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrib_data = {};
|
||||
if (GetFileAttributesExW(path16.data, GetFileExInfoStandard, &attrib_data))
|
||||
result = (attrib_data.dwFileAttributes != INVALID_FILE_ATTRIBUTES) &&
|
||||
@@ -557,12 +557,12 @@ DN_API bool DN_OS_PathIsFile(DN_Str8 path)
|
||||
DN_API bool DN_OS_PathIsDir(DN_Str8 path)
|
||||
{
|
||||
bool result = false;
|
||||
if (path.size == 0)
|
||||
if (path.count == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
if (path16.size) {
|
||||
if (path16.count) {
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrib_data = {};
|
||||
if (GetFileAttributesExW(path16.data, GetFileExInfoStandard, &attrib_data))
|
||||
result = (attrib_data.dwFileAttributes != INVALID_FILE_ATTRIBUTES) &&
|
||||
@@ -591,8 +591,8 @@ DN_API bool DN_OS_PathMakeDir(DN_Str8 path)
|
||||
// If we find a file at some point in the path we fail out because the
|
||||
// series of directories can not be made if a file exists with the same
|
||||
// name.
|
||||
for (DN_USize index = 0; index < path16.size; index++) {
|
||||
bool first_char = index == (path16.size - 1);
|
||||
for (DN_USize index = 0; index < path16.count; index++) {
|
||||
bool first_char = index == (path16.count - 1);
|
||||
wchar_t ch = path16.data[index];
|
||||
if (ch == '/' || ch == '\\' || first_char) {
|
||||
wchar_t temp = path16.data[index];
|
||||
@@ -628,7 +628,7 @@ DN_API bool DN_OS_PathMakeDir(DN_Str8 path)
|
||||
|
||||
DN_API bool DN_OS_PathIterateDir(DN_Str8 path, DN_OSDirIterator *it)
|
||||
{
|
||||
if (path.size == 0 || !it || path.size <= 0)
|
||||
if (path.count == 0 || !it || path.count <= 0)
|
||||
return false;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
@@ -654,7 +654,7 @@ DN_API bool DN_OS_PathIterateDir(DN_Str8 path, DN_OSDirIterator *it)
|
||||
}
|
||||
|
||||
path16 = DN_OS_W32Str8ToStr16(&scratch.arena, adjusted_path);
|
||||
if (path16.size <= 0) { // Conversion error
|
||||
if (path16.count <= 0) { // Conversion error
|
||||
DN_TCScratchEnd(&scratch);
|
||||
return false;
|
||||
}
|
||||
@@ -836,7 +836,7 @@ DN_API DN_OSExecResult DN_OS_ExecWait(DN_OSExecAsyncHandle handle, DN_Arena *are
|
||||
result = DN_OS_ExecPump(handle, stdout_buffer, &stdout_size, stderr_buffer, &stderr_size, wait_ms, err);
|
||||
DN_Str8BuilderAppendCopy(&stdout_builder, result.stdout_text);
|
||||
DN_Str8BuilderAppendCopy(&stderr_builder, result.stderr_text);
|
||||
wait_ms = (result.stdout_text.size || result.stderr_text.size) ? FAST_WAIT_TIME_MS : SLOW_WAIT_TIME_MS;
|
||||
wait_ms = (result.stdout_text.count || result.stderr_text.count) ? FAST_WAIT_TIME_MS : SLOW_WAIT_TIME_MS;
|
||||
}
|
||||
|
||||
// NOTE: Get stdout/stderr. If no arena is passed this is a no-op
|
||||
@@ -865,7 +865,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
|
||||
DN_Str8 env_block8 = DN_Str8FromStr8BuilderDelimitArena(&env_builder, DN_Str8Lit("\0"), &scratch.arena);
|
||||
DN_Str16 env_block16 = {};
|
||||
if (env_block8.size)
|
||||
if (env_block8.count)
|
||||
env_block16 = DN_OS_W32Str8ToStr16(&scratch.arena, env_block8);
|
||||
|
||||
// NOTE: Stdout/err security attributes
|
||||
@@ -1346,7 +1346,7 @@ DN_API DN_Str16 DN_OS_W32ErrorCodeToMsg16Alloc(DN_U32 error_code)
|
||||
}
|
||||
|
||||
wchar_t *result16 = nullptr;
|
||||
DWORD size = FormatMessageW(/*DWORD dwFlags */ flags | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||
DWORD count = FormatMessageW(/*DWORD dwFlags */ flags | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||
/*LPCVOID lpSource */ module_to_get_errors_from,
|
||||
/*DWORD dwMessageId */ error_code,
|
||||
/*DWORD dwLanguageId*/ 0,
|
||||
@@ -1356,7 +1356,7 @@ DN_API DN_Str16 DN_OS_W32ErrorCodeToMsg16Alloc(DN_U32 error_code)
|
||||
|
||||
DN_Str16 result = {};
|
||||
result.data = result16;
|
||||
result.size = size;
|
||||
result.count = count;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1365,7 +1365,7 @@ DN_API DN_OSW32Error DN_OS_W32ErrorCodeToMsgAlloc(DN_U32 error_code)
|
||||
DN_OSW32Error result = {};
|
||||
result.code = error_code;
|
||||
DN_Str16 error16 = DN_OS_W32ErrorCodeToMsg16Alloc(error_code);
|
||||
if (error16.size)
|
||||
if (error16.count)
|
||||
result.msg = DN_OS_W32Str16ToStr8FromHeap(error16);
|
||||
if (error16.data)
|
||||
LocalFree(error16.data);
|
||||
@@ -1378,7 +1378,7 @@ DN_API DN_OSW32Error DN_OS_W32ErrorCodeToMsg(DN_Arena *arena, DN_U32 error_code)
|
||||
result.code = error_code;
|
||||
if (arena) {
|
||||
DN_Str16 error16 = DN_OS_W32ErrorCodeToMsg16Alloc(error_code);
|
||||
if (error16.size)
|
||||
if (error16.count)
|
||||
result.msg = DN_OS_W32Str16ToStr8(arena, error16);
|
||||
if (error16.data)
|
||||
LocalFree(error16.data);
|
||||
@@ -1423,10 +1423,10 @@ DN_API void DN_OS_W32MakeProcessDPIAware()
|
||||
DN_API DN_Str16 DN_OS_W32Str8ToStr16(DN_Arena *arena, DN_Str8 src)
|
||||
{
|
||||
DN_Str16 result = {};
|
||||
if (!arena || src.size == 0)
|
||||
if (!arena || src.count == 0)
|
||||
return result;
|
||||
|
||||
int required_size = MultiByteToWideChar(CP_UTF8, 0 /*dwFlags*/, src.data, DN_Cast(int) src.size, nullptr /*dest*/, 0 /*dest size*/);
|
||||
int required_size = MultiByteToWideChar(CP_UTF8, 0 /*dwFlags*/, src.data, DN_Cast(int) src.count, nullptr /*dest*/, 0 /*dest size*/);
|
||||
if (required_size <= 0)
|
||||
return result;
|
||||
|
||||
@@ -1434,12 +1434,12 @@ DN_API DN_Str16 DN_OS_W32Str8ToStr16(DN_Arena *arena, DN_Str8 src)
|
||||
if (!buffer)
|
||||
return result;
|
||||
|
||||
int chars_written = MultiByteToWideChar(CP_UTF8, 0 /*dwFlags*/, src.data, DN_Cast(int) src.size, buffer, required_size);
|
||||
int chars_written = MultiByteToWideChar(CP_UTF8, 0 /*dwFlags*/, src.data, DN_Cast(int) src.count, buffer, required_size);
|
||||
DN_Assert(chars_written == required_size);
|
||||
if (chars_written == required_size) {
|
||||
result.data = buffer;
|
||||
result.size = chars_written;
|
||||
result.data[result.size] = 0;
|
||||
result.count = chars_written;
|
||||
result.data[result.count] = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1447,14 +1447,14 @@ DN_API DN_Str16 DN_OS_W32Str8ToStr16(DN_Arena *arena, DN_Str8 src)
|
||||
DN_API int DN_OS_W32Str8ToStr16Buffer(DN_Str8 src, wchar_t *dest, int dest_size)
|
||||
{
|
||||
int result = 0;
|
||||
if (src.size == 0)
|
||||
if (src.count == 0)
|
||||
return result;
|
||||
|
||||
result = MultiByteToWideChar(CP_UTF8, 0 /*dwFlags*/, src.data, DN_Cast(int) src.size, nullptr /*dest*/, 0 /*dest size*/);
|
||||
result = MultiByteToWideChar(CP_UTF8, 0 /*dwFlags*/, src.data, DN_Cast(int) src.count, nullptr /*dest*/, 0 /*dest size*/);
|
||||
if (result <= 0 || result > dest_size || !dest)
|
||||
return result;
|
||||
|
||||
result = MultiByteToWideChar(CP_UTF8, 0 /*dwFlags*/, src.data, DN_Cast(int) src.size, dest, DN_Cast(int) dest_size);
|
||||
result = MultiByteToWideChar(CP_UTF8, 0 /*dwFlags*/, src.data, DN_Cast(int) src.count, dest, DN_Cast(int) dest_size);
|
||||
dest[DN_Min(result, dest_size - 1)] = 0;
|
||||
return result;
|
||||
}
|
||||
@@ -1462,10 +1462,10 @@ DN_API int DN_OS_W32Str8ToStr16Buffer(DN_Str8 src, wchar_t *dest, int dest_size)
|
||||
DN_API int DN_OS_W32Str16ToStr8Buffer(DN_Str16 src, char *dest, int dest_size)
|
||||
{
|
||||
int result = 0;
|
||||
if (src.size == 0)
|
||||
if (src.count == 0)
|
||||
return result;
|
||||
|
||||
int src_size = DN_SaturateCastISizeToInt(src.size);
|
||||
int src_size = DN_SaturateCastISizeToInt(src.count);
|
||||
if (src_size <= 0)
|
||||
return result;
|
||||
|
||||
@@ -1481,10 +1481,10 @@ DN_API int DN_OS_W32Str16ToStr8Buffer(DN_Str16 src, char *dest, int dest_size)
|
||||
DN_API DN_Str8 DN_OS_W32Str16ToStr8(DN_Arena *arena, DN_Str16 src)
|
||||
{
|
||||
DN_Str8 result = {};
|
||||
if (!arena || src.size == 0)
|
||||
if (!arena || src.count == 0)
|
||||
return result;
|
||||
|
||||
int src_size = DN_SaturateCastISizeToInt(src.size);
|
||||
int src_size = DN_SaturateCastISizeToInt(src.count);
|
||||
if (src_size <= 0)
|
||||
return result;
|
||||
|
||||
@@ -1496,25 +1496,25 @@ DN_API DN_Str8 DN_OS_W32Str16ToStr8(DN_Arena *arena, DN_Str16 src)
|
||||
// null-termination already so no-need to +1 the required size
|
||||
DN_Arena temp = DN_ArenaTempBeginFromArena(arena);
|
||||
DN_Str8 buffer = DN_Str8AllocArena(required_size, DN_ZMem_No, &temp);
|
||||
if (buffer.size) {
|
||||
int chars_written = WideCharToMultiByte(CP_UTF8, 0 /*dwFlags*/, src.data, src_size, buffer.data, DN_Cast(int) buffer.size, nullptr, nullptr);
|
||||
if (buffer.count) {
|
||||
int chars_written = WideCharToMultiByte(CP_UTF8, 0 /*dwFlags*/, src.data, src_size, buffer.data, DN_Cast(int) buffer.count, nullptr, nullptr);
|
||||
DN_Assert(chars_written == required_size);
|
||||
if (chars_written == required_size) {
|
||||
result = buffer;
|
||||
result.data[result.size] = 0;
|
||||
result.data[result.count] = 0;
|
||||
}
|
||||
}
|
||||
DN_ArenaTempEnd(&temp, result.size == DN_Cast(DN_USize)required_size ? DN_ArenaReset_No : DN_ArenaReset_Yes);
|
||||
DN_ArenaTempEnd(&temp, result.count == DN_Cast(DN_USize)required_size ? DN_ArenaReset_No : DN_ArenaReset_Yes);
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_API DN_Str8 DN_OS_W32Str16ToStr8FromHeap(DN_Str16 src)
|
||||
{
|
||||
DN_Str8 result = {};
|
||||
if (src.size == 0)
|
||||
if (src.count == 0)
|
||||
return result;
|
||||
|
||||
int src_size = DN_SaturateCastISizeToInt(src.size);
|
||||
int src_size = DN_SaturateCastISizeToInt(src.count);
|
||||
if (src_size <= 0)
|
||||
return result;
|
||||
|
||||
@@ -1525,14 +1525,14 @@ DN_API DN_Str8 DN_OS_W32Str16ToStr8FromHeap(DN_Str16 src)
|
||||
// NOTE: Str8 allocate ensures there's one extra byte for
|
||||
// null-termination already so no-need to +1 the required size
|
||||
DN_Str8 buffer = DN_Str8FromHeap(required_size, DN_ZMem_No);
|
||||
if (buffer.size == 0)
|
||||
if (buffer.count == 0)
|
||||
return result;
|
||||
|
||||
int chars_written = WideCharToMultiByte(CP_UTF8, 0 /*dwFlags*/, src.data, src_size, buffer.data, DN_Cast(int) buffer.size, nullptr, nullptr);
|
||||
int chars_written = WideCharToMultiByte(CP_UTF8, 0 /*dwFlags*/, src.data, src_size, buffer.data, DN_Cast(int) buffer.count, nullptr, nullptr);
|
||||
DN_Assert(chars_written == required_size);
|
||||
if (chars_written == required_size) {
|
||||
result = buffer;
|
||||
result.data[result.size] = 0;
|
||||
result.data[result.count] = 0;
|
||||
} else {
|
||||
DN_OS_MemDealloc(buffer.data);
|
||||
buffer = {};
|
||||
@@ -1563,9 +1563,9 @@ DN_API DN_Str16 DN_OS_W32EXEPathW(DN_Arena *arena)
|
||||
index_of_last_slash = module_path[index] == '\\' ? index : 0;
|
||||
|
||||
result.data = DN_ArenaNewArray(arena, wchar_t, module_size + 1, DN_ZMem_No);
|
||||
result.size = module_size;
|
||||
DN_Memcpy(result.data, module_path, sizeof(wchar_t) * result.size);
|
||||
result.data[result.size] = 0;
|
||||
result.count = module_size;
|
||||
DN_Memcpy(result.data, module_path, sizeof(wchar_t) * result.count);
|
||||
result.data[result.count] = 0;
|
||||
DN_TCScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
@@ -1592,9 +1592,9 @@ DN_API DN_Str16 DN_OS_W32EXEDirW(DN_Arena *arena)
|
||||
index_of_last_slash = module_path[index] == '\\' ? index : 0;
|
||||
|
||||
result.data = DN_ArenaNewArray(arena, wchar_t, index_of_last_slash + 1, DN_ZMem_No);
|
||||
result.size = index_of_last_slash;
|
||||
DN_Memcpy(result.data, module_path, sizeof(wchar_t) * result.size);
|
||||
result.data[result.size] = 0;
|
||||
result.count = index_of_last_slash;
|
||||
DN_Memcpy(result.data, module_path, sizeof(wchar_t) * result.count);
|
||||
result.data[result.count] = 0;
|
||||
DN_TCScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
@@ -1611,13 +1611,13 @@ DN_API DN_Str8 DN_OS_W32WorkingDir(DN_Arena *arena, DN_Str8 suffix)
|
||||
|
||||
DN_API DN_Str16 DN_OS_W32WorkingDirW(DN_Arena *arena, DN_Str16 suffix)
|
||||
{
|
||||
DN_Assert(suffix.size >= 0);
|
||||
DN_Assert(suffix.count >= 0);
|
||||
DN_Str16 result = {};
|
||||
|
||||
// NOTE: required_size is the size required *including* the null-terminator
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
unsigned long required_size = GetCurrentDirectoryW(0, nullptr);
|
||||
unsigned long desired_size = required_size + DN_Cast(unsigned long) suffix.size;
|
||||
unsigned long desired_size = required_size + DN_Cast(unsigned long) suffix.count;
|
||||
|
||||
wchar_t *scratch_w_path = DN_ArenaNewArray(&scratch.arena, wchar_t, desired_size, DN_ZMem_No);
|
||||
if (!scratch_w_path) {
|
||||
@@ -1638,9 +1638,9 @@ DN_API DN_Str16 DN_OS_W32WorkingDirW(DN_Arena *arena, DN_Str16 suffix)
|
||||
return result;
|
||||
}
|
||||
|
||||
if (suffix.size) {
|
||||
if (suffix.count) {
|
||||
DN_Memcpy(w_path, scratch_w_path, sizeof(*scratch_w_path) * bytes_written_wo_null_terminator);
|
||||
DN_Memcpy(w_path + bytes_written_wo_null_terminator, suffix.data, sizeof(suffix.data[0]) * suffix.size);
|
||||
DN_Memcpy(w_path + bytes_written_wo_null_terminator, suffix.data, sizeof(suffix.data[0]) * suffix.count);
|
||||
w_path[desired_size] = 0;
|
||||
}
|
||||
|
||||
@@ -1676,14 +1676,14 @@ DN_API bool DN_OS_W32DirWIterate(DN_Str16 path, DN_OSW32FolderIteratorW *it)
|
||||
if (find_data.cFileName[0] == '.' || (find_data.cFileName[0] == '.' && find_data.cFileName[1] == '.'))
|
||||
continue;
|
||||
|
||||
it->file_name.size = DN_CStr16Size(find_data.cFileName);
|
||||
DN_Assert(it->file_name.size < (DN_ArrayCountU(it->file_name_buf) - 1));
|
||||
DN_Memcpy(it->file_name.data, find_data.cFileName, it->file_name.size * sizeof(wchar_t));
|
||||
it->file_name_buf[it->file_name.size] = 0;
|
||||
it->file_name.count = DN_CStr16Count(find_data.cFileName);
|
||||
DN_Assert(it->file_name.count < (DN_ArrayCountU(it->file_name_buf) - 1));
|
||||
DN_Memcpy(it->file_name.data, find_data.cFileName, it->file_name.count * sizeof(wchar_t));
|
||||
it->file_name_buf[it->file_name.count] = 0;
|
||||
break;
|
||||
} while (FindNextFileW(it->handle, &find_data) != 0);
|
||||
|
||||
bool result = it->file_name.size > 0;
|
||||
bool result = it->file_name.count > 0;
|
||||
if (!result)
|
||||
FindClose(it->handle);
|
||||
return result;
|
||||
|
||||
+61
-61
@@ -41,7 +41,7 @@ DN_INIStr8 DN_INI_Str8FromPtr(char const *data, size_t count)
|
||||
{
|
||||
DN_INIStr8 result = {};
|
||||
result.data = (char *)data;
|
||||
result.size = count;
|
||||
result.count = count;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -82,20 +82,20 @@ DN_INIStr8FromResult DN_INI_Str8FromINI(DN_INICore const *ini, char *buffer, siz
|
||||
if (it != &ini->first_section) {
|
||||
DN_INI_Str8BuilderAppend_(&builder, "[");
|
||||
for (DN_INISection *parent = it->parent; parent; parent = parent->parent)
|
||||
if (parent->name.size)
|
||||
if (parent->name.count)
|
||||
parent_stack[parent_stack_count++] = parent;
|
||||
for (size_t index = parent_stack_count - 1; index < parent_stack_count; index--) {
|
||||
DN_INISection *parent = parent_stack[index];
|
||||
DN_INI_Str8BuilderAppend_(&builder, "%.*s.", (int)parent->name.size, parent->name.data);
|
||||
DN_INI_Str8BuilderAppend_(&builder, "%.*s.", (int)parent->name.count, parent->name.data);
|
||||
}
|
||||
parent_stack_count = 0;
|
||||
DN_INI_Str8BuilderAppend_(&builder, "%.*s]\n", (int)it->name.size, it->name.data);
|
||||
DN_INI_Str8BuilderAppend_(&builder, "%.*s]\n", (int)it->name.count, it->name.data);
|
||||
}
|
||||
|
||||
for (DN_INIField *field = it->first_field; field; field = field->next) {
|
||||
DN_INI_Str8BuilderAppend_(&builder, "%.*s = ", (int)field->key.size, field->key.data);
|
||||
DN_INI_Str8BuilderAppend_(&builder, "%.*s = ", (int)field->key.count, field->key.data);
|
||||
switch (field->value_type) {
|
||||
case DN_INIFieldType_String: DN_INI_Str8BuilderAppend_(&builder, "%.*s\n", (int)field->value.size, field->value.data); break;
|
||||
case DN_INIFieldType_String: DN_INI_Str8BuilderAppend_(&builder, "%.*s\n", (int)field->value.count, field->value.data); break;
|
||||
case DN_INIFieldType_Bool: DN_INI_Str8BuilderAppend_(&builder, "%d\n", field->value_bool); break;
|
||||
case DN_INIFieldType_USize: DN_INI_Str8BuilderAppend_(&builder, "%zu\n", field->value_usize); break;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ DN_INIStr8FromResult DN_INI_Str8FromINI(DN_INICore const *ini, char *buffer, siz
|
||||
result.size_req = builder.size_req;
|
||||
if (buffer) {
|
||||
result.str8.data = builder.data;
|
||||
result.str8.size = builder.used;
|
||||
result.str8.count = builder.used;
|
||||
result.success = true;
|
||||
} else {
|
||||
result.success = true;
|
||||
@@ -124,7 +124,7 @@ DN_INIStr8FromResult DN_INI_Str8FromINI(DN_INICore const *ini, char *buffer, siz
|
||||
|
||||
static bool DN_INI_Str8Eq(DN_INIStr8 lhs, DN_INIStr8 rhs)
|
||||
{
|
||||
bool result = lhs.size == rhs.size && DN_INI_Memcmp(lhs.data, rhs.data, lhs.size) == 0;
|
||||
bool result = lhs.count == rhs.count && DN_INI_Memcmp(lhs.data, rhs.data, lhs.count) == 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -132,11 +132,11 @@ static DN_INIStr8 DN_INI_Str8Slice(DN_INIStr8 slice, size_t offset, size_t size)
|
||||
{
|
||||
DN_INIStr8 result = {};
|
||||
if (slice.data) {
|
||||
size_t max_offset = slice.size;
|
||||
size_t max_offset = slice.count;
|
||||
size_t final_offset = offset <= max_offset ? offset : max_offset;
|
||||
size_t max_size = slice.size - final_offset;
|
||||
size_t max_size = slice.count - final_offset;
|
||||
result.data = slice.data + final_offset;
|
||||
result.size = size <= max_size ? size : max_size;
|
||||
result.count = size <= max_size ? size : max_size;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -144,15 +144,15 @@ static DN_INIStr8 DN_INI_Str8Slice(DN_INIStr8 slice, size_t offset, size_t size)
|
||||
static DN_INIStr8BSplit DN_INI_Str8BSplit(DN_INIStr8 str8, DN_INIStr8 find)
|
||||
{
|
||||
DN_INIStr8BSplit result = {};
|
||||
if (find.size > str8.size)
|
||||
if (find.count > str8.count)
|
||||
return result;
|
||||
|
||||
for (size_t index = 0; index < (str8.size - find.size) + 1; index++) {
|
||||
DN_INIStr8 slice = DN_INI_Str8FromPtr(str8.data + index, find.size);
|
||||
for (size_t index = 0; index < (str8.count - find.count) + 1; index++) {
|
||||
DN_INIStr8 slice = DN_INI_Str8FromPtr(str8.data + index, find.count);
|
||||
if (DN_INI_Str8Eq(slice, find)) {
|
||||
result.lhs = DN_INI_Str8FromPtr(str8.data, (size_t)index);
|
||||
size_t rhs_size = (size_t)(str8.size - (index + 1));
|
||||
DN_INI_Assert(rhs_size < str8.size);
|
||||
size_t rhs_size = (size_t)(str8.count - (index + 1));
|
||||
DN_INI_Assert(rhs_size < str8.count);
|
||||
result.rhs = DN_INI_Str8FromPtr(str8.data + index + 1, rhs_size);
|
||||
break;
|
||||
}
|
||||
@@ -166,16 +166,16 @@ static DN_INIStr8BSplit DN_INI_Str8BSplit(DN_INIStr8 str8, DN_INIStr8 find)
|
||||
static DN_INIStr8BSplit DN_INI_Str8BSplitReverse(DN_INIStr8 str8, DN_INIStr8 find)
|
||||
{
|
||||
DN_INIStr8BSplit result = {};
|
||||
if (find.size > str8.size)
|
||||
if (find.count > str8.count)
|
||||
return result;
|
||||
|
||||
for (size_t index = str8.size - find.size; index > 0; index--) {
|
||||
DN_INIStr8 slice = DN_INI_Str8FromPtr(str8.data + index, find.size);
|
||||
for (size_t index = str8.count - find.count; index > 0; index--) {
|
||||
DN_INIStr8 slice = DN_INI_Str8FromPtr(str8.data + index, find.count);
|
||||
if (DN_INI_Str8Eq(slice, find)) {
|
||||
result.lhs = DN_INI_Str8FromPtr(str8.data, (size_t)index);
|
||||
size_t rhs_size = (size_t)(str8.size - index - find.size);
|
||||
DN_INI_Assert(rhs_size < str8.size);
|
||||
result.rhs = DN_INI_Str8FromPtr(str8.data + index + find.size, rhs_size);
|
||||
size_t rhs_size = (size_t)(str8.count - index - find.count);
|
||||
DN_INI_Assert(rhs_size < str8.count);
|
||||
result.rhs = DN_INI_Str8FromPtr(str8.data + index + find.count, rhs_size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -399,7 +399,7 @@ DN_INISection *DN_INI_ChildSectionFromStr8(DN_INISection *section, DN_INIStr8 st
|
||||
DN_INISection *curr = section;
|
||||
while (result) {
|
||||
DN_INIStr8BSplit split = DN_INI_Str8BSplit(section_name, DN_INIStr8Lit("."));
|
||||
if (split.lhs.size == 0)
|
||||
if (split.lhs.count == 0)
|
||||
break;
|
||||
|
||||
result = 0;
|
||||
@@ -426,8 +426,8 @@ DN_INIField *DN_INI_FieldFromSectionStr8(DN_INISection *section, DN_INIStr8 str8
|
||||
DN_INIStr8BSplit split = DN_INI_Str8BSplitReverse(str8, DN_INIStr8Lit("."));
|
||||
DN_INIStr8 find_key = str8;
|
||||
DN_INISection *find_section = section;
|
||||
if (split.rhs.size) {
|
||||
find_section = DN_INI_ChildSectionFromCStr(section, split.lhs.data, split.lhs.size);
|
||||
if (split.rhs.count) {
|
||||
find_section = DN_INI_ChildSectionFromCStr(section, split.lhs.data, split.lhs.count);
|
||||
find_key = split.rhs;
|
||||
}
|
||||
|
||||
@@ -458,20 +458,20 @@ DN_INIFieldUSize DN_INI_FieldUSizeFromSectionStr8(DN_INISection *section, DN_INI
|
||||
// NOTE: Try parse string as USize
|
||||
// NOTE: Sanitize input/output
|
||||
DN_INIStr8 value = result.field->value;
|
||||
while (value.size && DN_INI_CharIsWhitespace_(value.data[0])) {
|
||||
while (value.count && DN_INI_CharIsWhitespace_(value.data[0])) {
|
||||
value.data++;
|
||||
value.size--;
|
||||
value.count--;
|
||||
}
|
||||
|
||||
// NOTE: Handle prefix '+'
|
||||
if (value.size && value.data[0] == '+') {
|
||||
if (value.count && value.data[0] == '+') {
|
||||
value.data++;
|
||||
value.size--;
|
||||
value.count--;
|
||||
}
|
||||
|
||||
// NOTE: Convert the string number to the binary number
|
||||
size_t value_usize = 0;
|
||||
for (size_t index = 0; index < value.size; index++) {
|
||||
for (size_t index = 0; index < value.count; index++) {
|
||||
char ch = value.data[index];
|
||||
uint64_t digit = ch - '0';
|
||||
if (!(ch >= '0' && ch <= '9'))
|
||||
@@ -556,10 +556,10 @@ DN_INICore DN_INI_ParseFromPtr(char const *buf, size_t count, char *base, size_t
|
||||
curr_section = &result.first_section;
|
||||
for (;;) {
|
||||
DN_INIStr8BSplit split = DN_INI_Str8BSplit(section_name, DN_INIStr8Lit("."));
|
||||
if (split.lhs.size == 0)
|
||||
if (split.lhs.count == 0)
|
||||
break;
|
||||
|
||||
DN_INISection *next_section = DN_INI_ChildSectionFromCStr(parent, split.lhs.data, split.lhs.size);
|
||||
DN_INISection *next_section = DN_INI_ChildSectionFromCStr(parent, split.lhs.data, split.lhs.count);
|
||||
if (!next_section) {
|
||||
result.total_sections_count++;
|
||||
next_section = (DN_INISection *)DN_INI_ArenaAlloc(&arena, sizeof(*parent));
|
||||
@@ -598,7 +598,7 @@ DN_INICore DN_INI_ParseFromPtr(char const *buf, size_t count, char *base, size_t
|
||||
|
||||
if (field) {
|
||||
field->key.data = token.data;
|
||||
field->key.size = token.count;
|
||||
field->key.count = token.count;
|
||||
}
|
||||
|
||||
if (curr_section) {
|
||||
@@ -623,7 +623,7 @@ DN_INICore DN_INI_ParseFromPtr(char const *buf, size_t count, char *base, size_t
|
||||
result.memory_required += bytes_req;
|
||||
if (curr_section && field) {
|
||||
DN_INI_Assert(curr_section->fields_count);
|
||||
DN_INI_Assert(field->key.size);
|
||||
DN_INI_Assert(field->key.count);
|
||||
|
||||
char *string = (char *)DN_INI_ArenaAlloc(&arena, bytes_req);
|
||||
if (!string) {
|
||||
@@ -634,16 +634,16 @@ DN_INICore DN_INI_ParseFromPtr(char const *buf, size_t count, char *base, size_t
|
||||
if (tokeniser.prev_token.type == DN_INITokenType_Value) {
|
||||
|
||||
field->value.data = string;
|
||||
field->value.size = 0;
|
||||
field->value.count = 0;
|
||||
|
||||
for (size_t index = 0; index < tokeniser.prev_token.count; index++) {
|
||||
char ch = tokeniser.prev_token.data[index];
|
||||
char next = index + 1 < tokeniser.prev_token.count ? tokeniser.prev_token.data[index + 1] : 0;
|
||||
if (ch == '\\' && next == 'n') {
|
||||
field->value.data[field->value.size++] = '\n';
|
||||
field->value.data[field->value.count++] = '\n';
|
||||
index++;
|
||||
} else {
|
||||
field->value.data[field->value.size++] = ch;
|
||||
field->value.data[field->value.count++] = ch;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -657,10 +657,10 @@ DN_INICore DN_INI_ParseFromPtr(char const *buf, size_t count, char *base, size_t
|
||||
char ch = token.data[index];
|
||||
char next = index + 1 < token.count ? token.data[index + 1] : 0;
|
||||
if (ch == '\\' && next == 'n') {
|
||||
field->value.data[field->value.size++] = '\n';
|
||||
field->value.data[field->value.count++] = '\n';
|
||||
index++;
|
||||
} else {
|
||||
field->value.data[field->value.size++] = ch;
|
||||
field->value.data[field->value.count++] = ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -682,7 +682,7 @@ DN_INICore DN_INI_ParseFromPtr(char const *buf, size_t count, char *base, size_t
|
||||
result.memory_required += bytes_req;
|
||||
if (curr_section && field) {
|
||||
DN_INI_Assert(curr_section->fields_count);
|
||||
DN_INI_Assert(field->key.size);
|
||||
DN_INI_Assert(field->key.count);
|
||||
if (bytes_req) {
|
||||
field->value.data = (char *)DN_INI_ArenaAlloc(&arena, bytes_req);
|
||||
if (!field->value.data) {
|
||||
@@ -694,16 +694,16 @@ DN_INICore DN_INI_ParseFromPtr(char const *buf, size_t count, char *base, size_t
|
||||
char ch = token.data[index];
|
||||
char next = index + 1 < token.count ? token.data[index + 1] : 0;
|
||||
if (ch == '\\' && next == 'n') {
|
||||
field->value.data[field->value.size++] = '\n';
|
||||
field->value.data[field->value.count++] = '\n';
|
||||
index++;
|
||||
} else {
|
||||
field->value.data[field->value.size++] = ch;
|
||||
field->value.data[field->value.count++] = ch;
|
||||
}
|
||||
}
|
||||
DN_INI_Assert(field->value.size <= bytes_req);
|
||||
DN_INI_Assert(field->value.count <= bytes_req);
|
||||
} else {
|
||||
field->value.data = token.data;
|
||||
field->value.size = token.count;
|
||||
field->value.count = token.count;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
@@ -738,8 +738,8 @@ DN_INISection *DN_INI_AppendSectionF(DN_INICore *ini, DN_INIArena *arena, DN_INI
|
||||
if (arena && arena->used + mem_req <= arena->max) {
|
||||
result = (DN_INISection *)DN_INI_ArenaAlloc(arena, sizeof(*result));
|
||||
result->name.data = (char *)DN_INI_ArenaAlloc(arena, size_req + 1);
|
||||
result->name.size = size_req;
|
||||
vsnprintf(result->name.data, result->name.size + 1, fmt, args_copy);
|
||||
result->name.count = size_req;
|
||||
vsnprintf(result->name.data, result->name.count + 1, fmt, args_copy);
|
||||
if (!section)
|
||||
section = &ini->first_section;
|
||||
|
||||
@@ -766,13 +766,13 @@ DN_INISection *DN_INI_AppendSectionF(DN_INICore *ini, DN_INIArena *arena, DN_INI
|
||||
static DN_INIField *DN_INI_AllocFieldInternal(DN_INIStr8 key, DN_INIArena *arena)
|
||||
{
|
||||
DN_INIField *result = 0;
|
||||
size_t mem_req = sizeof(*result) + (key.size + 1);
|
||||
size_t mem_req = sizeof(*result) + (key.count + 1);
|
||||
if (arena->used + mem_req <= arena->max) {
|
||||
result = (DN_INIField *)DN_INI_ArenaAlloc(arena, sizeof(*result));
|
||||
result->key.data = (char *)DN_INI_ArenaAlloc(arena, key.size + 1);
|
||||
result->key.size = key.size;
|
||||
DN_INI_Memcpy(result->key.data, key.data, key.size);
|
||||
result->key.data[result->key.size] = 0;
|
||||
result->key.data = (char *)DN_INI_ArenaAlloc(arena, key.count + 1);
|
||||
result->key.count = key.count;
|
||||
DN_INI_Memcpy(result->key.data, key.data, key.count);
|
||||
result->key.data[result->key.count] = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -780,13 +780,13 @@ static DN_INIField *DN_INI_AllocFieldInternal(DN_INIStr8 key, DN_INIArena *arena
|
||||
DN_INIField *DN_INI_AppendKeyBool(DN_INICore *ini, DN_INIArena *arena, DN_INISection *section, DN_INIStr8 key, bool value)
|
||||
{
|
||||
DN_INIField *result = 0;
|
||||
size_t mem_req = sizeof(*result) + key.size + sizeof(value);
|
||||
size_t mem_req = sizeof(*result) + key.count + sizeof(value);
|
||||
ini->memory_required += mem_req;
|
||||
if (arena && arena->used + mem_req <= arena->max) {
|
||||
result = DN_INI_AllocFieldInternal(key, arena);
|
||||
result->value_bool = value;
|
||||
result->value_type = DN_INIFieldType_Bool;
|
||||
DN_INI_Memcpy(result->key.data, key.data, key.size);
|
||||
DN_INI_Memcpy(result->key.data, key.data, key.count);
|
||||
DN_INI_AppendValue(section, result);
|
||||
}
|
||||
return result;
|
||||
@@ -802,13 +802,13 @@ DN_INIField *DN_INI_AppendKeyPtrBool(DN_INICore *ini, DN_INIArena *arena, DN_INI
|
||||
DN_INIField *DN_INI_AppendKeyUSize(DN_INICore *ini, DN_INIArena *arena, DN_INISection *section, DN_INIStr8 key, size_t value)
|
||||
{
|
||||
DN_INIField *result = 0;
|
||||
size_t mem_req = sizeof(*result) + key.size + sizeof(value);
|
||||
size_t mem_req = sizeof(*result) + key.count + sizeof(value);
|
||||
ini->memory_required += mem_req;
|
||||
if (arena && arena->used + mem_req <= arena->max) {
|
||||
result = DN_INI_AllocFieldInternal(key, arena);
|
||||
result->value_usize = value;
|
||||
result->value_type = DN_INIFieldType_USize;
|
||||
DN_INI_Memcpy(result->key.data, key.data, key.size);
|
||||
DN_INI_Memcpy(result->key.data, key.data, key.count);
|
||||
DN_INI_AppendValue(section, result);
|
||||
}
|
||||
return result;
|
||||
@@ -824,12 +824,12 @@ DN_INIField *DN_INI_AppendKeyPtrUSize(DN_INICore *ini, DN_INIArena *arena, DN_IN
|
||||
DN_INIField *DN_INI_AppendKeyCStr8(DN_INICore *ini, DN_INIArena *arena, DN_INISection *section, DN_INIStr8 key, char const *value, size_t value_size)
|
||||
{
|
||||
DN_INIField *result = 0;
|
||||
size_t mem_req = sizeof(*result) + (key.size + 1) + value_size;
|
||||
size_t mem_req = sizeof(*result) + (key.count + 1) + value_size;
|
||||
ini->memory_required += mem_req;
|
||||
if (arena && arena->used + mem_req <= arena->max) {
|
||||
result = DN_INI_AllocFieldInternal(key, arena);
|
||||
result->value.data = (char *)DN_INI_ArenaAlloc(arena, value_size);
|
||||
result->value.size = value_size;
|
||||
result->value.count = value_size;
|
||||
result->value_type = DN_INIFieldType_String;
|
||||
DN_INI_Memcpy(result->value.data, value, value_size);
|
||||
DN_INI_AppendValue(section, result);
|
||||
@@ -846,14 +846,14 @@ DN_INIField *DN_INI_AppendKeyF(DN_INICore *ini, DN_INIArena *arena, DN_INISectio
|
||||
va_end(args);
|
||||
|
||||
DN_INIField *result = 0;
|
||||
size_t mem_req = sizeof(*result) + (key.size + 1) + (size_req + 1);
|
||||
size_t mem_req = sizeof(*result) + (key.count + 1) + (size_req + 1);
|
||||
ini->memory_required += mem_req;
|
||||
if (arena && arena->used + mem_req <= arena->max) {
|
||||
result = DN_INI_AllocFieldInternal(key, arena);
|
||||
result->value.data = (char *)DN_INI_ArenaAlloc(arena, size_req + 1);
|
||||
result->value.size = size_req;
|
||||
vsnprintf(result->value.data, result->value.size + 1, fmt, args_copy);
|
||||
result->value.data[result->value.size] = 0;
|
||||
result->value.count = size_req;
|
||||
vsnprintf(result->value.data, result->value.count + 1, fmt, args_copy);
|
||||
result->value.data[result->value.count] = 0;
|
||||
DN_INI_AppendValue(section, result);
|
||||
}
|
||||
va_end(args_copy);
|
||||
|
||||
@@ -48,13 +48,13 @@
|
||||
|
||||
// NOTE: Calculate the number of bytes required to parse the buffer and make one single
|
||||
// allocation
|
||||
DN_INICore ini = DN_INI_ParseFromPtr(ini_buffer.data, ini_buffer.size, NULL, 0);
|
||||
DN_INICore ini = DN_INI_ParseFromPtr(ini_buffer.data, ini_buffer.count, NULL, 0);
|
||||
size_t parse_buffer_size = ini.memory_required;
|
||||
char* parse_buffer = calloc(1, parse_buffer_size);
|
||||
|
||||
// NOTE: Parse the buffer into the `ini` object from the single allocation. No additional
|
||||
// allocations are made
|
||||
ini = DN_INI_ParseFromPtr(ini_buffer.data, ini_buffer.size, parse_buffer, parse_buffer_size);
|
||||
ini = DN_INI_ParseFromPtr(ini_buffer.data, ini_buffer.count, parse_buffer, parse_buffer_size);
|
||||
|
||||
// NOTE: Process the ini file
|
||||
// The .INI file parsed into a tree, resembling
|
||||
@@ -75,7 +75,7 @@
|
||||
|
||||
printf("My Section Foo XYZ: %zu fields\n", my_section_foo_xyz->fields_count);
|
||||
for (DN_INIField *field = my_section_foo->first_field; field; field = field->next)
|
||||
printf(" %.*s: %.*s\n", (int)field->key.size, field->key.data, (int)field->value.size, field->value.data);
|
||||
printf(" %.*s: %.*s\n", (int)field->key.count, field->key.data, (int)field->value.count, field->value.data);
|
||||
|
||||
// Alternatively you can access the section directly by specifying the fully qualified path from
|
||||
// the section, e.g.:
|
||||
@@ -87,7 +87,7 @@
|
||||
// You may also lookup the field directly by specifying the fully qualified path
|
||||
DN_INIField *my_section_item = DN_INI_FieldFromSectionStr8(&ini.first_section, DN_INIStr8Lit("my_section.item"));
|
||||
if (my_section_item)
|
||||
printf(" %.*s: %.*s\n", (int)my_section_item->key.size, my_section_item->key.data, (int)my_section_item->value.size, my_section_item->value.data);
|
||||
printf(" %.*s: %.*s\n", (int)my_section_item->key.count, my_section_item->key.data, (int)my_section_item->value.count, my_section_item->value.data);
|
||||
|
||||
// NOTE: Release memory, `ini` and its contents are invalidated and should not be used
|
||||
free(parse_buffer);
|
||||
@@ -137,7 +137,7 @@ typedef enum DN_INITokenType {
|
||||
|
||||
typedef struct DN_INIStr8 {
|
||||
char *data;
|
||||
size_t size;
|
||||
size_t count;
|
||||
} DN_INIStr8;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
+535
-511
File diff suppressed because it is too large
Load Diff
+165
-138
@@ -760,7 +760,7 @@ enum DN_ZMem
|
||||
struct DN_Str8
|
||||
{
|
||||
char *data; // The bytes of the string
|
||||
DN_USize size; // The number of bytes in the string
|
||||
DN_USize count; // The number of bytes in the string
|
||||
};
|
||||
|
||||
struct DN_Str8Slice
|
||||
@@ -769,18 +769,18 @@ struct DN_Str8Slice
|
||||
DN_USize count;
|
||||
};
|
||||
|
||||
struct DN_Str8x16 { char data[16]; DN_USize size; };
|
||||
struct DN_Str8x32 { char data[32]; DN_USize size; };
|
||||
struct DN_Str8x64 { char data[64]; DN_USize size; };
|
||||
struct DN_Str8x128 { char data[128]; DN_USize size; };
|
||||
struct DN_Str8x256 { char data[256]; DN_USize size; };
|
||||
struct DN_Str8x512 { char data[512]; DN_USize size; };
|
||||
struct DN_Str8x1024 { char data[1024]; DN_USize size; };
|
||||
struct DN_Str8x16 { char data[16]; DN_USize count; };
|
||||
struct DN_Str8x32 { char data[32]; DN_USize count; };
|
||||
struct DN_Str8x64 { char data[64]; DN_USize count; };
|
||||
struct DN_Str8x128 { char data[128]; DN_USize count; };
|
||||
struct DN_Str8x256 { char data[256]; DN_USize count; };
|
||||
struct DN_Str8x512 { char data[512]; DN_USize count; };
|
||||
struct DN_Str8x1024 { char data[1024]; DN_USize count; };
|
||||
|
||||
struct DN_Str16 // A pointer and length style string that holds slices to UTF16 bytes.
|
||||
{
|
||||
wchar_t *data; // The UTF16 bytes of the string
|
||||
DN_USize size; // The number of characters in the string
|
||||
DN_USize count; // The number of characters in the string
|
||||
};
|
||||
|
||||
struct DN_Str16Slice
|
||||
@@ -895,14 +895,14 @@ struct DN_TicketMutex
|
||||
};
|
||||
|
||||
|
||||
struct DN_Hex32 { char data[32 + 1]; DN_USize size; };
|
||||
struct DN_Hex64 { char data[64 + 1]; DN_USize size; };
|
||||
struct DN_Hex128 { char data[128 + 1]; DN_USize size; };
|
||||
struct DN_Hex32 { char data[32 + 1]; DN_USize count; };
|
||||
struct DN_Hex64 { char data[64 + 1]; DN_USize count; };
|
||||
struct DN_Hex128 { char data[128 + 1]; DN_USize count; };
|
||||
|
||||
struct DN_HexU64
|
||||
{
|
||||
char data[(sizeof(DN_U64) * 2) + 1 /*null-terminator*/];
|
||||
DN_U8 size;
|
||||
DN_U8 count;
|
||||
};
|
||||
|
||||
enum DN_HexFromU64Type
|
||||
@@ -1095,11 +1095,11 @@ enum DN_MemFuncsType
|
||||
DN_MemFuncsType_Virtual,
|
||||
};
|
||||
|
||||
typedef void *(DN_MemHeapAllocFunc)(DN_USize size);
|
||||
typedef void *(DN_MemHeapAllocFunc)(DN_USize count);
|
||||
typedef void (DN_MemHeapDeallocFunc)(void *ptr);
|
||||
typedef void *(DN_MemVirtualReserveFunc)(DN_USize size, DN_MemCommit commit, DN_MemPage page_flags);
|
||||
typedef bool (DN_MemVirtualCommitFunc)(void *ptr, DN_USize size, DN_U32 page_flags);
|
||||
typedef void (DN_MemVirtualReleaseFunc)(void *ptr, DN_USize size);
|
||||
typedef void *(DN_MemVirtualReserveFunc)(DN_USize count, DN_MemCommit commit, DN_MemPage page_flags);
|
||||
typedef bool (DN_MemVirtualCommitFunc)(void *ptr, DN_USize count, DN_U32 page_flags);
|
||||
typedef void (DN_MemVirtualReleaseFunc)(void *ptr, DN_USize count);
|
||||
struct DN_MemFuncs
|
||||
{
|
||||
DN_MemFuncsType type;
|
||||
@@ -1372,7 +1372,7 @@ struct DN_Str8TruncResult
|
||||
{
|
||||
bool truncated;
|
||||
DN_Str8 str8;
|
||||
DN_USize size_req; // Not including null-terminator
|
||||
DN_USize count_req; // Not including null-terminator
|
||||
};
|
||||
|
||||
struct DN_Str8SplitResult
|
||||
@@ -1654,7 +1654,7 @@ struct DN_LogDate
|
||||
|
||||
struct DN_LogPrefixSize
|
||||
{
|
||||
DN_USize size;
|
||||
DN_USize count;
|
||||
DN_USize padding;
|
||||
};
|
||||
|
||||
@@ -1817,7 +1817,7 @@ struct DN_ArrayEraseResult
|
||||
// The next index your for-index should be set to such that you can continue
|
||||
// to iterate the remainder of the array, e.g:
|
||||
//
|
||||
// for (DN_USize index = 0; index < array.size; index++) {
|
||||
// for (DN_USize index = 0; index < array.count; index++) {
|
||||
// if (erase)
|
||||
// index = DN_FArray_EraseRange(&array, index, -3, DN_ArrayErase_Unstable);
|
||||
// }
|
||||
@@ -2281,9 +2281,9 @@ DN_API bool DN_VerifyArgs
|
||||
#define DN_VSPrintF(...) STB_SPRINTF_DECORATE(vsprintf)(__VA_ARGS__)
|
||||
#define DN_VSNPrintF(...) STB_SPRINTF_DECORATE(vsnprintf)(__VA_ARGS__)
|
||||
|
||||
DN_API bool DN_MemStartsWith (void const *lhs, DN_USize lhs_size, void const *rhs, DN_USize rhs_size);
|
||||
DN_API bool DN_MemEq (void const *lhs, DN_USize lhs_size, void const *rhs, DN_USize rhs_size);
|
||||
DN_API bool DN_MemEqUnsafe (void const *lhs, void const *rhs, DN_USize size);
|
||||
DN_API bool DN_MemStartsWith (void const *lhs, DN_USize lhs_count, void const *rhs, DN_USize rhs_count);
|
||||
DN_API bool DN_MemEq (void const *lhs, DN_USize lhs_count, void const *rhs, DN_USize rhs_count);
|
||||
DN_API bool DN_MemEqUnsafe (void const *lhs, void const *rhs, DN_USize count);
|
||||
#if defined(__cplusplus)
|
||||
template <typename T> T* DN_MemCopyObjT (T *dest, T const *src, DN_USize count);
|
||||
#define DN_MemCopyObj(dest, src, count) DN_MemCopyObjT(dest, src, count)
|
||||
@@ -2416,7 +2416,7 @@ DN_API void DN_ASanUnpoisonMemoryRegion
|
||||
DN_API DN_F32 DN_EpsilonClampF32 (DN_F32 value, DN_F32 target, DN_F32 epsilon);
|
||||
|
||||
DN_API DN_MemStats DN_MemStatsSum (DN_MemStats lhs, DN_MemStats rhs);
|
||||
DN_API DN_MemStats DN_MemStatsSumArray (DN_MemStats const *array, DN_USize size);
|
||||
DN_API DN_MemStats DN_MemStatsSumArray (DN_MemStats const *array, DN_USize count);
|
||||
|
||||
// NOTE: MemList
|
||||
// Overview
|
||||
@@ -2588,7 +2588,7 @@ DN_API DN_I64FromResult DN_I64FromPtr
|
||||
DN_API DN_I64 DN_I64FromPtrUnsafe (void const *data, DN_USize size, char separator);
|
||||
|
||||
DN_API bool DN_U8x32Eq (DN_U8x32 const *lhs, DN_U8x32 const *rhs);
|
||||
DN_API DN_U8x32 DN_U8x32FromBytesLeftPadZ (DN_U8 const *ptr, DN_USize count);
|
||||
DN_API DN_U8x32 DN_U8x32FromBytesLeftPadZ (DN_U8 const *ptr, DN_USize size);
|
||||
DN_API DN_U8x32 DN_U8x32FromHexUnsafe (DN_Str8 hex_32b);
|
||||
DN_API DN_U8x32FromResult DN_U8x32FromHex (DN_Str8 hex_32b);
|
||||
DN_API DN_U8x32FromResult DN_U8x32FromDecimalStr8 (DN_Str8 decimal); // Write decimal string (e.g. "12345") as big-endian 256-bit value
|
||||
@@ -2596,33 +2596,33 @@ DN_API DN_U8x32FromResult DN_U8x32FromDecimalStr8
|
||||
DN_API DN_Allocator DN_AllocatorFromMemList (DN_MemList *mem);
|
||||
DN_API DN_Allocator DN_AllocatorFromArena (DN_Arena *arena);
|
||||
DN_API DN_Allocator DN_AllocatorFromPool (DN_Pool *pool);
|
||||
DN_API void* DN_AllocatorAlloc (DN_Allocator allocator, DN_USize size, DN_U8 align, DN_ZMem z_mem);
|
||||
DN_API void* DN_AllocatorAlloc (DN_Allocator allocator, DN_USize count, DN_U8 align, DN_ZMem z_mem);
|
||||
|
||||
DN_API DN_USize DN_FmtVSize (DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_USize DN_FmtSize (DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_USize DN_FmtVCount (DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API DN_USize DN_FmtCount (DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_FmtAppendResult DN_FmtVAppend (char *buf, DN_USize *buf_size, DN_USize buf_max, char const *fmt, va_list args);
|
||||
DN_API DN_FmtAppendResult DN_FmtAppend (char *buf, DN_USize *buf_size, DN_USize buf_max, char const *fmt, ...);
|
||||
DN_API DN_FmtAppendResult DN_FmtAppendTruncate (char *buf, DN_USize *buf_size, DN_USize buf_max, DN_Str8 truncator, char const *fmt, ...);
|
||||
DN_API DN_USize DN_CStr8Size (char const *src);
|
||||
DN_API DN_USize DN_CStr16Size (wchar_t const *src);
|
||||
DN_API DN_USize DN_CStr8Count (char const *src);
|
||||
DN_API DN_USize DN_CStr16Count (wchar_t const *src);
|
||||
|
||||
#define DN_Str16Lit(string) DN_Str16{(wchar_t *)(string), sizeof(string)/sizeof(string[0]) - 1}
|
||||
#define DN_Str16FromPtr(data, size) DN_Literal(DN_Str16){(wchar_t *)(data), (DN_USize)(size)}
|
||||
#define DN_Str16FromPtr(data, count) DN_Literal(DN_Str16){(wchar_t *)(data), (DN_USize)(count)}
|
||||
|
||||
#define DN_Str8Lit(c_str) DN_Literal(DN_Str8){(char *)(c_str), sizeof(c_str) - 1}
|
||||
#define DN_Str8PrintFmt(string) (int)((string).size), (string).data
|
||||
#define DN_Str8PrintFmt(string) (int)((string).count), (string).data
|
||||
|
||||
#define DN_Str8FromPtr(data, size) DN_Literal(DN_Str8){(char *)(data), (DN_USize)(size)}
|
||||
#define DN_Str8FromStruct(ptr) DN_Str8FromPtr((ptr)->data, (ptr)->size)
|
||||
#define DN_Str8FromPtr(data, count) DN_Literal(DN_Str8){(char *)(data), (DN_USize)(count)}
|
||||
#define DN_Str8FromStruct(ptr) DN_Str8FromPtr((ptr)->data, (ptr)->count)
|
||||
#define DN_Str8FromLitArray(c_array) DN_Str8FromPtr(c_array, DN_ArrayCountU(c_array))
|
||||
DN_API DN_Str8 DN_Str8AllocAllocator (DN_USize size, DN_ZMem z_mem, DN_Allocator allocator);
|
||||
DN_API DN_Str8 DN_Str8AllocArena (DN_USize size, DN_ZMem z_mem, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8AllocPool (DN_USize size, DN_Pool *pool);
|
||||
DN_API DN_Str8 DN_Str8AllocAllocator (DN_USize count, DN_ZMem z_mem, DN_Allocator allocator);
|
||||
DN_API DN_Str8 DN_Str8AllocArena (DN_USize count, DN_ZMem z_mem, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8AllocPool (DN_USize count, DN_Pool *pool);
|
||||
|
||||
DN_API DN_Str8 DN_Str8FromCStr8 (char const *src);
|
||||
DN_API DN_Str8 DN_Str8FromCStr8Arena (char const *src, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromPtrArena (void const *data, DN_USize size, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromPtrPool (void const *data, DN_USize size, DN_Pool *pool);
|
||||
DN_API DN_Str8 DN_Str8FromPtrArena (void const *data, DN_USize count, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromPtrPool (void const *data, DN_USize count, DN_Pool *pool);
|
||||
DN_API DN_Str8 DN_Str8FromStr8Allocator (DN_Str8 string, DN_Allocator allocator);
|
||||
DN_API DN_Str8 DN_Str8FromStr8Arena (DN_Str8 string, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8FromStr8Pool (DN_Str8 string, DN_Pool *pool);
|
||||
@@ -2665,7 +2665,7 @@ DN_API void DN_Str8x1024AppendFmtV
|
||||
DN_API DN_Str8x32 DN_Str8x32FromU64 (DN_U64 val, char separator);
|
||||
DN_API bool DN_Str8IsAll (DN_Str8 string, DN_Str8IsAllType is_all);
|
||||
DN_API char * DN_Str8End (DN_Str8 string);
|
||||
DN_API DN_Str8 DN_Str8Subset (DN_Str8 string, DN_USize offset, DN_USize size);
|
||||
DN_API DN_Str8 DN_Str8Subset (DN_Str8 string, DN_USize offset, DN_USize count);
|
||||
DN_API DN_Str8 DN_Str8Advance (DN_Str8 string, DN_USize amount);
|
||||
DN_API DN_Str8 DN_Str8NextLine (DN_Str8 string);
|
||||
DN_API DN_Str8BSplitResult DN_Str8BSplitArray (DN_Str8 string, DN_Str8 const *find, DN_USize find_size);
|
||||
@@ -2705,7 +2705,7 @@ DN_API DN_Str8 DN_Str8AppendF
|
||||
DN_API DN_Str8 DN_Str8AppendFV (DN_Arena *arena, DN_Str8 string, char const *fmt, va_list args);
|
||||
DN_API DN_Str8 DN_Str8FillF (DN_Arena *arena, DN_USize count, char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FillFV (DN_Arena *arena, DN_USize count, char const *fmt, va_list args);
|
||||
DN_API void DN_Str8Remove (DN_Str8 *string, DN_USize offset, DN_USize size);
|
||||
DN_API void DN_Str8Remove (DN_Str8 *string, DN_USize offset, DN_USize count);
|
||||
DN_API DN_Str8TruncResult DN_Str8TruncMiddlePtr (DN_Str8 str8, DN_USize side_size, DN_Str8 truncator, char *dest, DN_USize dest_max);
|
||||
DN_API DN_Str8TruncResult DN_Str8TruncMiddle (DN_Str8 str8, DN_USize side_size, DN_Str8 truncator, DN_Arena *arena);
|
||||
DN_API DN_Str8 DN_Str8Lower (DN_Str8 string, DN_Arena *arena);
|
||||
@@ -2738,28 +2738,28 @@ DN_API DN_Str16 DN_Str16SliceRender
|
||||
DN_API DN_Str16 DN_Str16RenderSpaceSep (DN_Str16Slice array, DN_Arena *arena);
|
||||
|
||||
DN_API DN_Str8Builder DN_Str8BuilderFromArena (DN_Arena *arena);
|
||||
DN_API DN_Str8Builder DN_Str8BuilderFromStr8PtrRef (DN_Arena *arena, DN_Str8 const *strings, DN_USize size);
|
||||
DN_API DN_Str8Builder DN_Str8BuilderFromStr8PtrCopy (DN_Arena *arena, DN_Str8 const *strings, DN_USize size);
|
||||
DN_API DN_Str8Builder DN_Str8BuilderFromStr8PtrRef (DN_Arena *arena, DN_Str8 const *strings, DN_USize count);
|
||||
DN_API DN_Str8Builder DN_Str8BuilderFromStr8PtrCopy (DN_Arena *arena, DN_Str8 const *strings, DN_USize count);
|
||||
DN_API DN_Str8Builder DN_Str8BuilderFromBuilder (DN_Arena *arena, DN_Str8Builder const *builder);
|
||||
DN_API bool DN_Str8BuilderAddArrayRef (DN_Str8Builder *builder, DN_Str8 const *strings, DN_USize size, DN_Str8BuilderAdd add);
|
||||
DN_API bool DN_Str8BuilderAddArrayCopy (DN_Str8Builder *builder, DN_Str8 const *strings, DN_USize size, DN_Str8BuilderAdd add);
|
||||
DN_API bool DN_Str8BuilderAddArrayRef (DN_Str8Builder *builder, DN_Str8 const *strings, DN_USize count, DN_Str8BuilderAdd add);
|
||||
DN_API bool DN_Str8BuilderAddArrayCopy (DN_Str8Builder *builder, DN_Str8 const *strings, DN_USize count, DN_Str8BuilderAdd add);
|
||||
DN_API bool DN_Str8BuilderAddFV (DN_Str8Builder *builder, DN_Str8BuilderAdd add, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
#define DN_Str8BuilderAppendArrayRef(builder, strings, size) DN_Str8BuilderAddArrayRef(builder, strings, size, DN_Str8BuilderAdd_Append)
|
||||
#define DN_Str8BuilderAppendArrayCopy(builder, strings, size) DN_Str8BuilderAddArrayCopy(builder, strings, size, DN_Str8BuilderAdd_Append)
|
||||
#define DN_Str8BuilderAppendSliceRef(builder, slice) DN_Str8BuilderAddArrayRef(builder, slice.data, slice.size, DN_Str8BuilderAdd_Append)
|
||||
#define DN_Str8BuilderAppendSliceCopy(builder, slice) DN_Str8BuilderAddArrayCopy(builder, slice.data, slice.size, DN_Str8BuilderAdd_Append)
|
||||
#define DN_Str8BuilderAppendSliceRef(builder, slice) DN_Str8BuilderAddArrayRef(builder, slice.data, slice.count, DN_Str8BuilderAdd_Append)
|
||||
#define DN_Str8BuilderAppendSliceCopy(builder, slice) DN_Str8BuilderAddArrayCopy(builder, slice.data, slice.count, DN_Str8BuilderAdd_Append)
|
||||
DN_API bool DN_Str8BuilderAppendRef (DN_Str8Builder *builder, DN_Str8 string);
|
||||
DN_API bool DN_Str8BuilderAppendCopy (DN_Str8Builder *builder, DN_Str8 string);
|
||||
#define DN_Str8BuilderAppendFV(builder, fmt, args) DN_Str8BuilderAddFV(builder, DN_Str8BuilderAdd_Append, fmt, args)
|
||||
DN_API bool DN_Str8BuilderAppendF (DN_Str8Builder *builder, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API bool DN_Str8BuilderAppendBytesRef (DN_Str8Builder *builder, void const *ptr, DN_USize size);
|
||||
DN_API bool DN_Str8BuilderAppendBytesCopy (DN_Str8Builder *builder, void const *ptr, DN_USize size);
|
||||
DN_API bool DN_Str8BuilderAppendBytesRef (DN_Str8Builder *builder, void const *ptr, DN_USize count);
|
||||
DN_API bool DN_Str8BuilderAppendBytesCopy (DN_Str8Builder *builder, void const *ptr, DN_USize count);
|
||||
DN_API bool DN_Str8BuilderAppendBuilderRef (DN_Str8Builder *dest, DN_Str8Builder const *src);
|
||||
DN_API bool DN_Str8BuilderAppendBuilderCopy (DN_Str8Builder *dest, DN_Str8Builder const *src);
|
||||
#define DN_Str8BuilderPrependArrayRef(builder, strings, size) DN_Str8BuilderAddArrayRef(builder, strings, size, DN_Str8BuilderAdd_Prepend)
|
||||
#define DN_Str8BuilderPrependArrayCopy(builder, strings, size) DN_Str8BuilderAddArrayCopy(builder, strings, size, DN_Str8BuilderAdd_Prepend)
|
||||
#define DN_Str8BuilderPrependSliceRef(builder, slice) DN_Str8BuilderAddArrayRef(builder, slice.data, slice.size, DN_Str8BuilderAdd_Prepend)
|
||||
#define DN_Str8BuilderPrependSliceCopy(builder, slice) DN_Str8BuilderAddArrayCopy(builder, slice.data, slice.size, DN_Str8BuilderAdd_Prepend)
|
||||
#define DN_Str8BuilderPrependSliceRef(builder, slice) DN_Str8BuilderAddArrayRef(builder, slice.data, slice.count, DN_Str8BuilderAdd_Prepend)
|
||||
#define DN_Str8BuilderPrependSliceCopy(builder, slice) DN_Str8BuilderAddArrayCopy(builder, slice.data, slice.count, DN_Str8BuilderAdd_Prepend)
|
||||
DN_API bool DN_Str8BuilderPrependRef (DN_Str8Builder *builder, DN_Str8 string);
|
||||
DN_API bool DN_Str8BuilderPrependCopy (DN_Str8Builder *builder, DN_Str8 string);
|
||||
#define DN_Str8BuilderPrependFV(builder, fmt, args) DN_Str8BuilderAddFV(builder, DN_Str8BuilderAdd_Prepend, fmt, args)
|
||||
@@ -2902,8 +2902,8 @@ DN_API void DN_PCG32Advance
|
||||
#define DN_FNV1A64_SEED 14695981039346656037ULL
|
||||
#endif
|
||||
|
||||
DN_API DN_U32 DN_FNV1AHashU32FromBytes (void const *bytes, DN_USize size, DN_U32 seed);
|
||||
DN_API DN_U64 DN_FNV1AHashU64FromBytes (void const *bytes, DN_USize size, DN_U64 seed);
|
||||
DN_API DN_U32 DN_FNV1AHashU32FromBytes (void const *bytes, DN_USize count, DN_U32 seed);
|
||||
DN_API DN_U64 DN_FNV1AHashU64FromBytes (void const *bytes, DN_USize count, DN_U64 seed);
|
||||
|
||||
DN_API DN_U32 DN_MurmurHash3HashU32FromBytesX86 (void const *bytes, int len, DN_U32 seed);
|
||||
DN_API DN_MurmurHash3 DN_MurmurHash3HashU128FromBytesX64 (void const *bytes, int len, DN_U32 seed);
|
||||
@@ -3461,7 +3461,7 @@ DN_API DN_RaycastV2 DN_RaycastLineIntersectV2
|
||||
// API
|
||||
// ResizeFrom: Resizes the array to `new_max` erase elements if resizing to a smaller size
|
||||
// GrowFrom: Expands the capacity of the array if `new_max > array.max` otherwise no-op
|
||||
// GrowIfNeeded: Expands the capacity of the array if `array.size + add_count > array.max` otherwise no-op
|
||||
// GrowIfNeeded: Expands the capacity of the array if `array.count + add_count > array.max` otherwise no-op
|
||||
//
|
||||
// Variants
|
||||
// PArray => Pointer (to) Array
|
||||
@@ -3471,7 +3471,7 @@ DN_API DN_RaycastV2 DN_RaycastLineIntersectV2
|
||||
// automatically using DN_ArrayCountU(l_array).
|
||||
//
|
||||
// MyStruct buffer[TB_ASType_Count] = {};
|
||||
// DN_USize size = 0;
|
||||
// DN_USize count = 0;
|
||||
// MyStruct *item_0 = DN_PArrayMake(buffer, &size, DN_ArrayCountU(buffer), DN_ZMem_No);
|
||||
// MyStruct *item_1 = DN_LArrayMake(buffer, &size, DN_ZMem_No);
|
||||
//
|
||||
@@ -3649,44 +3649,44 @@ DN_API DN_RaycastV2 DN_RaycastLineIntersectV2
|
||||
#define DN_ISliceAllocArena(slice_ptr, count_, zmem, arena) (DN_CppDeclType(&((slice_ptr)->data[0])))DN_SliceAllocArena((void **)&((slice_ptr)->data), &((slice_ptr)->count), count_, sizeof((slice_ptr)->data[0]), alignof(DN_CppDeclType((slice_ptr)->data[0])), zmem, arena)
|
||||
|
||||
|
||||
DN_API void* DN_SliceAllocArena (void **data, DN_USize *slice_size_field, DN_USize size, DN_USize elem_size, DN_U8 align, DN_ZMem zmem, DN_Arena *arena);
|
||||
DN_API void* DN_SliceAllocArena (void **data, DN_USize *slice_size_field, DN_USize count, DN_USize elem_size, DN_U8 align, DN_ZMem zmem, DN_Arena *arena);
|
||||
|
||||
DN_API DN_ArrayFindResult DN_ArrayFind (void *data, DN_USize size, DN_USize elem_size, void const *find, DN_ArrayFindEqFunc *eq_func);
|
||||
DN_API DN_ArrayFindResult DN_ArrayFindMemEq (void *data, DN_USize size, DN_USize elem_size, void const *find);
|
||||
DN_API void* DN_ArrayInsertArray (void *data, DN_USize *size, DN_USize max, DN_USize elem_size, DN_USize index, void const *items, DN_USize count);
|
||||
DN_API void* DN_ArrayPopFront (void *data, DN_USize *size, DN_USize elem_size, DN_USize count);
|
||||
DN_API void* DN_ArrayPopBack (void *data, DN_USize *size, DN_USize elem_size, DN_USize count);
|
||||
DN_API DN_ArrayEraseResult DN_ArrayEraseRange (void *data, DN_USize *size, DN_USize elem_size, DN_USize begin_index, DN_ISize count, DN_ArrayErase erase);
|
||||
DN_API void* DN_ArrayMakeArray (void *data, DN_USize *size, DN_USize max, DN_USize elem_size, DN_USize make_count, DN_ZMem z_mem);
|
||||
DN_API void* DN_ArrayMakeArrayAssert (void *data, DN_USize *size, DN_USize max, DN_USize elem_size, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site);
|
||||
DN_API void* DN_ArrayAddArray (void *data, DN_USize *size, DN_USize max, DN_USize elem_size, void const *elems, DN_USize elems_count, DN_ArrayAdd add);
|
||||
DN_API void* DN_ArrayAddArrayAssert (void *data, DN_USize *size, DN_USize max, DN_USize elem_size, void const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site);
|
||||
DN_API bool DN_ArrayResizeFromPool (void **data, DN_USize *size, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max);
|
||||
DN_API bool DN_ArrayResizeFromArena (void **data, DN_USize *size, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize new_max);
|
||||
DN_API bool DN_ArrayGrowFromPool (void **data, DN_USize size, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max);
|
||||
DN_API bool DN_ArrayGrowFromArena (void **data, DN_USize size, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize new_max);
|
||||
DN_API bool DN_ArrayGrowIfNeededFromPool (void **data, DN_USize size, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize add_count);
|
||||
DN_API bool DN_ArrayGrowIfNeededFromArena (void **data, DN_USize size, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize add_count);
|
||||
DN_API DN_ArrayFindResult DN_ArrayFind (void *data, DN_USize count, DN_USize elem_size, void const *find, DN_ArrayFindEqFunc *eq_func);
|
||||
DN_API DN_ArrayFindResult DN_ArrayFindMemEq (void *data, DN_USize count, DN_USize elem_size, void const *find);
|
||||
DN_API void* DN_ArrayInsertArray (void *data, DN_USize *count, DN_USize max, DN_USize elem_size, DN_USize index, void const *items, DN_USize items_count);
|
||||
DN_API void* DN_ArrayPopFront (void *data, DN_USize *count, DN_USize elem_size, DN_USize pop_count);
|
||||
DN_API void* DN_ArrayPopBack (void *data, DN_USize *count, DN_USize elem_size, DN_USize pop_count);
|
||||
DN_API DN_ArrayEraseResult DN_ArrayEraseRange (void *data, DN_USize *count, DN_USize elem_size, DN_USize begin_index, DN_ISize erase_count, DN_ArrayErase erase);
|
||||
DN_API void* DN_ArrayMakeArray (void *data, DN_USize *count, DN_USize max, DN_USize elem_size, DN_USize make_count, DN_ZMem z_mem);
|
||||
DN_API void* DN_ArrayMakeArrayAssert (void *data, DN_USize *count, DN_USize max, DN_USize elem_size, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site);
|
||||
DN_API void* DN_ArrayAddArray (void *data, DN_USize *count, DN_USize max, DN_USize elem_size, void const *elems, DN_USize elems_count, DN_ArrayAdd add);
|
||||
DN_API void* DN_ArrayAddArrayAssert (void *data, DN_USize *count, DN_USize max, DN_USize elem_size, void const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site);
|
||||
DN_API bool DN_ArrayResizeFromPool (void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max);
|
||||
DN_API bool DN_ArrayResizeFromArena (void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize new_max);
|
||||
DN_API bool DN_ArrayGrowFromPool (void **data, DN_USize count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max);
|
||||
DN_API bool DN_ArrayGrowFromArena (void **data, DN_USize count, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize new_max);
|
||||
DN_API bool DN_ArrayGrowIfNeededFromPool (void **data, DN_USize count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize add_count);
|
||||
DN_API bool DN_ArrayGrowIfNeededFromArena (void **data, DN_USize count, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize add_count);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
template <typename T> DN_ArrayFindResult DN_TArrayFind (T *data, DN_USize size, void const *find, DN_ArrayFindEqFunc *eq_func);
|
||||
template <typename T> DN_ArrayFindResult DN_TArrayFindMemEq (T *data, DN_USize size, void const *find, DN_ArrayFindEqFunc *eq_func);
|
||||
template <typename T> T* DN_TArrayInsertArray (T *data, DN_USize *size, DN_USize max, DN_USize index, void const *items, DN_USize count);
|
||||
template <typename T> T* DN_TArrayPopFront (T *data, DN_USize *size, DN_USize count);
|
||||
template <typename T> T* DN_TArrayPopBack (T *data, DN_USize *size, DN_USize count);
|
||||
template <typename T> DN_ArrayEraseResult DN_TArrayEraseRange (T *data, DN_USize *size, DN_USize begin_index, DN_ISize count, DN_ArrayErase erase);
|
||||
template <typename T> T* DN_TArrayMakeArray (T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_ZMem z_mem);
|
||||
template <typename T> T* DN_TArrayMakeArrayAssert (T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site);
|
||||
template <typename T> T* DN_TArrayMakeArrayAssertZ (T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_CallSite call_site);
|
||||
template <typename T> T* DN_TArrayMakeArrayAssertNoZ (T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_CallSite call_site);
|
||||
template <typename T> T* DN_TArrayAddArray (T *data, DN_USize *size, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add);
|
||||
template <typename T> T* DN_TArrayAddArrayAssert (T *data, DN_USize *size, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site);
|
||||
template <typename T> bool DN_TArrayResizeFromPool (T **data, DN_USize *size, DN_USize *max, DN_Pool *pool, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayResizeFromArena (T **data, DN_USize *size, DN_USize *max, DN_Arena *arena, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayGrowFromPool (T **data, DN_USize size, DN_USize *max, DN_Pool *pool, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayGrowFromArena (T **data, DN_USize size, DN_USize *max, DN_Pool *pool, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayGrowIfNeededFromPool (T **data, DN_USize size, DN_USize *max, DN_Pool *pool, DN_USize add_count);
|
||||
template <typename T> bool DN_TArrayGrowIfNeededFromArena (T **data, DN_USize size, DN_USize *max, DN_Arena *pool, DN_USize add_count);
|
||||
template <typename T> DN_ArrayFindResult DN_TArrayFind (T *data, DN_USize count, void const *find, DN_ArrayFindEqFunc *eq_func);
|
||||
template <typename T> DN_ArrayFindResult DN_TArrayFindMemEq (T *data, DN_USize count, void const *find, DN_ArrayFindEqFunc *eq_func);
|
||||
template <typename T> T* DN_TArrayInsertArray (T *data, DN_USize *count, DN_USize max, DN_USize index, void const *items, DN_USize pop_count);
|
||||
template <typename T> T* DN_TArrayPopFront (T *data, DN_USize *count, DN_USize pop_count);
|
||||
template <typename T> T* DN_TArrayPopBack (T *data, DN_USize *count, DN_USize pop_count);
|
||||
template <typename T> DN_ArrayEraseResult DN_TArrayEraseRange (T *data, DN_USize *count, DN_USize begin_index, DN_ISize erase_count, DN_ArrayErase erase);
|
||||
template <typename T> T* DN_TArrayMakeArray (T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_ZMem z_mem);
|
||||
template <typename T> T* DN_TArrayMakeArrayAssert (T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site);
|
||||
template <typename T> T* DN_TArrayMakeArrayAssertZ (T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_CallSite call_site);
|
||||
template <typename T> T* DN_TArrayMakeArrayAssertNoZ (T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_CallSite call_site);
|
||||
template <typename T> T* DN_TArrayAddArray (T *data, DN_USize *count, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add);
|
||||
template <typename T> T* DN_TArrayAddArrayAssert (T *data, DN_USize *count, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site);
|
||||
template <typename T> bool DN_TArrayResizeFromPool (T **data, DN_USize *count, DN_USize *max, DN_Pool *pool, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayResizeFromArena (T **data, DN_USize *count, DN_USize *max, DN_Arena *arena, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayGrowFromPool (T **data, DN_USize count, DN_USize *max, DN_Pool *pool, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayGrowFromArena (T **data, DN_USize count, DN_USize *max, DN_Pool *pool, DN_USize new_max);
|
||||
template <typename T> bool DN_TArrayGrowIfNeededFromPool (T **data, DN_USize count, DN_USize *max, DN_Pool *pool, DN_USize add_count);
|
||||
template <typename T> bool DN_TArrayGrowIfNeededFromArena (T **data, DN_USize count, DN_USize *max, DN_Arena *pool, DN_USize add_count);
|
||||
#endif
|
||||
|
||||
DN_API void* DN_SinglyLLDetach (void **link, void **next);
|
||||
@@ -3719,8 +3719,8 @@ template <typename T> bool DN_DSMapResize (DN_DSMap
|
||||
template <typename T> bool DN_DSMapErase (DN_DSMap<T> *map, DN_DSMapKey key);
|
||||
template <typename T> bool DN_DSMapEraseKeyU64 (DN_DSMap<T> *map, DN_U64 key);
|
||||
template <typename T> bool DN_DSMapEraseKeyStr8 (DN_DSMap<T> *map, DN_Str8 key);
|
||||
template <typename T> DN_DSMapKey DN_DSMapKeyBuffer (DN_DSMap<T> const *map, void const *data, DN_USize size);
|
||||
template <typename T> DN_DSMapKey DN_DSMapKeyBufferAsU64NoHash (DN_DSMap<T> const *map, void const *data, DN_USize size);
|
||||
template <typename T> DN_DSMapKey DN_DSMapKeyBuffer (DN_DSMap<T> const *map, void const *data, DN_USize count);
|
||||
template <typename T> DN_DSMapKey DN_DSMapKeyBufferAsU64NoHash (DN_DSMap<T> const *map, void const *data, DN_USize count);
|
||||
template <typename T> DN_DSMapKey DN_DSMapKeyU64 (DN_DSMap<T> const *map, DN_U64 u64);
|
||||
template <typename T> DN_DSMapKey DN_DSMapKeyStr8 (DN_DSMap<T> const *map, DN_Str8 string);
|
||||
#define DN_DSMapKeyCStr8(map, string) DN_DSMapKeyBuffer(map, string, sizeof((string))/sizeof((string)[0]) - 1)
|
||||
@@ -3940,19 +3940,19 @@ DN_API DN_Arena DN_ArenaFromHeap (D
|
||||
DN_API DN_Arena DN_ArenaFromVMem (DN_U64 reserve, DN_U64 commit, DN_MemFlags flags);
|
||||
|
||||
DN_API DN_Str8 DN_Str8FromHeapF (DN_FMT_ATTRIB char const *fmt, ...);
|
||||
DN_API DN_Str8 DN_Str8FromHeap (DN_USize size, DN_ZMem z_mem);
|
||||
DN_API DN_Str8 DN_Str8FromHeap (DN_USize count, DN_ZMem z_mem);
|
||||
DN_API DN_Str8 DN_Str8BuilderBuildFromHeap (DN_Str8Builder const *builder);
|
||||
|
||||
DN_API void DN_OS_LogPrint (DN_LogTypeParam type, void *user_data, DN_CallSite call_site, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API void DN_OS_SetLogPrintFuncToOS ();
|
||||
|
||||
DN_API void * DN_OS_MemReserve (DN_USize size, DN_MemCommit commit, DN_MemPage page_flags);
|
||||
DN_API bool DN_OS_MemCommit (void *ptr, DN_USize size, DN_U32 page_flags);
|
||||
DN_API void DN_OS_MemDecommit (void *ptr, DN_USize size);
|
||||
DN_API void DN_OS_MemRelease (void *ptr, DN_USize size);
|
||||
DN_API int DN_OS_MemProtect (void *ptr, DN_USize size, DN_U32 page_flags);
|
||||
DN_API void * DN_OS_MemReserve (DN_USize count, DN_MemCommit commit, DN_MemPage page_flags);
|
||||
DN_API bool DN_OS_MemCommit (void *ptr, DN_USize count, DN_U32 page_flags);
|
||||
DN_API void DN_OS_MemDecommit (void *ptr, DN_USize count);
|
||||
DN_API void DN_OS_MemRelease (void *ptr, DN_USize count);
|
||||
DN_API int DN_OS_MemProtect (void *ptr, DN_USize count, DN_U32 page_flags);
|
||||
|
||||
DN_API void * DN_OS_MemAlloc (DN_USize size, DN_ZMem z_mem);
|
||||
DN_API void * DN_OS_MemAlloc (DN_USize count, DN_ZMem z_mem);
|
||||
DN_API void DN_OS_MemDealloc (void *ptr);
|
||||
|
||||
DN_API DN_Date DN_OS_DateLocalTimeNow ();
|
||||
@@ -3990,8 +3990,8 @@ DN_API bool DN_OS_FileCopy (D
|
||||
DN_API bool DN_OS_FileMove (DN_Str8 src, DN_Str8 dest, bool overwrite, DN_ErrSink *err);
|
||||
|
||||
DN_API DN_OSFile DN_OS_FileOpen (DN_Str8 path, DN_OSFileOpen open_mode, DN_OSFileAccess access, DN_ErrSink *err);
|
||||
DN_API DN_OSFileRead DN_OS_FileRead (DN_OSFile *file, void *buffer, DN_USize size, DN_ErrSink *err);
|
||||
DN_API bool DN_OS_FileWritePtr (DN_OSFile *file, void const *data, DN_USize size, DN_ErrSink *err);
|
||||
DN_API DN_OSFileRead DN_OS_FileRead (DN_OSFile *file, void *buffer, DN_USize count, DN_ErrSink *err);
|
||||
DN_API bool DN_OS_FileWritePtr (DN_OSFile *file, void const *data, DN_USize count, DN_ErrSink *err);
|
||||
DN_API bool DN_OS_FileWrite (DN_OSFile *file, DN_Str8 buffer, DN_ErrSink *err);
|
||||
DN_API bool DN_OS_FileWriteFV (DN_OSFile *file, DN_ErrSink *err, DN_FMT_ATTRIB char const *fmt, va_list args);
|
||||
DN_API bool DN_OS_FileWriteF (DN_OSFile *file, DN_ErrSink *err, DN_FMT_ATTRIB char const *fmt, ...);
|
||||
@@ -4214,128 +4214,128 @@ template <typename T> T *DN_MemCopyObjT(T *dest, T const *src, DN_USize count)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DN_ArrayFindResult DN_TArrayFind(T *data, DN_USize size, void const *find, DN_ArrayFindEqFunc *eq_func)
|
||||
DN_ArrayFindResult DN_TArrayFind(T *data, DN_USize count, void const *find, DN_ArrayFindEqFunc *eq_func)
|
||||
{
|
||||
DN_ArrayFindResult result = DN_ArrayFind(data, size, sizeof(*data), find, eq_func);
|
||||
DN_ArrayFindResult result = DN_ArrayFind(data, count, sizeof(*data), find, eq_func);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DN_ArrayFindResult DN_TArrayFindMemEq(T *data, DN_USize size, void const *find)
|
||||
DN_ArrayFindResult DN_TArrayFindMemEq(T *data, DN_USize count, void const *find)
|
||||
{
|
||||
DN_ArrayFindResult result = DN_ArrayFindMemEq(data, size, sizeof(*data), find);
|
||||
DN_ArrayFindResult result = DN_ArrayFindMemEq(data, count, sizeof(*data), find);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayInsertArray(T *data, DN_USize *size, DN_USize max, DN_USize index, T const *items, DN_USize count)
|
||||
T *DN_TArrayInsertArray(T *data, DN_USize *count, DN_USize max, DN_USize index, T const *items, DN_USize items_count)
|
||||
{
|
||||
T *result = DN_Cast(T *)DN_ArrayInsertArray(data, size, max, sizeof(*data), index, items, count);
|
||||
T *result = DN_Cast(T *)DN_ArrayInsertArray(data, count, max, sizeof(*data), index, items, items_count);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayPopFront(T *data, DN_USize *size, DN_USize count)
|
||||
T *DN_TArrayPopFront(T *data, DN_USize *count, DN_USize pop_count)
|
||||
{
|
||||
T *result = DN_Cast(T *)DN_ArrayPopFront(data, size, sizeof(*data), count);
|
||||
T *result = DN_Cast(T *)DN_ArrayPopFront(data, count, sizeof(*data), pop_count);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayPopBack(T *data, DN_USize *size, DN_USize count)
|
||||
T *DN_TArrayPopBack(T *data, DN_USize *count, DN_USize pop_count)
|
||||
{
|
||||
T *result = DN_Cast(T *)DN_ArrayPopBack(data, size, sizeof(*data), count);
|
||||
T *result = DN_Cast(T *)DN_ArrayPopBack(data, count, sizeof(*data), pop_count);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DN_ArrayEraseResult DN_TArrayEraseRange(T *data, DN_USize *size, DN_USize begin_index, DN_ISize count, DN_ArrayErase erase)
|
||||
DN_ArrayEraseResult DN_TArrayEraseRange(T *data, DN_USize *count, DN_USize begin_index, DN_ISize erase_count, DN_ArrayErase erase)
|
||||
{
|
||||
DN_ArrayEraseResult result = DN_ArrayEraseRange(data, size, sizeof(*data), begin_index, count, erase);
|
||||
DN_ArrayEraseResult result = DN_ArrayEraseRange(data, count, sizeof(*data), begin_index, erase_count, erase);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayMakeArray(T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_ZMem z_mem)
|
||||
T *DN_TArrayMakeArray(T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_ZMem z_mem)
|
||||
{
|
||||
T *result = DN_Cast(T *)DN_ArrayMakeArray(data, size, max, sizeof(*data), make_count, z_mem);
|
||||
T *result = DN_Cast(T *)DN_ArrayMakeArray(data, count, max, sizeof(*data), make_count, z_mem);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayMakeArrayAssert(T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site)
|
||||
T *DN_TArrayMakeArrayAssert(T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_ZMem z_mem, DN_CallSite call_site)
|
||||
{
|
||||
T *result = DN_Cast(T *)DN_ArrayMakeArrayAssert(data, size, max, sizeof(*data), make_count, z_mem, call_site);
|
||||
T *result = DN_Cast(T *)DN_ArrayMakeArrayAssert(data, count, max, sizeof(*data), make_count, z_mem, call_site);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayMakeArrayAssertZ(T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_CallSite call_site)
|
||||
T *DN_TArrayMakeArrayAssertZ(T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_CallSite call_site)
|
||||
{
|
||||
T* result = DN_TArrayMakeArrayAssert(data, size, max, make_count, DN_ZMem_Yes, call_site);
|
||||
T* result = DN_TArrayMakeArrayAssert(data, count, max, make_count, DN_ZMem_Yes, call_site);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayMakeArrayAssertNoZ(T *data, DN_USize *size, DN_USize max, DN_USize make_count, DN_CallSite call_site)
|
||||
T *DN_TArrayMakeArrayAssertNoZ(T *data, DN_USize *count, DN_USize max, DN_USize make_count, DN_CallSite call_site)
|
||||
{
|
||||
T* result = DN_TArrayMakeArrayAssert(data, size, max, make_count, DN_ZMem_No, call_site);
|
||||
T* result = DN_TArrayMakeArrayAssert(data, count, max, make_count, DN_ZMem_No, call_site);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayAddArray(T *data, DN_USize *size, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add)
|
||||
T *DN_TArrayAddArray(T *data, DN_USize *count, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add)
|
||||
{
|
||||
T* result = DN_Cast(T *)DN_ArrayAddArray(data, size, max, sizeof(*elems), elems, elems_count, add);
|
||||
T* result = DN_Cast(T *)DN_ArrayAddArray(data, count, max, sizeof(*elems), elems, elems_count, add);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *DN_TArrayAddArrayAssert(T *data, DN_USize *size, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site)
|
||||
T *DN_TArrayAddArrayAssert(T *data, DN_USize *count, DN_USize max, T const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site)
|
||||
{
|
||||
T* result = DN_Cast(T *)DN_ArrayAddArrayAssert(data, size, max, sizeof(*elems), elems, elems_count, add, call_site);
|
||||
T* result = DN_Cast(T *)DN_ArrayAddArrayAssert(data, count, max, sizeof(*elems), elems, elems_count, add, call_site);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DN_TArrayResizeFromPool(T **data, DN_USize *size, DN_USize *max, DN_Pool *pool, DN_USize new_max)
|
||||
bool DN_TArrayResizeFromPool(T **data, DN_USize *count, DN_USize *max, DN_Pool *pool, DN_USize new_max)
|
||||
{
|
||||
bool result = DN_ArrayResizeFromPool(DN_Cast(void **)data, size, max, sizeof(**data), pool, new_max);
|
||||
bool result = DN_ArrayResizeFromPool(DN_Cast(void **)data, count, max, sizeof(**data), pool, new_max);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DN_TArrayResizeFromArena(T **data, DN_USize *size, DN_USize *max, DN_Arena *arena, DN_USize new_max)
|
||||
bool DN_TArrayResizeFromArena(T **data, DN_USize *count, DN_USize *max, DN_Arena *arena, DN_USize new_max)
|
||||
{
|
||||
bool result = DN_ArrayResizeFromArena(DN_Cast(void **)data, size, max, sizeof(**data), arena, new_max);
|
||||
bool result = DN_ArrayResizeFromArena(DN_Cast(void **)data, count, max, sizeof(**data), arena, new_max);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DN_TArrayGrowFromPool(T **data, DN_USize size, DN_USize *max, DN_Pool *pool, DN_USize new_max)
|
||||
bool DN_TArrayGrowFromPool(T **data, DN_USize count, DN_USize *max, DN_Pool *pool, DN_USize new_max)
|
||||
{
|
||||
bool result = DN_ArrayGrowFromPool(DN_Cast(void **)data, size, max, sizeof(**data), pool, new_max);
|
||||
bool result = DN_ArrayGrowFromPool(DN_Cast(void **)data, count, max, sizeof(**data), pool, new_max);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DN_TArrayGrowFromArena(T **data, DN_USize size, DN_USize *max, DN_Arena *arena, DN_USize new_max)
|
||||
bool DN_TArrayGrowFromArena(T **data, DN_USize count, DN_USize *max, DN_Arena *arena, DN_USize new_max)
|
||||
{
|
||||
bool result = DN_ArrayGrowFromArena(DN_Cast(void **)data, size, max, sizeof(**data), arena, new_max);
|
||||
bool result = DN_ArrayGrowFromArena(DN_Cast(void **)data, count, max, sizeof(**data), arena, new_max);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DN_TArrayGrowIfNeededFromPool(T **data, DN_USize size, DN_USize *max, DN_Pool *pool, DN_USize add_count)
|
||||
bool DN_TArrayGrowIfNeededFromPool(T **data, DN_USize count, DN_USize *max, DN_Pool *pool, DN_USize add_count)
|
||||
{
|
||||
bool result = DN_ArrayGrowIfNeededFromPool(DN_Cast(void **)data, size, max, sizeof(**data), pool, add_count);
|
||||
bool result = DN_ArrayGrowIfNeededFromPool(DN_Cast(void **)data, count, max, sizeof(**data), pool, add_count);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DN_TArrayGrowIfNeededFromArena(T **data, DN_USize size, DN_USize *max, DN_Arena *arena, DN_USize add_count)
|
||||
bool DN_TArrayGrowIfNeededFromArena(T **data, DN_USize count, DN_USize *max, DN_Arena *arena, DN_USize add_count)
|
||||
{
|
||||
bool result = DN_ArrayGrowIfNeededFromArena(DN_Cast(void **)data, size, max, sizeof(**data), arena, add_count);
|
||||
bool result = DN_ArrayGrowIfNeededFromArena(DN_Cast(void **)data, count, max, sizeof(**data), arena, add_count);
|
||||
return result;
|
||||
}
|
||||
#endif // defined(__cplusplus)
|
||||
@@ -4370,10 +4370,12 @@ enum DN_NETWSSend
|
||||
DN_NETWSSend_Pong,
|
||||
};
|
||||
|
||||
enum DN_NETDoHTTPFlags
|
||||
typedef DN_U32 DN_NETDoHTTPFlags;
|
||||
enum DN_NETDoHTTPFlags_
|
||||
{
|
||||
DN_NETDoHTTPFlags_Nil = 0,
|
||||
DN_NETDoHTTPFlags_BasicAuth = 1 << 0,
|
||||
DN_NETDoHTTPFlags_DisableSSLVerify = 1 << 1,
|
||||
};
|
||||
|
||||
struct DN_NETDoHTTPArgs
|
||||
@@ -4397,6 +4399,8 @@ struct DN_NETRequestHandle
|
||||
|
||||
struct DN_NETResponse
|
||||
{
|
||||
// NOTE: When filling these fields, all their values are copied internally in the library so the
|
||||
// values do not need to persist past the initial invocation of the HTTP/WS request.
|
||||
// NOTE: Common to WS and HTTP responses
|
||||
DN_NETRequestType type;
|
||||
DN_NETResponseState state;
|
||||
@@ -4455,10 +4459,24 @@ struct DN_NETCore
|
||||
DN_NETInterface api;
|
||||
};
|
||||
|
||||
// NOTE: NET
|
||||
// Overview
|
||||
// Defines a multi-threaded interface for doing network requests (via the `DN_NETInterface`
|
||||
// object) in the core struct. On top of this is a asynchronous API provided to the caller along
|
||||
// the lines of, do http/ws followed to dispatch a request followed by a blocking wait for
|
||||
// response function.
|
||||
//
|
||||
// API
|
||||
// DN_NET_ResponseHasFailed
|
||||
// After a response has been dispatched via do http/ws the returned handle's status can be
|
||||
// queried using this function. A request has failed if the `state` has returned
|
||||
// `DN_NETResponseState_Error`, or the returned HTTP status code was `>= 400`.
|
||||
DN_Str8 DN_NET_Str8FromResponseState (DN_NETResponseState state);
|
||||
DN_NETRequest * DN_NET_RequestFromHandle (DN_NETRequestHandle handle);
|
||||
DN_NETRequestHandle DN_NET_HandleFromRequest (DN_NETRequest *request);
|
||||
bool DN_NET_ResponseHasFailed (DN_NETResponse const* resp);
|
||||
bool DN_NET_ResponseHasSucceeded (DN_NETResponse const* resp);
|
||||
bool DN_NET_ResponseIsReady (DN_NETResponse const* resp);
|
||||
DN_Str8 DN_NET_Str8DiagnosticFromResponse(DN_NETResponse const* resp, DN_Arena *arena);
|
||||
|
||||
// NOTE: Internal functions for different networking implementations to use
|
||||
@@ -4468,6 +4486,15 @@ void DN_NET_EndFinishedRequest (DN_NETRequest *request);
|
||||
#endif
|
||||
|
||||
#if DN_WITH_NET_CURL
|
||||
#if defined(DN_COMPILER_MSVC) || defined(DN_COMPILER_CLANG_CL)
|
||||
#pragma comment(lib, "advapi32")
|
||||
#pragma comment(lib, "ws2_32")
|
||||
#pragma comment(lib, "wldap32")
|
||||
#pragma comment(lib, "crypt32")
|
||||
#pragma comment(lib, "secur32")
|
||||
#pragma comment(lib, "Iphlpapi")
|
||||
#endif
|
||||
|
||||
#if !DN_WITH_OS || !DN_WITH_NET
|
||||
#error "NET API with CURL requires #define DN_WITH_NET 1 and #define DN_WITH_OS 1"
|
||||
#endif
|
||||
|
||||
@@ -57,8 +57,8 @@ pushd %build_dir%
|
||||
call %build_dir%\single_header_generator.exe %script_dir%\Source %script_dir%\Single-Header || echo Single header generation failed&& exit /b 1
|
||||
|
||||
REM Build the single header using the single header (to test that the generated single header)
|
||||
call cl %script_dir%\single_header_generator.cpp -Z7 -nologo -link -D USE_SINGLE_HEADER || echo Single header generator build failed&& exit /b 1
|
||||
call %build_dir%\single_header_generator.exe %script_dir%\Source %script_dir%\Single-Header -D USE_SINGLE_HEADER || echo Single header generation failed&& exit /b 1
|
||||
call cl %script_dir%\single_header_generator.cpp -Z7 -nologo -D USE_SINGLE_HEADER -link || echo Single header generator build failed&& exit /b 1
|
||||
call %build_dir%\single_header_generator.exe %script_dir%\Source %script_dir%\Single-Header || echo Single header generation failed&& exit /b 1
|
||||
)
|
||||
|
||||
where /q clang-cl && (
|
||||
|
||||
@@ -32,7 +32,7 @@ static void AppendCppFileLineByLine(DN_Str8Builder *dest, DN_Str8 cpp_path)
|
||||
DN_ErrSinkEndExitIfErrorF(err, -1, "Failed to load file from '%S' for appending", cpp_path);
|
||||
|
||||
bool inside_clangd_preprocessor_block = false;
|
||||
for (DN_Str8 walker = buffer; walker.size;) {
|
||||
for (DN_Str8 walker = buffer; walker.count;) {
|
||||
// NOTE: Trim the whitespace, mainly for windows, the file we read will have \r\n whereas we just want to emit \n
|
||||
DN_Str8BSplitResult split = DN_Str8BSplit(walker, DN_Str8Lit("\n"));
|
||||
DN_Str8 line = DN_Str8TrimTailWhitespace(split.lhs);
|
||||
@@ -81,7 +81,7 @@ static void AppendCppFileLineByLine(DN_Str8Builder *dest, DN_Str8 cpp_path)
|
||||
DN_Str8BuilderAppendCopy(dest, line);
|
||||
DN_Str8BuilderAppendRef(dest, DN_Str8Lit("\n"));
|
||||
|
||||
if (extra_include_path.size)
|
||||
if (extra_include_path.count)
|
||||
AppendCppFileLineByLine(dest, extra_include_path);
|
||||
}
|
||||
DN_TCScratchEnd(&scratch);
|
||||
|
||||
Reference in New Issue
Block a user