From 3cac240aa386689878e6f29bcb4dc4891edc4236 Mon Sep 17 00:00:00 2001 From: doyle Date: Sat, 15 Oct 2022 17:12:13 +1100 Subject: [PATCH] dqn: Forward Dqn_String8 implementation to Dqn_CString8 --- build.bat | 4 +- build.sh | 2 +- dqn.h | 1476 +++++++++++++++++---------- dqn_tester.h | 22 +- dqn_tests.cpp => dqn_unit_tests.cpp | 501 +++++---- 5 files changed, 1178 insertions(+), 827 deletions(-) rename dqn_tests.cpp => dqn_unit_tests.cpp (83%) diff --git a/build.bat b/build.bat index b6ed166..940557a 100644 --- a/build.bat +++ b/build.bat @@ -28,7 +28,7 @@ pushd Build if not exist msvc mkdir msvc pushd msvc - cl %compile_flags% %msvc_flags% %code_dir%Dqn_Tests.cpp %link_flags% + cl %compile_flags% %msvc_flags% %code_dir%dqn_unit_tests.cpp %link_flags% popd REM Compiler: clang-cl @@ -40,6 +40,6 @@ pushd Build if not exist clang mkdir clang pushd clang - clang-cl %compile_flags% %clang_flags% %code_dir%Dqn_Tests.cpp %link_flags% + clang-cl %compile_flags% %clang_flags% %code_dir%dqn_unit_tests.cpp %link_flags% popd popd diff --git a/build.sh b/build.sh index 4656e2f..4245489 100755 --- a/build.sh +++ b/build.sh @@ -4,5 +4,5 @@ code_dir=${PWD} mkdir -p Build pushd Build - g++ ${code_dir}/Dqn_Tests.cpp -D DQN_TEST_WITH_MAIN -std=c++17 -o Dqn_UnitTests + g++ ${code_dir}/dqn_unit_tests.cpp -D DQN_TEST_WITH_MAIN -std=c++17 -o dqn_unit_tests popd diff --git a/dqn.h b/dqn.h index a97a8ce..9108f31 100644 --- a/dqn.h +++ b/dqn.h @@ -765,6 +765,227 @@ void Dqn_Allocator_Dealloc(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, void *pt #define Dqn_Allocator_New(allocator, Type, zero_mem) Dqn_Allocator_NewTagged(nullptr, allocator, Type, zero_mem) #define Dqn_Allocator_NewTagged(tag, allocator, Type, zero_mem) Dqn_Allocator_NewArrayTagged(tag, allocator, Type, 1 /*count*/, zero_mem) +// NOTE: Dqn_CString8 +// ------------------------------------------------------------------------------------------------- +/// Calculate the size of a cstring literal/array at compile time +/// @param literal The cstring literal/array to calculate the size for +/// @return The size of the cstring not including the null-terminating byte +template constexpr Dqn_usize Dqn_CString8_ArrayCount(char const (&literal)[N]) { (void)literal; return N - 1; } + +/// @copybrief Dqn_CString8_ArrayCount +template constexpr Dqn_isize Dqn_CString8_ArrayCountI(char const (&literal)[N]) { (void)literal; return N - 1; } + +/// @copybrief Dqn_CString8_ArrayCount +template constexpr Dqn_isize Dqn_CString8_ArrayCountInt(char const (&literal)[N]) { (void)literal; return N - 1; } + +/// Calculate the required size to format the given format cstring. +/// @param[in] fmt The format string to calculate the size for +/// @return The size required to format the string, not including the null +/// terminator. +DQN_API Dqn_isize Dqn_CString8_FmtSize(char const *fmt, ...); + +/// @copydoc Dqn_CString8_FmtSize +/// @param[in] args The variable argument list to use to format the string +DQN_API Dqn_isize Dqn_CString8_FmtSizeV(char const *fmt, va_list args); + +/// Split a string into the substring occuring prior and after the first +/// occurence of the `delimiter`. +/// +/// @param[in] string The string to split +/// @param[in] string_size The size of the string +/// @param[in] delimiter The character to split the string on +/// @param[out] lhs_size The size of the left hand side of the split string +/// @param[out] rhs The right hand side of the split string +/// @param[out] rhs_size The size of the right hand side of the split string +/// +/// @return The left hand side of the split string. The original pointer is +/// returned if the arguments were invalid. +DQN_API char const *Dqn_CString8_BinarySplit(char const *string, Dqn_isize string_size, char delimiter, Dqn_isize *lhs_size, char **rhs, Dqn_isize *rhs_size); + +enum struct Dqn_CString8EqCase +{ + Sensitive, + Insensitive, +}; + +/// Compare a string for equality with or without case sensitivity. +/// @param[in] lhs The first string to compare equality with +/// @param[in] rhs The second string to compare equality with +/// @param[in] lhs The first string's size +/// @param[in] rhs The second string's size +/// @param[in] eq_case Set the comparison to be case sensitive or insensitive +/// @return True if the arguments are valid, non-null and the strings +/// are equal, false otherwise. +DQN_API bool Dqn_CString8_Eq(char const *lhs, char const *rhs, Dqn_isize lhs_size = -1, Dqn_isize rhs_size = -1, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive); + +/// Compare a string for equality, case insensitive +/// @see Dqn_CString8_Eq +DQN_API bool Dqn_CString8_EqInsensitive(char const *lhs, char const *rhs, Dqn_isize lhs_size = -1, Dqn_isize rhs_size = -1); + +/// Check if a string starts with the specified prefix +/// @param[in] string The string to check for the prefix +/// @param[in] prefix The prefix to check against the string +/// @param[in] string_size The size of the string +/// @param[in] prefix_size The size of the prefix string +/// @param[in] eq_case Set the comparison to be case sensitive or insensitive +/// @return True if the string is valid, non-null and has the specified prefix, +/// false otherwise. +DQN_API bool Dqn_CString8_StartsWith(char const *string, char const *prefix, Dqn_isize string_size = -1, Dqn_isize prefix_size = -1, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive); + +/// Check if a string starts with the specified prefix, case insensitive +/// @see Dqn_CString8_StartsWith +DQN_API bool Dqn_CString8_StartsWithInsensitive(char const *string, char const *prefix, Dqn_isize string_size = -1, Dqn_isize prefix_size = -1); + +/// Check if a string ends with the specified suffix +/// @param[in] string The string to check for the suffix +/// @param[in] suffix The suffix to check against the string +/// @param[in] eq_case Set the comparison to be case sensitive or insensitive +/// @return True if the string has the specified suffix, false otherwise +DQN_API bool Dqn_CString8_EndsWith(char const *string, char const *suffix, Dqn_isize string_size = -1, Dqn_isize suffix_size = -1, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive); + +/// Check if a string ends with the specified suffix, case insensitive +/// @param[in] string The string to check for the suffix +/// @param[in] suffix The suffix to check against the string +/// @return True if the string has the specified suffix, false otherwise +DQN_API bool Dqn_CString8_EndsWithInsensitive(char const *string, char const *suffix, Dqn_isize string_size = -1, Dqn_isize suffix_size = -1); + +/// Remove the prefix from the given `string` if it starts with it by +/// offsetting the input string. +/// +/// @param[in] string The string to trim +/// @param[in] prefix The prefix to trim from the string +/// @param[in] string_size The size of the string +/// @param[in] prefix_size The size of the prefix +/// @param[in] eq_case Set the comparison to be case sensitive or insensitive +/// @param[out] trimmed_string The size of the trimmed string +/// +/// @return The trimmed string. The original input string is returned if +/// arguments are invalid or no trim was possible. +DQN_API char const *Dqn_CString8_TrimPrefix(char const *string, char const *prefix, Dqn_isize string_size = -1, Dqn_isize prefix_size = -1, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive, Dqn_isize *trimmed_size = nullptr); + +/// Remove the prefix from the given `string` if it ends with it by +/// adjusting the input string size. +/// +/// @param[in] string The string to trim +/// @param[in] suffix The suffix to trim from the string +/// @param[in] string_size The size of the string +/// @param[in] suffix_size The size of the suffix +/// @param[in] eq_case Set the comparison to be case sensitive or insensitive +/// @param[out] trimmed_string The size of the trimmed string +/// +/// @return The trimmed string. The original input string is returned if +/// arguments are invalid or no trim was possible. +DQN_API char const *Dqn_CString8_TrimSuffix(char const *string, char const *suffix, Dqn_isize string_size = -1, Dqn_isize suffix_size = -1, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive, Dqn_isize *trimmed_size = nullptr); + +/// Trim whitespace from the prefix and suffix of the string +/// +/// @param[in] string The string to trim +/// @param[in] string_size The size of the string +/// @param[out] trimmed_string The size of the trimmed string +/// +/// @return The trimmed string. The original input string is returned if +/// arguments are invalid or no trim was possible. +DQN_API char const *Dqn_CString8_TrimWhitespaceAround(char const *string, Dqn_isize string_size = -1, Dqn_isize *trimmed_size = nullptr); + +/// Trim UTF8, UTF16 BE/LE, UTF32 BE/LE byte order mark prefix in the string. +/// +/// @param[in] string The string to trim +/// @param[in] string_size The size of the string +/// @param[out] trimmed_string The size of the trimmed string +/// +/// @return The trimmed string. The original input string is returned if +/// arguments are invalid or no trim was possible. +DQN_API char const *Dqn_CString8_TrimByteOrderMark(char const *string, Dqn_isize string_size = -1, Dqn_isize *trimmed_size = nullptr); + +/// Get the file name from a file path. +/// +/// The file name is evaluated by searching from the end of the string backwards +/// to the first occurring path separator '/' or '\'. If no path separator is +/// found, the original string is returned. This function preserves the file +/// extension if there were any. +/// +/// @param[in] path A file path on the disk +/// @param[in] size The size of the file path string, if size is '-1' the null +/// terminated string length is evaluated. +/// @param[out] file_name_size The size of the returned file name +/// +/// @return The file name in the file path, if none is found, the original path +/// string is returned. Null pointer if arguments are null or invalid. +DQN_API char const *Dqn_CString8_FileNameFromPath(char const *path, Dqn_isize size = -1, Dqn_isize *file_name_size = nullptr); + +/// Convert a number represented as a string to a unsigned 64 bit number. +/// +/// This function behaves similarly to @see Dqn_CString8_ToI64Checked with the +/// exception that only the '+' prefix is permitted. +DQN_API bool Dqn_CString8_ToU64Checked(char const *buf, Dqn_isize size, char separator, uint64_t *output); + +/// Convert a number to an unsigned 64 bit number. +/// +/// @copydetails Dqn_CString8_ToU64Checked +/// +/// @return The parsed number. On failure, this function optimistically returns +/// the most that could be parsed from the string, i.e. "1234 dog" will return +/// "1234". +DQN_API uint64_t Dqn_CString8_ToU64(char const *buf, Dqn_isize size = -1, char separator = ','); + +/// Convert a number represented as a string to a signed 64 bit number. +/// +/// The `separator` is an optional digit separator for example, if `separator` +/// is set to ',' then "1,234" will successfully be parsed to '1234'. +/// +/// Real numbers are truncated. Both '-' and '+' prefixed strings are permitted, +/// i.e. "+1234" -> 1234 and "-1234" -> -1234. Strings must consist entirely of +/// digits, the seperator or the permitted prefixes as previously mentioned, +/// otherwise this function will return false, i.e. "1234 dog" will cause the +/// function to return false, however, the output is greedily converted and will +/// be evaluated to "1234". +/// +/// @param[in] buf The string to convert +/// @param[in] size The size of the string, pass '-1' to calculate the +/// null-terminated string length in the function. +/// @param[in] separator The character used to separate the digits, if any. Set +/// this to 0, if no separators are permitted. +/// @param[out] output The number to write the parsed value to +/// +/// @return True if the string was parsed successfully, false otherwise, e.g. +/// non-permitted character found in string. +DQN_API bool Dqn_CString8_ToI64Checked(char const *buf, Dqn_isize size, char separator, int64_t *output); + +/// Convert a number represented as a string to a signed 64 bit number. +/// +/// This function behaves similarly to @see Dqn_CString8_ToI64Checked +/// +/// @return The parsed number. On failure, this function optimistically returns +/// the most that could be parsed from the string, i.e. "1234 dog" will return +/// "1234". +DQN_API int64_t Dqn_CString8_ToI64(char const *buf, Dqn_isize size = -1, char separator = ','); + +DQN_API char const *Dqn_CString8_FindMulti(char const *buf, char const *find_list[], Dqn_isize const *find_string_sizes, Dqn_isize find_size, Dqn_isize *match_index, Dqn_isize buf_size = -1); +DQN_API char const *Dqn_CString8_Find(char const *buf, char const *find, Dqn_isize buf_size = -1, Dqn_isize find_size = -1, bool case_insensitive = false); + +/// Calculate the string length of the null-terminated string. +/// @param[in] a The string whose length is to be determined +/// @return The length of the string +DQN_API Dqn_isize Dqn_CString8_Size(char const *a); + +DQN_API bool Dqn_CString8_Match(char const *src, char const *find, int find_size); +DQN_API char const *Dqn_CString8_SkipToChar(char const *src, char ch); +DQN_API char const *Dqn_CString8_SkipToNextAlphaNum(char const *src); +DQN_API char const *Dqn_CString8_SkipToNextDigit(char const *src); +DQN_API char const *Dqn_CString8_SkipToNextChar(char const *src); +DQN_API char const *Dqn_CString8_SkipToNextWord(char const *src); +DQN_API char const *Dqn_CString8_SkipToNextWhitespace(char const *src); +DQN_API char const *Dqn_CString8_SkipWhitespace(char const *src); +DQN_API char const *Dqn_CString8_SkipToCharInPlace(char const **src, char ch); +DQN_API char const *Dqn_CString8_SkipToNextAlphaNumInPlace(char const **src); +DQN_API char const *Dqn_CString8_SkipToNextCharInPlace(char const **src); +DQN_API char const *Dqn_CString8_SkipToNextWhitespaceInPlace(char const **src); +DQN_API char const *Dqn_CString8_SkipToNextWordInPlace(char const **src); +DQN_API char const *Dqn_CString8_SkipWhitespaceInPlace(char const **src); +DQN_API bool Dqn_CString8_IsAllDigits(char const *src, Dqn_isize size); + +DQN_API Dqn_isize Dqn_CString16_Size(wchar_t const *a); + // NOTE: Dqn_String8 // ------------------------------------------------------------------------------------------------- /// Construct a UTF8 c-string literal into a Dqn_String8 referencing a string @@ -790,9 +1011,9 @@ struct Dqn_String8 /// A pointer and length style string that holds slices to UT char *end () { return data + size; } ///< End iterator for range-for loops }; -struct Dqn_String8_Link { +struct Dqn_String8Link { Dqn_String8 string; ///< The string - Dqn_String8_Link *next; ///< The next string in the linked list + Dqn_String8Link *next; ///< The next string in the linked list }; struct Dqn_String16 /// A pointer and length style string that holds slices to UTF16 bytes. @@ -854,30 +1075,20 @@ DQN_API Dqn_String8 Dqn_String8_Fmt_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, /// @param[in] arena The allocator the string will be allocated from /// @param[in] fmt The printf style format cstring /// @param[in] va The variable argument list -#define Dqn_String8_FmtV(allocator, fmt, va) Dqn_String8_FmtVTagged(nullptr, allocator, fmt, va) +#define Dqn_String8_FmtV(allocator, fmt, args) Dqn_String8_FmtVTagged(nullptr, allocator, fmt, args) /// @copybrief Dqn_String8_FmtV The tagged variant takes a cstring to describe the /// purpose of the allocation. /// @param[in] tag A cstring to describe the nature of the allocation /// @copydetails Dqn_String8_FmtV -#define Dqn_String8_FmtVTagged(tag, allocator, fmt, va) Dqn_String8_FmtV_(DQN_CALL_SITE(tag) allocator, fmt, va) +#define Dqn_String8_FmtVTagged(tag, allocator, fmt, args) Dqn_String8_FmtV_(DQN_CALL_SITE(tag) allocator, fmt, args) /// @copybrief Dqn_String8_FmtV Internal function, prefer Dqn_String8_FmtV() /// @param[in] DQN_CALL_SITE_ARGS Call site macro that is compiled out if call /// site information is not enabled. Exposes call site information on /// allocation. /// @copydetails Dqn_String8_FmtV -DQN_API Dqn_String8 Dqn_String8_FmtV_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *fmt, va_list va); - -/// Calculate the required size to format the given format string. -/// @param[in] fmt The format string to calculate the size for -/// @return The size required to format the string, not including the null -/// terminator. -DQN_API Dqn_isize Dqn_String8_FmtSize(char const *fmt, ...); - -/// @copybrief Dqn_String8_FmtSize -/// @param[in] args The variable argument list to use to format the string -DQN_API Dqn_isize Dqn_String8_FmtSizeV(char const *fmt, va_list args); +DQN_API Dqn_String8 Dqn_String8_FmtV_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *fmt, va_list args); /// Create an empty string with the requested size /// @param[in] allocator The allocator the string will be allocated from @@ -946,51 +1157,54 @@ DQN_API Dqn_String8 Dqn_String8_CopyCString_(DQN_CALL_SITE_ARGS Dqn_Allocator al /// @copydetails Dqn_String8_Copy DQN_API Dqn_String8 Dqn_String8_Copy_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, Dqn_String8 string); -enum struct Dqn_String8_EqCase -{ - Sensitive, - Insensitive, -}; +/// @see Dqn_CString8_BinarySplit +DQN_API Dqn_String8 Dqn_String8_BinarySplit(Dqn_String8 string, char delimiter, Dqn_String8 *rhs); -// Compare a string for equality -// @param[in] lhs The first string to compare equality with -// @param[in] rhs The second string to compare equality with -// @param[in] eq_case Set the comparison to be case sensitive or insensitive -// @return True if the strings are equal, false otherwise. -DQN_API bool Dqn_String8_Eq(Dqn_String8 lhs, Dqn_String8 rhs, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); +/// @see Dqn_CString8_Eq +DQN_API bool Dqn_String8_Eq(Dqn_String8 lhs, Dqn_String8 rhs, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive); -// Compare a string for equality, case insensitive -// @param[in] lhs The first string to compare equality with -// @param[in] rhs The second string to compare equality with -// @return True if the strings are equal, false otherwise. +/// @see Dqn_CString8_EqInsensitive DQN_API bool Dqn_String8_EqInsensitive(Dqn_String8 lhs, Dqn_String8 rhs); -// Check if a string starts with the specified prefix -// @param[in] string The string to check for the prefix -// @param[in] prefix The prefix to check against the string -// @param[in] eq_case Set the comparison to be case sensitive or insensitive -// @return True if the string has the specified prefix, false otherwise -DQN_API bool Dqn_String8_StartsWith(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); +/// @see Dqn_CString8_StartsWith +DQN_API bool Dqn_String8_StartsWith(Dqn_String8 string, Dqn_String8 prefix, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive); -// Check if a string starts with the specified prefix, case insensitive -// @param[in] string The string to check for the prefix -// @param[in] prefix The prefix to check against the string -// @return True if the string has the specified prefix, false otherwise +/// @see Dqn_CString8_StartsWithInsensitive DQN_API bool Dqn_String8_StartsWithInsensitive(Dqn_String8 string, Dqn_String8 prefix); -// Check if a string ends with the specified suffix -// @param[in] string The string to check for the suffix -// @param[in] suffix The suffix to check against the string -// @param[in] eq_case Set the comparison to be case sensitive or insensitive -// @return True if the string has the specified suffix, false otherwise -DQN_API bool Dqn_String8_EndsWith(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); +/// @see Dqn_CString8_EndsWith +DQN_API bool Dqn_String8_EndsWith(Dqn_String8 string, Dqn_String8 prefix, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive); -// Check if a string ends with the specified suffix, case insensitive -// @param[in] string The string to check for the suffix -// @param[in] suffix The suffix to check against the string -// @return True if the string has the specified suffix, false otherwise +/// @see Dqn_CString8_EndsWithInsensitive DQN_API bool Dqn_String8_EndsWithInsensitive(Dqn_String8 string, Dqn_String8 prefix); +/// @see Dqn_CString8_TrimPrefix +DQN_API Dqn_String8 Dqn_String8_TrimPrefix(Dqn_String8 string, Dqn_String8 prefix, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive); + +/// @see Dqn_CString8_TrimSuffix +DQN_API Dqn_String8 Dqn_String8_TrimSuffix(Dqn_String8 string, Dqn_String8 suffix, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive); + +/// @see Dqn_CString8_TrimWhitespaceAround +DQN_API Dqn_String8 Dqn_String8_TrimWhitespaceAround(Dqn_String8 string); + +/// @see Dqn_CString8_TrimByteOrderMark +DQN_API Dqn_String8 Dqn_String8_TrimByteOrderMark(Dqn_String8 string); + +/// @see Dqn_CString8_FileNameFromPath +DQN_API Dqn_String8 Dqn_String8_FileNameFromPath(Dqn_String8 path); + +/// @see Dqn_CString8_ToU64Checked +DQN_API bool Dqn_String8_ToU64Checked(Dqn_String8 string, char separator, uint64_t *output); + +/// @see Dqn_CString8_ToU64 +DQN_API uint64_t Dqn_String8_ToU64(Dqn_String8 string, char separator); + +/// @see Dqn_CString8_ToI64Checked +DQN_API bool Dqn_String8_ToI64Checked(Dqn_String8 string, char separator, int64_t *output); + +/// @see Dqn_CString8_ToI64 +DQN_API int64_t Dqn_String8_ToI64(Dqn_String8 string, char separator); + /// Split a string by the delimiting character. /// This function can evaluate the number of splits required in the return value /// by setting `splits` to null and `splits_count` to 0. @@ -1005,12 +1219,7 @@ DQN_API bool Dqn_String8_EndsWithInsensitive(Dqn_String8 string, Dqn_String8 pre /// capacity given by the caller, i.e. `splits_count`. This function should be /// called again with a sufficiently sized array if all splits are desired. DQN_API Dqn_isize Dqn_String8_Split(Dqn_String8 string, char delimiter, Dqn_String8 *splits, Dqn_isize splits_count); -DQN_API Dqn_String8 Dqn_String8_TrimPrefix(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); -DQN_API Dqn_String8 Dqn_String8_TrimSuffix(Dqn_String8 string, Dqn_String8 suffix, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); -DQN_API Dqn_String8 Dqn_String8_TrimWhitespaceAround(Dqn_String8 string); -/// Trim UTF8, UTF16 BE/LE, UTF32 BE/LE byte order mark in the string. -DQN_API Dqn_String8 Dqn_String8_TrimByteOrderMark(Dqn_String8 string); DQN_API bool Dqn_String8_IsAllDigits(Dqn_String8 string); DQN_API bool Dqn_String8_IsAllHex(Dqn_String8 string); DQN_API bool Dqn_String8_HasChar(Dqn_String8 string, char ch); @@ -1022,24 +1231,15 @@ DQN_API void Dqn_String8_Remove(Dqn_String8 *string, Dqn_isize begin, Dqn /// @param[in] start_index Set an index within the string string to start the /// search from, if not desired, set to 0 /// @return The index of the matching find, -1 if it is not found -DQN_API Dqn_isize Dqn_String8_FindOffset(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); +DQN_API Dqn_isize Dqn_String8_FindOffset(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive); /// @param start_index Set an index within the string string to start the search /// from, if not desired, set to 0 /// @return A string that points to the matching find, otherwise a 0 length string. -DQN_API Dqn_String8 Dqn_String8_Find(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); -DQN_API Dqn_String8 Dqn_String8_Replace(Dqn_String8 string, Dqn_String8 find, Dqn_String8 replace, Dqn_isize start_index, Dqn_Allocator allocator, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); -DQN_API Dqn_String8 Dqn_String8_ReplaceInsensitive(Dqn_String8 string, Dqn_String8 find, Dqn_String8 replace, Dqn_isize start_index, Dqn_Allocator allocator); +DQN_API Dqn_String8 Dqn_String8_Find(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive); -/// Get the file name from a file path by searching from the end of the string -/// backwards to the first occurring path separator '/' or '\'. If no path -/// separator is found, the original string is returned. -/// @param[in] path A file path on the disk -/// @return The file name of the file path, if none is found, the path string is -/// returned. -DQN_API Dqn_String8 Dqn_String8_FileNameFromPath(Dqn_String8 path); -DQN_API uint64_t Dqn_String8_ToU64(Dqn_String8 string); -DQN_API uint64_t Dqn_String8_ToI64(Dqn_String8 string); +DQN_API Dqn_String8 Dqn_String8_Replace(Dqn_String8 string, Dqn_String8 find, Dqn_String8 replace, Dqn_isize start_index, Dqn_Allocator allocator, Dqn_CString8EqCase eq_case = Dqn_CString8EqCase::Sensitive); +DQN_API Dqn_String8 Dqn_String8_ReplaceInsensitive(Dqn_String8 string, Dqn_String8 find, Dqn_String8 replace, Dqn_isize start_index, Dqn_Allocator allocator); // NOTE: Dqn_Log // ------------------------------------------------------------------------------------------------- @@ -1113,7 +1313,7 @@ struct Dqn_AllocationTrace char const *msg; }; -struct Dqn_AllocationTracer_ +struct Dqn_AllocationTracer { // NOTE: Read only fields Dqn_TicketMutex mutex; @@ -1474,8 +1674,8 @@ template DQN_API Dqn_String8 Dqn_FixedString_ToString // ----------------------------------------------------------------------------- struct Dqn_String8Builder { Dqn_Allocator allocator; ///< Allocator to use to back the string list - Dqn_String8_Link *head; ///< First string in the linked list of strings - Dqn_String8_Link *tail; ///< Last string in the linked list of strings + Dqn_String8Link *head; ///< First string in the linked list of strings + Dqn_String8Link *tail; ///< Last string in the linked list of strings ptrdiff_t string_size; ///< The size in bytes necessary to construct the current string ptrdiff_t count; ///< The number of links in the linked list of strings }; @@ -1853,7 +2053,7 @@ DQN_API Dqn_isize Dqn_Safe_TruncateI64ToISize (uint64_t val); DQN_API uint32_t Dqn_Safe_TruncateU64ToU32 (uint64_t val); DQN_API uint16_t Dqn_Safe_TruncateU64ToU16 (uint64_t val); DQN_API uint8_t Dqn_Safe_TruncateU64ToU8 (uint64_t val); -DQN_API uint64_t Dqn_Safe_TruncateU64ToI64 (uint64_t val); +DQN_API int64_t Dqn_Safe_TruncateU64ToI64 (uint64_t val); DQN_API int32_t Dqn_Safe_TruncateU64ToI32 (uint64_t val); DQN_API int16_t Dqn_Safe_TruncateU64ToI16 (uint64_t val); DQN_API uint8_t Dqn_Safe_TruncateU64ToI8 (uint64_t val); @@ -1914,48 +2114,6 @@ DQN_API Dqn_Array Dqn_Hex_CStringToU8Array(char const *hex, Dqn_isize DQN_API Dqn_Array Dqn_Hex_StringToU8Array(Dqn_String8 const hex, Dqn_Arena *arena); #endif // DQN_WITH_HEX -// NOTE: Dqn_CString8 -// ------------------------------------------------------------------------------------------------- -/// Calculate the size of a cstring literal/array at compile time -/// @param literal The cstring literal/array to calculate the size for -/// @return The size of the cstring not including the null-terminating byte -template constexpr Dqn_usize Dqn_CString8_ArrayCount(char const (&literal)[N]) { (void)literal; return N - 1; } - -/// @copybrief Dqn_CString8_ArrayCount -template constexpr Dqn_isize Dqn_CString8_ArrayCountI(char const (&literal)[N]) { (void)literal; return N - 1; } - -/// @copybrief Dqn_CString8_ArrayCount -template constexpr Dqn_isize Dqn_CString8_ArrayCountInt(char const (&literal)[N]) { (void)literal; return N - 1; } - -DQN_API bool Dqn_CString8_Equals(char const *a, char const *b, Dqn_isize a_size = -1, Dqn_isize b_size = -1); -DQN_API char const *Dqn_CString8_FindMulti(char const *buf, char const *find_list[], Dqn_isize const *find_string_sizes, Dqn_isize find_size, Dqn_isize *match_index, Dqn_isize buf_size = -1); -DQN_API char const *Dqn_CString8_Find(char const *buf, char const *find, Dqn_isize buf_size = -1, Dqn_isize find_size = -1, bool case_insensitive = false); -DQN_API char const *Dqn_CString8_FileNameFromPath(char const *path, Dqn_isize size = -1, Dqn_isize *file_name_size = nullptr); -DQN_API Dqn_isize Dqn_CString8_Size(char const *a); -DQN_API bool Dqn_CString8_Match(char const *src, char const *find, int find_size); -DQN_API char const *Dqn_CString8_SkipToChar(char const *src, char ch); -DQN_API char const *Dqn_CString8_SkipToNextAlphaNum(char const *src); -DQN_API char const *Dqn_CString8_SkipToNextDigit(char const *src); -DQN_API char const *Dqn_CString8_SkipToNextChar(char const *src); -DQN_API char const *Dqn_CString8_SkipToNextWord(char const *src); -DQN_API char const *Dqn_CString8_SkipToNextWhitespace(char const *src); -DQN_API char const *Dqn_CString8_SkipWhitespace(char const *src); -DQN_API char const *Dqn_CString8_SkipToCharInPlace(char const **src, char ch); -DQN_API char const *Dqn_CString8_SkipToNextAlphaNumInPlace(char const **src); -DQN_API char const *Dqn_CString8_SkipToNextCharInPlace(char const **src); -DQN_API char const *Dqn_CString8_SkipToNextWhitespaceInPlace(char const **src); -DQN_API char const *Dqn_CString8_SkipToNextWordInPlace(char const **src); -DQN_API char const *Dqn_CString8_SkipWhitespaceInPlace(char const **src); -DQN_API char const *Dqn_CString8_TrimWhitespaceAround(char const *src, Dqn_isize size, Dqn_isize *new_size); -DQN_API char const *Dqn_CString8_TrimPrefix(char const *src, Dqn_isize size, char const *prefix, Dqn_isize prefix_size, Dqn_isize *trimmed_size); -DQN_API bool Dqn_CString8_IsAllDigits(char const *src, Dqn_isize size); - -// separator: The separator between the thousand-th digits, i.e. separator = ',' converts '1,234' to '1234'. -DQN_API uint64_t Dqn_CString8_ToU64(char const *buf, Dqn_isize size = -1, char separator = ','); -DQN_API uint64_t Dqn_CString8_ToI64(char const *buf, Dqn_isize size = -1, char separator = ','); - -DQN_API Dqn_isize Dqn_CString16_Size(wchar_t const *a); - // NOTE: Dqn_Fs_ // ------------------------------------------------------------------------------------------------- struct Dqn_Fs_Info @@ -3820,6 +3978,551 @@ void Dqn_AllocationTracer_Remove(Dqn_AllocationTracer *tracer, void *ptr) #endif } +// NOTE: Dqn_CString8 +// ------------------------------------------------------------------------------------------------- +DQN_API Dqn_isize Dqn_CString8_FmtSize(char const *fmt, ...) +{ + va_list args; + va_start(args, fmt); + Dqn_isize result = STB_SPRINTF_DECORATE(vsnprintf)(nullptr, 0, fmt, args); + va_end(args); + return result; +} + +DQN_API Dqn_isize Dqn_CString8_FmtSizeV(char const *fmt, va_list args) +{ + va_list args_copy; + va_copy(args_copy, args); + Dqn_isize result = STB_SPRINTF_DECORATE(vsnprintf)(nullptr, 0, fmt, args_copy); + va_end(args_copy); + return result; +} + +static bool Dqn_CString8_Validate_(char const *lhs, Dqn_isize *lhs_size) +{ + if (lhs_size && *lhs_size <= -1) + *lhs_size = Dqn_CString8_Size(lhs); + + if (!lhs || !lhs_size) + return false; + + return true; +} + +DQN_API char const *Dqn_CString8_BinarySplit(char const *string, Dqn_isize string_size, char delimiter, Dqn_isize *lhs_size, char **rhs, Dqn_isize *rhs_size) +{ + char const *result = string; + if (lhs_size) + *lhs_size = 0; + if (rhs_size) + *rhs_size = 0; + if (rhs && *rhs) { + *rhs = nullptr; + } + + if (!Dqn_CString8_Validate_(string, &string_size)) { + return result; + } + + Dqn_isize offset = 0; + while (offset < string_size && string[offset] != delimiter) { + offset++; + } + + // NOTE: LHS, the string before the delimiter + result = string; + if (lhs_size) + *lhs_size = offset; + + // NOTE: RHS, the string after the delimiter + if (rhs && *rhs) { + *rhs = DQN_CAST(char *)(string + offset + 1); + *rhs_size = (string + string_size) - (*rhs); + } + + return result; +} + +DQN_API bool Dqn_CString8_Eq(char const *lhs, char const *rhs, Dqn_isize lhs_size, Dqn_isize rhs_size, Dqn_CString8EqCase eq_case) +{ + if (!Dqn_CString8_Validate_(lhs, &lhs_size) || !Dqn_CString8_Validate_(rhs, &rhs_size)) { + return false; + } + + if (lhs_size != rhs_size) + return false; + + bool result = lhs_size == rhs_size; + if (result) { + if (eq_case == Dqn_CString8EqCase::Sensitive) { + result = (DQN_MEMCMP(lhs, rhs, DQN_CAST(size_t)lhs_size) == 0); + } else { + for (Dqn_isize index = 0; index < lhs_size && result; index++) + result = (Dqn_Char_ToLower(lhs[index]) == Dqn_Char_ToLower(rhs[index])); + } + } + + return result; +} + +DQN_API bool Dqn_CString8_EqInsensitive(char const *lhs, char const *rhs, Dqn_isize lhs_size, Dqn_isize rhs_size, Dqn_CString8EqCase eq_case) +{ + bool result = Dqn_CString8_Eq(lhs, rhs, lhs_size, rhs_size, Dqn_CString8EqCase::Insensitive); + return result; +} + +DQN_API bool Dqn_CString8_StartsWith(char const *string, char const *prefix, Dqn_isize string_size, Dqn_isize prefix_size, Dqn_CString8EqCase eq_case) +{ + if (!Dqn_CString8_Validate_(string, &string_size) || !Dqn_CString8_Validate_(prefix, &prefix_size)) { + return false; + } + + bool result = false; + if (string_size >= prefix_size) + result = Dqn_CString8_Eq(string /*lhs*/, prefix /*rhs*/, prefix_size /*lhs_size*/, prefix_size /*rhs_size*/, eq_case); + + return result; +} + +DQN_API bool Dqn_CString8_StartsWithInsensitive(char const *string, char const *prefix, Dqn_isize string_size, Dqn_isize prefix_size) +{ + bool result = Dqn_CString8_StartsWith(string, prefix, string_size, prefix_size, Dqn_CString8EqCase::Insensitive); + return result; +} + +DQN_API bool Dqn_CString8_EndsWith(char const *string, char const *suffix, Dqn_isize string_size, Dqn_isize suffix_size, Dqn_CString8EqCase eq_case) +{ + if (!Dqn_CString8_Validate_(string, &string_size) || !Dqn_CString8_Validate_(suffix, &suffix_size)) { + return false; + } + + bool result = false; + if (string_size >= suffix_size) { + char const *string_tail = (string + string_size) - suffix_size; + result = Dqn_CString8_Eq(string_tail /*lhs*/, suffix /*rhs*/, suffix_size /*lhs_size*/, suffix_size /*rhs_size*/, eq_case); + } + + return result; +} + +DQN_API bool Dqn_CString8_EndsWithInsensitive(char const *string, char const *suffix, Dqn_isize string_size, Dqn_isize suffix_size) +{ + bool result = Dqn_CString8_EndsWith(string, suffix, string_size, suffix_size, Dqn_CString8EqCase::Insensitive); + return result; +} + +DQN_API char const *Dqn_CString8_TrimPrefix(char const *string, char const *prefix, Dqn_isize string_size, Dqn_isize prefix_size, Dqn_CString8EqCase eq_case, Dqn_isize *trimmed_size) +{ + char const *result = string; + bool starts_with = Dqn_CString8_StartsWith(string, prefix, string_size, prefix_size, eq_case); + + if (starts_with) { + result = string + prefix_size; + } + + if (trimmed_size) { + if (starts_with) + *trimmed_size = string_size - prefix_size; + else + *trimmed_size = string_size; + } + + return result; +} + +DQN_API char const *Dqn_CString8_TrimSuffix(char const *string, char const *suffix, Dqn_isize string_size, Dqn_isize suffix_size, Dqn_CString8EqCase eq_case, Dqn_isize *trimmed_size) +{ + char const *result = string; + bool ends_with = Dqn_CString8_EndsWith(string, suffix, string_size, suffix_size, eq_case); + + if (trimmed_size) { + if (ends_with) + *trimmed_size = string_size - suffix_size; + else + *trimmed_size = string_size; + } + + return result; +} + +DQN_API char const *Dqn_CString8_TrimWhitespaceAround(char const *string, Dqn_isize string_size, Dqn_isize *trimmed_size) +{ + char const *result = string; + if (trimmed_size) + *trimmed_size = 0; + + if (!Dqn_CString8_Validate_(string, &string_size)) { + return result; + } + + char const *start = result; + char const *end = start + string_size; + + while (start < end && Dqn_Char_IsWhitespace(start[0])) + start++; + + while (end > start && Dqn_Char_IsWhitespace(end[-1])) + end--; + + result = start; + Dqn_isize result_size = end - start; + DQN_ASSERT(result_size >= 0); + + if (trimmed_size) + *trimmed_size = result_size; + + return result; +} + +DQN_API char const *Dqn_CString8_TrimByteOrderMark(char const *string, Dqn_isize string_size, Dqn_isize *trimmed_size) +{ + // TODO(dqn): This is little endian + char const *result = string; + if (trimmed_size) + *trimmed_size = string_size; + + if (!Dqn_CString8_Validate_(string, &string_size)) + return result; + + char const UTF8_BOM[] = "\xEF\xBB\xBF"; + char const UTF16_BOM_BE[] = "\xEF\xFF"; + char const UTF16_BOM_LE[] = "\xFF\xEF"; + char const UTF32_BOM_BE[] = "\x00\x00\xFE\xFF"; + char const UTF32_BOM_LE[] = "\xFF\xFE\x00\x00"; + + Dqn_isize result_size = string_size; + result = Dqn_CString8_TrimPrefix(result, UTF8_BOM, result_size, DQN_CHAR_COUNT(UTF8_BOM), Dqn_CString8EqCase::Sensitive, &result_size); + result = Dqn_CString8_TrimPrefix(result, UTF16_BOM_BE, result_size, DQN_CHAR_COUNT(UTF16_BOM_BE), Dqn_CString8EqCase::Sensitive, &result_size); + result = Dqn_CString8_TrimPrefix(result, UTF16_BOM_LE, result_size, DQN_CHAR_COUNT(UTF16_BOM_LE), Dqn_CString8EqCase::Sensitive, &result_size); + result = Dqn_CString8_TrimPrefix(result, UTF32_BOM_BE, result_size, DQN_CHAR_COUNT(UTF32_BOM_BE), Dqn_CString8EqCase::Sensitive, &result_size); + result = Dqn_CString8_TrimPrefix(result, UTF32_BOM_LE, result_size, DQN_CHAR_COUNT(UTF32_BOM_LE), Dqn_CString8EqCase::Sensitive, &result_size); + + if (trimmed_size) + *trimmed_size = result_size; + + return result; +} + +DQN_API char const *Dqn_CString8_FileNameFromPath(char const *path, Dqn_isize path_size, Dqn_isize *file_name_size) +{ + char const *result = path; + if (file_name_size) + *file_name_size = path_size; + + if (!Dqn_CString8_Validate_(path, &path_size)) + return result; + + Dqn_isize result_size = path_size; + for (Dqn_isize i = (result_size - 1); i >= 0; --i) { + if (result[i] == '\\' || result[i] == '/') { + char const *file_end = result + result_size; + result = result + (i + 1); + result_size = file_end - result; + break; + } + } + + if (file_name_size) + *file_name_size = result_size; + + return result; +} + +DQN_API bool Dqn_CString8_ToU64Checked(char const *buf, Dqn_isize size, char separator, uint64_t *output) +{ + // NOTE: Argument check + if (!Dqn_CString8_Validate_(buf, &size)) { + return false; + } + + // NOTE: Sanitize input/output + *output = 0; + Dqn_isize start_index = Dqn_CString8_TrimWhitespaceAround(buf, size, &size /*new_size*/) - buf; + DQN_ASSERT(start_index <= size); + + if (size == 0) + return true; + + // NOTE: Handle prefix '+' + if (!Dqn_Char_IsDigit(buf[start_index])) { + if (buf[start_index] == '+') { + start_index++; + } else { + return false; + } + } + + // NOTE: Convert the string number to the binary number + for (Dqn_isize index = start_index; index < size; ++index) { + char ch = buf[index]; + if (index) { + if (separator != 0 && ch == separator) + continue; + } + + if (ch < '0' || ch > '9') + return false; + + *output = Dqn_Safe_MulU64(*output, 10); + uint64_t digit = ch - '0'; + *output = Dqn_Safe_AddU64(*output, digit); + } + + return true; +} + +DQN_API uint64_t Dqn_CString8_ToU64(char const *buf, Dqn_isize size, char separator) +{ + uint64_t result = 0; + Dqn_CString8_ToU64Checked(buf, size, separator, &result); + return result; +} + +DQN_API bool Dqn_CString8_ToI64Checked(char const *buf, Dqn_isize size, char separator, int64_t *output) +{ + // NOTE: Sanitize input/output + *output = 0; + Dqn_isize start_index = Dqn_CString8_TrimWhitespaceAround(buf, size, &size /*new_size*/) - buf; + DQN_ASSERT(start_index <= size); + + if (size == 0) + return true; + + // NOTE: Handle prefix '-' or '+' + bool negative = false; + if (!Dqn_Char_IsDigit(buf[start_index])) { + negative = (buf[start_index] == '-'); + if (negative || buf[start_index] == '+') { + start_index++; + } else { + return false; // NOTE: Prefix not handled + } + } + + // NOTE: Convert the string number to the binary number + for (Dqn_isize index = start_index; index < size; ++index) { + char ch = buf[index]; + if (index) { + if (separator != 0 && ch == separator) + continue; + } + + if (ch < '0' || ch > '9') + return false; + + *output = Dqn_Safe_MulI64(*output, 10); + int64_t val = ch - '0'; + *output = Dqn_Safe_AddI64(*output, val); + } + + if (negative) + *output *= -1; + + return true; +} + +DQN_API int64_t Dqn_CString8_ToI64(char const *buf, Dqn_isize size, char separator) +{ + int64_t result = 0; + Dqn_CString8_ToI64Checked(buf, size, separator, &result); + return result; +} + + +DQN_API char const *Dqn_CString8_FindMulti(char const *buf, char const *find_list[], Dqn_isize const *find_string_sizes, Dqn_isize find_size, Dqn_isize *match_index, Dqn_isize buf_size) +{ + char const *result = nullptr; + if (find_size == 0) return result; + if (buf_size < 0) buf_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(buf); + + char const *buf_end = buf + buf_size; + for (; buf != buf_end; ++buf) { + Dqn_isize remaining = static_cast(buf_end - buf); + for (Dqn_isize find_index = 0; find_index < find_size; find_index++) { + char const *find = find_list[find_index]; + Dqn_isize find_str_size = find_string_sizes[find_index]; + if (remaining < find_str_size) continue; + + if (strncmp(buf, find, DQN_CAST(size_t)find_str_size) == 0) { + result = buf; + *match_index = find_index; + return result; + } + } + + } + return result; +} + +DQN_API char const *Dqn_CString8_Find(char const *buf, char const *find, Dqn_isize buf_size, Dqn_isize find_size, bool case_insensitive) +{ + if (find_size == 0) return nullptr; + if (buf_size < 0) buf_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(buf); + if (find_size < 0) find_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(find); + + char const *buf_end = buf + buf_size; + char const *result = nullptr; + for (; buf != buf_end; ++buf) + { + Dqn_isize remaining = static_cast(buf_end - buf); + if (remaining < find_size) break; + + bool matched = true; + for (Dqn_isize index = 0; index < find_size; index++) + { + char lhs = buf[index]; + char rhs = find[index]; + + if (case_insensitive) + { + lhs = Dqn_Char_ToLower(lhs); + rhs = Dqn_Char_ToLower(rhs); + } + + if (lhs != rhs) + { + matched = false; + break; + } + } + + if (matched) + { + result = buf; + break; + } + } + return result; +} + +DQN_API Dqn_isize Dqn_CString8_Size(char const *src) +{ + Dqn_isize result = 0; + while (src && src[0] != 0) { + src++; + result++; + } + + return result; +} + +DQN_API bool Dqn_CString8_Match(char const *src, char const *find, int find_size) +{ + if (find_size == -1) find_size = Dqn_Safe_TruncateUSizeToInt(Dqn_CString8_Size(find)); + bool result = (DQN_MEMCMP(src, find, DQN_CAST(size_t)find_size) == 0); + return result; +} + +DQN_API char const *Dqn_CString8_SkipToChar(char const *src, char ch) +{ + char const *result = src; + while (result && result[0] && result[0] != ch) ++result; + return result; +} + +DQN_API char const *Dqn_CString8_SkipToNextAlphaNum(char const *src) +{ + char const *result = src; + while (result && result[0] && !Dqn_Char_IsAlphaNum(result[0])) ++result; + return result; +} + +DQN_API char const *Dqn_CString8_SkipToNextDigit(char const *src) +{ + char const *result = src; + while (result && result[0] && !Dqn_Char_IsDigit(result[0])) ++result; + return result; +} + +DQN_API char const *Dqn_CString8_SkipToNextChar(char const *src) +{ + char const *result = src; + while (result && result[0] && !Dqn_Char_IsAlpha(result[0])) ++result; + return result; +} + +DQN_API char const *Dqn_CString8_SkipToNextWord(char const *src) +{ + char const *result = src; + while (result && result[0] && !Dqn_Char_IsWhitespace(result[0])) ++result; + while (result && result[0] && Dqn_Char_IsWhitespace(result[0])) ++result; + return result; +} + +DQN_API char const *Dqn_CString8_SkipToNextWhitespace(char const *src) +{ + char const *result = src; + while (result && result[0] && !Dqn_Char_IsWhitespace(result[0])) ++result; + return result; +} + +DQN_API char const *Dqn_CString8_SkipWhitespace(char const *src) +{ + char const *result = src; + while (result && result[0] && Dqn_Char_IsWhitespace(result[0])) ++result; + return result; +} + +DQN_API char const *Dqn_CString8_SkipToCharInPlace(char const **src, char ch) +{ + *src = Dqn_CString8_SkipToChar(*src, ch); + return *src; +} + +DQN_API char const *Dqn_CString8_SkipToNextAlphaNumInPlace(char const **src) +{ + *src = Dqn_CString8_SkipToNextAlphaNum(*src); + return *src; +} + +DQN_API char const *Dqn_CString8_SkipToNextCharInPlace(char const **src) +{ + *src = Dqn_CString8_SkipToNextChar(*src); + return *src; +} + +DQN_API char const *Dqn_CString8_SkipToNextWhitespaceInPlace(char const **src) +{ + *src = Dqn_CString8_SkipToNextWhitespace(*src); + return *src; +} + +DQN_API char const *Dqn_CString8_SkipToNextWordInPlace(char const **src) +{ + *src = Dqn_CString8_SkipToNextWord(*src); + return *src; +} + +DQN_API char const *Dqn_CString8_SkipWhitespaceInPlace(char const **src) +{ + *src = Dqn_CString8_SkipWhitespace(*src); + return *src; +} + +DQN_API bool Dqn_CString8_IsAllDigits(char const *src, Dqn_isize size) +{ + if (!src) return false; + if (size <= -1) size = Dqn_CString8_Size(src); + for (Dqn_isize ch_index = 0; ch_index < size; ch_index++) { + if (!(src[ch_index] >= '0' && src[ch_index] <= '9')) + return false; + } + bool result = src && size > 0; + return result; +} + +DQN_API Dqn_isize Dqn_CString16_Size(wchar_t const *src) +{ + Dqn_isize result = 0; + while (src && src[0] != 0) { + src++; + result++; + } + + return result; +} + + // NOTE: Dqn_String8 // ------------------------------------------------------------------------------------------------- DQN_API Dqn_String8 Dqn_String8_Init(char const *string, Dqn_isize size) @@ -3865,43 +4568,25 @@ DQN_API Dqn_String8 Dqn_String8_Fmt_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, return result; } -DQN_API Dqn_String8 Dqn_String8_FmtV_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *fmt, va_list va) +DQN_API Dqn_String8 Dqn_String8_FmtV_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *fmt, va_list args) { Dqn_String8 result = {}; if (!fmt) return result; - va_list va2; - va_copy(va2, va); - int size = STB_SPRINTF_DECORATE(vsnprintf)(nullptr, 0, fmt, va2); - va_end(va2); + va_list args_copy; + va_copy(args_copy, args); + Dqn_isize size = Dqn_CString8_FmtSizeV(fmt, args_copy); + va_end(args_copy); result = Dqn_String8_Allocate_(DQN_CALL_SITE_ARGS_INPUT allocator, size, Dqn_ZeroMem_No); if (Dqn_String8_IsValid(result)) { - STB_SPRINTF_DECORATE(vsnprintf)(result.data, size + 1 /*null-terminator*/, fmt, va); + STB_SPRINTF_DECORATE(vsnprintf)(result.data, size + 1 /*null-terminator*/, fmt, args); result.data[result.size] = 0; } return result; } -DQN_API Dqn_isize Dqn_String8_FmtSize(char const *fmt, ...) -{ - va_list args; - va_start(args, fmt); - Dqn_isize result = STB_SPRINTF_DECORATE(vsnprintf)(nullptr, 0, fmt, args); - va_end(args); - return result; -} - -DQN_API Dqn_isize Dqn_String8_FmtSizeV(char const *fmt, va_list args) -{ - va_list args_copy; - va_copy(args_copy, args); - Dqn_isize result = STB_SPRINTF_DECORATE(vsnprintf)(nullptr, 0, fmt, args_copy); - va_end(args_copy); - return result; -} - DQN_API Dqn_String8 Dqn_String8_Allocate_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, Dqn_isize size, Dqn_ZeroMem zero_mem) { Dqn_String8 result = {}; @@ -3932,57 +4617,111 @@ DQN_API Dqn_String8 Dqn_String8_Copy_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator return result; } -DQN_API bool Dqn_String8_Eq(Dqn_String8 lhs, Dqn_String8 rhs, Dqn_String8_EqCase eq_case) +DQN_API Dqn_String8 Dqn_String8_BinarySplit(Dqn_String8 string, char delimiter, Dqn_String8 *rhs) { - if (!Dqn_String8_IsValid(lhs) || !Dqn_String8_IsValid(rhs)) - return false; + char **rhs_string = rhs ? &rhs->data : nullptr; + Dqn_isize *rhs_size = rhs ? &rhs->size : nullptr; + Dqn_String8 result = {}; + result.data = DQN_CAST(char *)Dqn_CString8_BinarySplit(string.data, string.size, delimiter, &result.size, rhs_string, rhs_size); + return result; +} - bool result = lhs.size == rhs.size; - if (result) { - if (eq_case == Dqn_String8_EqCase::Sensitive) { - result = (DQN_MEMCMP(lhs.data, rhs.data, DQN_CAST(size_t)lhs.size) == 0); - } else { - for (Dqn_isize index = 0; index < lhs.size && result; index++) - result = (Dqn_Char_ToLower(lhs.data[index]) == Dqn_Char_ToLower(rhs.data[index])); - } - } +DQN_API bool Dqn_String8_Eq(Dqn_String8 lhs, Dqn_String8 rhs, Dqn_CString8EqCase eq_case) +{ + bool result = Dqn_CString8_Eq(lhs.data, rhs.data, lhs.size, rhs.size, eq_case); return result; } DQN_API bool Dqn_String8_EqInsensitive(Dqn_String8 lhs, Dqn_String8 rhs) { - bool result = Dqn_String8_Eq(lhs, rhs, Dqn_String8_EqCase::Insensitive); + bool result = Dqn_String8_Eq(lhs, rhs, Dqn_CString8EqCase::Insensitive); return result; } -DQN_API bool Dqn_String8_StartsWith(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8_EqCase eq_case) +DQN_API bool Dqn_String8_StartsWith(Dqn_String8 string, Dqn_String8 prefix, Dqn_CString8EqCase eq_case) { - Dqn_String8 substring = Dqn_String8_Slice(string, 0, prefix.size); - bool result = Dqn_String8_Eq(substring, prefix, eq_case); + bool result = Dqn_CString8_StartsWith(string.data, prefix.data, string.size, prefix.size, eq_case); return result; } DQN_API bool Dqn_String8_StartsWithInsensitive(Dqn_String8 string, Dqn_String8 prefix) { - bool result = Dqn_String8_StartsWith(string, prefix, Dqn_String8_EqCase::Insensitive); + bool result = Dqn_String8_StartsWith(string, prefix, Dqn_CString8EqCase::Insensitive); return result; } -DQN_API bool Dqn_String8_EndsWith(Dqn_String8 string, - Dqn_String8 suffix, - Dqn_String8_EqCase eq_case) +DQN_API bool Dqn_String8_EndsWith(Dqn_String8 string, Dqn_String8 suffix, Dqn_CString8EqCase eq_case) { - Dqn_String8 substring = Dqn_String8_Slice(string, string.size - suffix.size, suffix.size); - bool result = Dqn_String8_Eq(substring, suffix, eq_case); + bool result = Dqn_CString8_EndsWith(string.data, suffix.data, string.size, suffix.size, eq_case); return result; } DQN_API bool Dqn_String8_EndsWithInsensitive(Dqn_String8 string, Dqn_String8 suffix) { - bool result = Dqn_String8_EndsWith(string, suffix, Dqn_String8_EqCase::Insensitive); + bool result = Dqn_String8_EndsWith(string, suffix, Dqn_CString8EqCase::Insensitive); return result; } +DQN_API Dqn_String8 Dqn_String8_TrimPrefix(Dqn_String8 string, Dqn_String8 prefix, Dqn_CString8EqCase eq_case) +{ + Dqn_String8 result = {}; + result.data = DQN_CAST(char *)Dqn_CString8_TrimPrefix(string.data, prefix.data, string.size, prefix.size, eq_case, &result.size); + return result; +} + +DQN_API Dqn_String8 Dqn_String8_TrimSuffix(Dqn_String8 string, Dqn_String8 suffix, Dqn_CString8EqCase eq_case) +{ + Dqn_String8 result = {}; + result.data = DQN_CAST(char *)Dqn_CString8_TrimSuffix(string.data, suffix.data, string.size, suffix.size, eq_case, &result.size); + return result; +} + +DQN_API Dqn_String8 Dqn_String8_TrimWhitespaceAround(Dqn_String8 string) +{ + Dqn_String8 result = {}; + result.data = DQN_CAST(char *)Dqn_CString8_TrimWhitespaceAround(string.data, string.size, &result.size); + return result; +} + +DQN_API Dqn_String8 Dqn_String8_TrimByteOrderMark(Dqn_String8 string) +{ + Dqn_String8 result = {}; + result.data = DQN_CAST(char *)Dqn_CString8_TrimByteOrderMark(string.data, string.size, &result.size); + return result; +} + +DQN_API Dqn_String8 Dqn_String8_FileNameFromPath(Dqn_String8 path) +{ + Dqn_String8 result = {}; + result.data = DQN_CAST(char *)Dqn_CString8_FileNameFromPath(path.data, path.size, &result.size); + return result; +} + +DQN_API bool Dqn_String8_ToU64Checked(Dqn_String8 string, char separator, uint64_t *output) +{ + bool result = Dqn_CString8_ToU64Checked(string.data, string.size, separator, output); + return result; +} + +DQN_API uint64_t Dqn_String8_ToU64(Dqn_String8 string, char separator) +{ + uint64_t result = Dqn_CString8_ToU64(string.data, string.size, separator); + return result; +} + +DQN_API bool Dqn_String8_ToI64Checked(Dqn_String8 string, char separator, int64_t *output) +{ + bool result = Dqn_CString8_ToI64Checked(string.data, string.size, separator, output); + return result; +} + +DQN_API int64_t Dqn_String8_ToI64(Dqn_String8 string, char separator) +{ + int64_t result = Dqn_CString8_ToI64(string.data, string.size, separator); + return result; +} + + DQN_API Dqn_isize Dqn_String8_Split(Dqn_String8 string, char delimiter, Dqn_String8 *splits, Dqn_isize splits_count) { Dqn_isize result = 0; // The number of splits in the actual string. @@ -4009,50 +4748,6 @@ DQN_API Dqn_isize Dqn_String8_Split(Dqn_String8 string, char delimiter, Dqn_Stri return result; } -DQN_API Dqn_String8 Dqn_String8_TrimPrefix(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8_EqCase eq_case) -{ - Dqn_String8 result = string; - if (Dqn_String8_StartsWith(result, prefix, eq_case)) { - result = Dqn_String8_Slice(result, prefix.size, result.size - prefix.size); - } - return result; -} - -DQN_API Dqn_String8 Dqn_String8_TrimSuffix(Dqn_String8 string, Dqn_String8 suffix, Dqn_String8_EqCase eq_case) -{ - Dqn_String8 result = string; - if (Dqn_String8_EndsWith(string, suffix, eq_case)) { - result = Dqn_String8_Slice(result, 0, result.size - suffix.size); - } - return result; -} - -DQN_API Dqn_String8 Dqn_String8_TrimWhitespaceAround(Dqn_String8 string) -{ - Dqn_String8 result = {}; - if (Dqn_String8_IsValid(string)) { - result.data = DQN_CAST(char *)Dqn_CString8_TrimWhitespaceAround(string.data, string.size, &result.size); - } - return result; -} - -DQN_API Dqn_String8 Dqn_String8_TrimByteOrderMark(Dqn_String8 string) -{ - // TODO(dqn): This is little endian - auto const UTF8_BOM = DQN_STRING8("\xEF\xBB\xBF"); - auto const UTF16_BOM_BE = DQN_STRING8("\xEF\xFF"); - auto const UTF16_BOM_LE = DQN_STRING8("\xFF\xEF"); - auto const UTF32_BOM_BE = DQN_STRING8("\x00\x00\xFE\xFF"); - auto const UTF32_BOM_LE = DQN_STRING8("\xFF\xFE\x00\x00"); - Dqn_String8 result = string; - result = Dqn_String8_TrimPrefix(result, UTF8_BOM); - result = Dqn_String8_TrimPrefix(result, UTF16_BOM_BE); - result = Dqn_String8_TrimPrefix(result, UTF16_BOM_LE); - result = Dqn_String8_TrimPrefix(result, UTF32_BOM_BE); - result = Dqn_String8_TrimPrefix(result, UTF32_BOM_LE); - return result; -} - DQN_API bool Dqn_String8_IsAllDigits(Dqn_String8 string) { bool result = Dqn_String8_IsValid(string) && string.size > 0; @@ -4063,7 +4758,7 @@ DQN_API bool Dqn_String8_IsAllDigits(Dqn_String8 string) DQN_API bool Dqn_String8_IsAllHex(Dqn_String8 string) { - Dqn_String8 trimmed = Dqn_String8_TrimPrefix(string, DQN_STRING8("0x"), Dqn_String8_EqCase::Insensitive); + Dqn_String8 trimmed = Dqn_String8_TrimPrefix(string, DQN_STRING8("0x"), Dqn_CString8EqCase::Insensitive); bool result = Dqn_String8_IsValid(trimmed) && trimmed.size > 0; for (Dqn_isize index = 0; result && index < trimmed.size; index++) { char ch = trimmed.data[index]; @@ -4098,7 +4793,7 @@ DQN_API void Dqn_String8_Remove(Dqn_String8 *string, Dqn_isize begin, Dqn_isize string->size -= size; } -DQN_API Dqn_isize Dqn_String8_FindOffset(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_String8_EqCase eq_case) +DQN_API Dqn_isize Dqn_String8_FindOffset(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_CString8EqCase eq_case) { Dqn_isize result = -1; if (!Dqn_String8_IsValid(string) || !Dqn_String8_IsValid(find) || start_index < 0) @@ -4114,7 +4809,7 @@ DQN_API Dqn_isize Dqn_String8_FindOffset(Dqn_String8 string, Dqn_String8 find, D return result; } -DQN_API Dqn_String8 Dqn_String8_Find(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_String8_EqCase eq_case) +DQN_API Dqn_String8 Dqn_String8_Find(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_CString8EqCase eq_case) { Dqn_isize offset = Dqn_String8_FindOffset(string, find, start_index, eq_case); Dqn_String8 result = Dqn_String8_Slice(string, offset == -1 ? 0 : offset, offset == -1 ? 0 : find.size); @@ -4127,7 +4822,7 @@ DQN_API Dqn_String8 Dqn_String8_Replace(Dqn_String8 string, Dqn_isize start_index, Dqn_Arena *arena, Dqn_Arena *temp_arena, - Dqn_String8_EqCase eq_case) + Dqn_CString8EqCase eq_case) { auto temp_arena_scope = Dqn_ArenaTempMemoryScope(temp_arena); Dqn_String8Builder string_builder = {}; @@ -4171,36 +4866,7 @@ DQN_API Dqn_String8 Dqn_String8_Replace(Dqn_String8 string, DQN_API Dqn_String8 Dqn_String8_ReplaceInsensitive(Dqn_String8 string, Dqn_String8 find, Dqn_String8 replace, Dqn_isize start_index, Dqn_Arena *arena, Dqn_Arena *temp_arena) { - Dqn_String8 result = Dqn_String8_Replace(string, find, replace, start_index, arena, temp_arena, Dqn_String8_EqCase::Insensitive); - return result; -} - -DQN_API Dqn_String8 Dqn_String8_FileNameFromPath(Dqn_String8 path) -{ - Dqn_String8 result = path; - if (!Dqn_String8_IsValid(path)) { - return result; - } - - for (Dqn_isize index = (result.size - 1); index >= 0; --index) { - if (result.data[index] == '\\' || result.data[index] == '/') { - char const *end = result.data + result.size; - result = Dqn_String8_Slice(path, index + 1, end - result.data); - break; - } - } - return result; -} - -DQN_API uint64_t Dqn_String8_ToU64(Dqn_String8 string) -{ - uint64_t result = Dqn_CString8_ToU64(string.data, DQN_CAST(int)string.size); - return result; -} - -DQN_API uint64_t Dqn_String8_ToI64(Dqn_String8 string) -{ - uint64_t result = Dqn_CString8_ToI64(string.data, DQN_CAST(int)string.size); + Dqn_String8 result = Dqn_String8_Replace(string, find, replace, start_index, arena, temp_arena, Dqn_CString8EqCase::Insensitive); return result; } @@ -4211,7 +4877,7 @@ bool Dqn_String8Builder_AppendString8Ref(Dqn_String8Builder *builder, Dqn_String if (!builder || !string.data || string.size <= 0) return false; - Dqn_String8_Link *link = Dqn_Allocator_New(builder->allocator, Dqn_String8_Link, Dqn_ZeroMem_No); + Dqn_String8Link *link = Dqn_Allocator_New(builder->allocator, Dqn_String8Link, Dqn_ZeroMem_No); if (!link) return false; link->string = string; @@ -4285,7 +4951,7 @@ Dqn_String8 Dqn_String8Builder_Build(Dqn_String8Builder const *builder, Dqn_Allo if (!result.data) return result; - for (Dqn_String8_Link *link = builder->head; link; link = link->next) { + for (Dqn_String8Link *link = builder->head; link; link = link->next) { DQN_MEMCOPY(result.data + result.size, link->string.data, link->string.size); result.size += link->string.size; } @@ -5171,7 +5837,7 @@ DQN_API uint8_t Dqn_Safe_TruncateU64ToU8(uint64_t val) return result; } -DQN_API uint64_t Dqn_Safe_TruncateU64ToI64(uint64_t val) +DQN_API int64_t Dqn_Safe_TruncateU64ToI64(uint64_t val) { DQN_ASSERT_MSG(val <= INT64_MAX, "%I64u <= %I64d", val, INT64_MAX); auto result = (val <= INT64_MAX) ? DQN_CAST(uint64_t)val : INT64_MAX; @@ -5356,11 +6022,12 @@ DQN_API char const *Dqn_Hex_CStringTrimSpaceAnd0xPrefix(char const *hex, Dqn_isi { Dqn_isize trimmed_size = 0; char const *trimmed_hex = Dqn_CString8_TrimWhitespaceAround(hex, size, &trimmed_size); - char const *result = Dqn_CString8_TrimPrefix(trimmed_hex, - trimmed_size, - "0x", - 2 /*prefix_size*/, - &trimmed_size); + char const *result = Dqn_CString8_TrimPrefix(trimmed_hex, /*string*/ + "0x", /*prefix*/ + trimmed_size, /*string_size*/ + 2 /*prefix_size*/, + Dqn_CString8EqCase::Insensitive, + &trimmed_size); if (real_size) *real_size = trimmed_size; return result; } @@ -5519,321 +6186,6 @@ DQN_API Dqn_Array Dqn_Hex_StringToU8Array(Dqn_String8 const hex, Dqn_Ar #endif // DQN_WITH_HEX -// NOTE: Dqn_Str -// ------------------------------------------------------------------------------------------------- -DQN_API bool Dqn_CString8_Equals(char const *a, char const *b, Dqn_isize a_size, Dqn_isize b_size) -{ - if (a_size == -1) a_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(a); - if (b_size == -1) b_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(b); - if (a_size != b_size) return false; - return (DQN_MEMCMP(a, b, DQN_CAST(size_t)a_size) == 0); -} - -DQN_API char const *Dqn_CString8_FindMulti(char const *buf, char const *find_list[], Dqn_isize const *find_string_sizes, Dqn_isize find_size, Dqn_isize *match_index, Dqn_isize buf_size) -{ - char const *result = nullptr; - if (find_size == 0) return result; - if (buf_size < 0) buf_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(buf); - - char const *buf_end = buf + buf_size; - for (; buf != buf_end; ++buf) { - Dqn_isize remaining = static_cast(buf_end - buf); - for (Dqn_isize find_index = 0; find_index < find_size; find_index++) { - char const *find = find_list[find_index]; - Dqn_isize find_str_size = find_string_sizes[find_index]; - if (remaining < find_str_size) continue; - - if (strncmp(buf, find, DQN_CAST(size_t)find_str_size) == 0) { - result = buf; - *match_index = find_index; - return result; - } - } - - } - return result; -} - -DQN_API char const *Dqn_CString8_Find(char const *buf, char const *find, Dqn_isize buf_size, Dqn_isize find_size, bool case_insensitive) -{ - if (find_size == 0) return nullptr; - if (buf_size < 0) buf_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(buf); - if (find_size < 0) find_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(find); - - char const *buf_end = buf + buf_size; - char const *result = nullptr; - for (; buf != buf_end; ++buf) - { - Dqn_isize remaining = static_cast(buf_end - buf); - if (remaining < find_size) break; - - bool matched = true; - for (Dqn_isize index = 0; index < find_size; index++) - { - char lhs = buf[index]; - char rhs = find[index]; - - if (case_insensitive) - { - lhs = Dqn_Char_ToLower(lhs); - rhs = Dqn_Char_ToLower(rhs); - } - - if (lhs != rhs) - { - matched = false; - break; - } - } - - if (matched) - { - result = buf; - break; - } - } - return result; -} - -DQN_API char const *Dqn_CString8_FileNameFromPath(char const *path, Dqn_isize size, Dqn_isize *file_name_size) -{ - char const *result = path; - Dqn_isize result_size = size <= -1 ? Dqn_CString8_Size(path) : size; - for (Dqn_isize i = (result_size - 1); i >= 0; --i) - { - if (result[i] == '\\' || result[i] == '/') - { - char const *file_end = result + result_size; - result = result + (i + 1); - result_size = DQN_CAST(Dqn_isize)(file_end - result); - break; - } - } - - if (file_name_size) *file_name_size = result_size; - return result; -} - -DQN_API Dqn_isize Dqn_CString8_Size(char const *src) -{ - Dqn_isize result = 0; - while (src && src[0] != 0) - { - src++; - result++; - } - - return result; -} - -DQN_API bool Dqn_CString8_Match(char const *src, char const *find, int find_size) -{ - if (find_size == -1) find_size = Dqn_Safe_TruncateUSizeToInt(Dqn_CString8_Size(find)); - bool result = (DQN_MEMCMP(src, find, DQN_CAST(size_t)find_size) == 0); - return result; -} - -DQN_API char const *Dqn_CString8_SkipToChar(char const *src, char ch) -{ - char const *result = src; - while (result && result[0] && result[0] != ch) ++result; - return result; -} - -DQN_API char const *Dqn_CString8_SkipToNextAlphaNum(char const *src) -{ - char const *result = src; - while (result && result[0] && !Dqn_Char_IsAlphaNum(result[0])) ++result; - return result; -} - -DQN_API char const *Dqn_CString8_SkipToNextDigit(char const *src) -{ - char const *result = src; - while (result && result[0] && !Dqn_Char_IsDigit(result[0])) ++result; - return result; -} - -DQN_API char const *Dqn_CString8_SkipToNextChar(char const *src) -{ - char const *result = src; - while (result && result[0] && !Dqn_Char_IsAlpha(result[0])) ++result; - return result; -} - -DQN_API char const *Dqn_CString8_SkipToNextWord(char const *src) -{ - char const *result = src; - while (result && result[0] && !Dqn_Char_IsWhitespace(result[0])) ++result; - while (result && result[0] && Dqn_Char_IsWhitespace(result[0])) ++result; - return result; -} - -DQN_API char const *Dqn_CString8_SkipToNextWhitespace(char const *src) -{ - char const *result = src; - while (result && result[0] && !Dqn_Char_IsWhitespace(result[0])) ++result; - return result; -} - -DQN_API char const *Dqn_CString8_SkipWhitespace(char const *src) -{ - char const *result = src; - while (result && result[0] && Dqn_Char_IsWhitespace(result[0])) ++result; - return result; -} - -DQN_API char const *Dqn_CString8_SkipToCharInPlace(char const **src, char ch) -{ - *src = Dqn_CString8_SkipToChar(*src, ch); - return *src; -} - -DQN_API char const *Dqn_CString8_SkipToNextAlphaNumInPlace(char const **src) -{ - *src = Dqn_CString8_SkipToNextAlphaNum(*src); - return *src; -} - -DQN_API char const *Dqn_CString8_SkipToNextCharInPlace(char const **src) -{ - *src = Dqn_CString8_SkipToNextChar(*src); - return *src; -} - -DQN_API char const *Dqn_CString8_SkipToNextWhitespaceInPlace(char const **src) -{ - *src = Dqn_CString8_SkipToNextWhitespace(*src); - return *src; -} - -DQN_API char const *Dqn_CString8_SkipToNextWordInPlace(char const **src) -{ - *src = Dqn_CString8_SkipToNextWord(*src); - return *src; -} - -DQN_API char const *Dqn_CString8_SkipWhitespaceInPlace(char const **src) -{ - *src = Dqn_CString8_SkipWhitespace(*src); - return *src; -} - -DQN_API char const *Dqn_CString8_TrimWhitespaceAround(char const *src, Dqn_isize size, Dqn_isize *new_size) -{ - char const *result = src; - if (new_size) *new_size = 0; - if (size <= 0) return result; - - char const *start = result; - char const *end = start + (size - 1); - while (start <= end && Dqn_Char_IsWhitespace(start[0])) start++; - while (end > start && Dqn_Char_IsWhitespace(end[0])) end--; - - result = start; - if (new_size) *new_size = ((end - start) + 1); - return result; -} - -DQN_API char const *Dqn_CString8_TrimPrefix(char const *src, Dqn_isize size, char const *prefix, Dqn_isize prefix_size, Dqn_isize *trimmed_size) -{ - if (size <= -1) size = Dqn_CString8_Size(src); - if (prefix_size <= -1) prefix_size = Dqn_CString8_Size(prefix); - char const *result = src; - if (prefix_size > size) - return result; - - if (DQN_MEMCMP(src, prefix, prefix_size) == 0) { - result += prefix_size; - if (trimmed_size) *trimmed_size = size - prefix_size; - } - - return result; -} - -DQN_API bool Dqn_CString8_IsAllDigits(char const *src, Dqn_isize size) -{ - if (!src) return false; - if (size <= -1) size = Dqn_CString8_Size(src); - for (Dqn_isize ch_index = 0; ch_index < size; ch_index++) { - if (!(src[ch_index] >= '0' && src[ch_index] <= '9')) - return false; - } - bool result = src && size > 0; - return result; -} - -DQN_API uint64_t Dqn_CString8_ToU64(char const *buf, Dqn_isize size, char separator) -{ - uint64_t result = 0; - if (!buf) - return result; - - if (size <= -1) - size = Dqn_CString8_Size(buf); - - for (Dqn_isize index = 0; index < size; ++index) - { - char ch = buf[index]; - if (index && ch == separator) - continue; - - if (ch < '0' || ch > '9') - break; - - result = Dqn_Safe_MulU64(result, 10); - int digit = ch - '0'; - result = Dqn_Safe_AddU64(result, digit); - } - - return result; -} - -DQN_API uint64_t Dqn_CString8_ToI64(char const *buf, Dqn_isize size, char separator) -{ - uint64_t result = 0; - if (!buf) - return result; - - if (size <= -1) - size = Dqn_CString8_Size(buf); - - char const *buf_ptr = buf; - bool negative = (buf[0] == '-'); - if (negative) { - ++buf_ptr; - --size; - } - - for (int buf_index = 0; buf_index < size; ++buf_index) { - char ch = buf_ptr[buf_index]; - if (buf_index && ch == separator) - continue; - - if (ch < '0' || ch > '9') - break; - - result = Dqn_Safe_MulU64(result, 10); - uint64_t val = ch - '0'; - result = Dqn_Safe_AddI64(result, val); - } - - if (negative) - result *= -1; - return result; -} - -DQN_API Dqn_isize Dqn_CString16_Size(wchar_t const *src) -{ - Dqn_isize result = 0; - while (src && src[0] != 0) { - src++; - result++; - } - - return result; -} - // NOTE: Dqn_Fs_ // ------------------------------------------------------------------------------------------------- DQN_API char *Dqn_Fs_ReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS char const *file_path, Dqn_isize file_path_size, Dqn_isize *file_size, Dqn_Arena *arena) diff --git a/dqn_tester.h b/dqn_tester.h index ef3940d..9d79f27 100644 --- a/dqn_tester.h +++ b/dqn_tester.h @@ -146,9 +146,9 @@ typedef struct Dqn_Tester { Dqn_TesterState state; } Dqn_Tester; -void Dqn_TesterBeginV(Dqn_Tester *test, char const *fmt, va_list args); -void Dqn_TesterBegin(Dqn_Tester *test, char const *fmt, ...); -void Dqn_TesterEnd(Dqn_Tester *test); +void Dqn_Tester_BeginV(Dqn_Tester *test, char const *fmt, va_list args); +void Dqn_Tester_Begin(Dqn_Tester *test, char const *fmt, ...); +void Dqn_Tester_End(Dqn_Tester *test); #if defined(__cplusplus) struct Dqn_TesterBeginScopedTest { @@ -162,11 +162,11 @@ struct Dqn_TesterBeginScopedTest { // NOTE: Implementation // ----------------------------------------------------------------------------- #if defined(DQN_TESTER_IMPLEMENTATION) -void Dqn_TesterBeginV(Dqn_Tester *test, char const *fmt, va_list args) +void Dqn_Tester_BeginV(Dqn_Tester *test, char const *fmt, va_list args) { assert(test->state == Dqn_TesterState_Nil && "Nesting a unit test within another unit test is not allowed, ensure" - "the first test has finished by calling Dqn_TesterEnd"); + "the first test has finished by calling Dqn_Tester_End"); test->num_tests_in_group++; test->state = Dqn_TesterState_TestBegun; @@ -186,17 +186,17 @@ void Dqn_TesterBeginV(Dqn_Tester *test, char const *fmt, va_list args) putc(DQN_TESTER_RESULT_PAD_CHAR, stdout); } -void Dqn_TesterBegin(Dqn_Tester *test, char const *fmt, ...) +void Dqn_Tester_Begin(Dqn_Tester *test, char const *fmt, ...) { va_list args; va_start(args, fmt); - Dqn_TesterBeginV(test, fmt, args); + Dqn_Tester_BeginV(test, fmt, args); va_end(args); } -void Dqn_TesterEnd(Dqn_Tester *test) +void Dqn_Tester_End(Dqn_Tester *test) { - assert(test->state != Dqn_TesterState_Nil && "Test was marked as ended but a test was never commenced using Dqn_TesterBegin"); + assert(test->state != Dqn_TesterState_Nil && "Test was marked as ended but a test was never commenced using Dqn_Tester_Begin"); if (test->log_count != 0) { // NOTE: We try and print the result on the same line as the test name, // but if there were logs printed throughout the test then we must print @@ -227,12 +227,12 @@ Dqn_TesterBeginScopedTest::Dqn_TesterBeginScopedTest(Dqn_Tester *test, char cons { va_list args; va_start(args, fmt); - Dqn_TesterBeginV(test, fmt, args); + Dqn_Tester_BeginV(test, fmt, args); va_end(args); } Dqn_TesterBeginScopedTest::~Dqn_TesterBeginScopedTest() { - Dqn_TesterEnd(test); + Dqn_Tester_End(test); } #endif // __cplusplus #endif // DQN_TESTER_IMPLEMENTATION diff --git a/dqn_tests.cpp b/dqn_unit_tests.cpp similarity index 83% rename from dqn_tests.cpp rename to dqn_unit_tests.cpp index 72cdb29..0259ea4 100644 --- a/dqn_tests.cpp +++ b/dqn_unit_tests.cpp @@ -35,7 +35,7 @@ Dqn_Tester Dqn_Test_Array() // NOTE: Dqn_Array_InitWithMemory { { - Dqn_TesterBegin(&test, "Fixed Memory: Test add single item and can't allocate more"); + Dqn_Tester_Begin(&test, "Fixed Memory: Test add single item and can't allocate more"); int memory[4] = {}; Dqn_Array array = Dqn_Array_InitWithMemory(memory, Dqn_CArray_Count(memory), 0 /*size*/); Dqn_Array_Add(&array, 1); @@ -52,11 +52,11 @@ Dqn_Tester Dqn_Test_Array() DQN_TESTER_ASSERTF(&test, added_item == nullptr, "Failed to add item to array"); DQN_TESTER_ASSERTF(&test, array.size == 4, "array.size: %zu", array.size); DQN_TESTER_ASSERTF(&test, array.max == 4, "array.max: %zu", array.max); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Fixed Memory: Test add array of items"); + Dqn_Tester_Begin(&test, "Fixed Memory: Test add array of items"); int memory[4] = {}; int DATA[] = {1, 2, 3}; Dqn_Array array = Dqn_Array_InitWithMemory(memory, Dqn_CArray_Count(memory), 0 /*size*/); @@ -66,11 +66,11 @@ Dqn_Tester Dqn_Test_Array() DQN_TESTER_ASSERTF(&test, array.data[2] == 3, "array.data %d", array.data[2]); DQN_TESTER_ASSERTF(&test, array.size == 3, "array.size: %zu", array.size); DQN_TESTER_ASSERTF(&test, array.max == 4, "array.max: %zu", array.max); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Fixed Memory: Test clear and clear with memory zeroed"); + Dqn_Tester_Begin(&test, "Fixed Memory: Test clear and clear with memory zeroed"); int memory[4] = {}; int DATA[] = {1, 2, 3}; Dqn_Array array = Dqn_Array_InitWithMemory(memory, Dqn_CArray_Count(memory), 0 /*size*/); @@ -82,11 +82,11 @@ Dqn_Tester Dqn_Test_Array() Dqn_Array_Clear(&array, Dqn_ZeroMem_Yes); DQN_TESTER_ASSERTF(&test, array.data[0] == 0, "array.data %d. Clear but zero memory old values should not remain", array.data[0]); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Fixed Memory: Test erase stable and erase unstable"); + Dqn_Tester_Begin(&test, "Fixed Memory: Test erase stable and erase unstable"); int memory[4] = {}; int DATA[] = {1, 2, 3, 4}; Dqn_Array array = Dqn_Array_InitWithMemory(memory, Dqn_CArray_Count(memory), 0 /*size*/); @@ -101,11 +101,11 @@ Dqn_Tester Dqn_Test_Array() DQN_TESTER_ASSERTF(&test, array.data[0] == 4, "array.data: %d", array.data[0]); DQN_TESTER_ASSERTF(&test, array.data[1] == 3, "array.data: %d", array.data[1]); DQN_TESTER_ASSERTF(&test, array.size == 2, "array.size: %zu", array.size); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Fixed Memory: Test array pop and peek"); + Dqn_Tester_Begin(&test, "Fixed Memory: Test array pop and peek"); int memory[4] = {}; int DATA[] = {1, 2, 3}; Dqn_Array array = Dqn_Array_InitWithMemory(memory, Dqn_CArray_Count(memory), 0 /*size*/); @@ -119,13 +119,13 @@ Dqn_Tester Dqn_Test_Array() DQN_TESTER_ASSERTF(&test, *peek_item == 1, "peek: %d", *peek_item); DQN_TESTER_ASSERTF(&test, array.size == 1, "array.size: %zu", array.size); DQN_TESTER_ASSERTF(&test, array.max == 4, "array.max: %zu", array.max); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } } // NOTE: Dynamic Memory: Dqn_Array { - Dqn_TesterBegin(&test, "Dynamic Memory: Reserve and check over commit reallocates"); + Dqn_Tester_Begin(&test, "Dynamic Memory: Reserve and check over commit reallocates"); Dqn_Arena arena = {}; Dqn_Array array = {}; array.arena = &arena; @@ -149,7 +149,7 @@ Dqn_Tester Dqn_Test_Array() DQN_TESTER_ASSERTF(&test, array.max >= 5, "array.max: %zu", array.max); Dqn_Arena_Free(&arena, false /*clear_mem*/); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); @@ -163,7 +163,7 @@ Dqn_Tester Dqn_Test_File() { Dqn_Arena arena = {}; Dqn_Allocator allocator = Dqn_Arena_Allocator(&arena); - Dqn_TesterBegin(&test, "Make directory recursive \"abcd/efgh\""); + Dqn_Tester_Begin(&test, "Make directory recursive \"abcd/efgh\""); DQN_TESTER_ASSERTF(&test, Dqn_Fs_MakeDir(DQN_STRING8("abcd/efgh")), "Failed to make directory"); DQN_TESTER_ASSERTF(&test, Dqn_Fs_DirExists(DQN_STRING8("abcd")), "Directory was not made"); DQN_TESTER_ASSERTF(&test, Dqn_Fs_DirExists(DQN_STRING8("abcd/efgh")), "Subdirectory was not made"); @@ -172,13 +172,13 @@ Dqn_Tester Dqn_Test_File() DQN_TESTER_ASSERTF(&test, Dqn_Fs_Delete(DQN_STRING8("abcd/efgh")), "Failed to delete directory"); DQN_TESTER_ASSERTF(&test, Dqn_Fs_Delete(DQN_STRING8("abcd")), "Failed to cleanup directory"); Dqn_Arena_Free(&arena, false /*clear_mem*/); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { // NOTE: Write step Dqn_String8 const SRC_FILE = DQN_STRING8("dqn_test_file"); - Dqn_TesterBegin(&test, "Write file, read it, copy it, move it and delete it"); + Dqn_Tester_Begin(&test, "Write file, read it, copy it, move it and delete it"); Dqn_b32 write_result = Dqn_Fs_WriteCString8ToFileCString8(SRC_FILE.data, SRC_FILE.size, "test", 4); DQN_TESTER_ASSERT(&test, write_result); DQN_TESTER_ASSERT(&test, Dqn_Fs_Exists(SRC_FILE)); @@ -216,7 +216,7 @@ Dqn_Tester Dqn_Test_File() DQN_TESTER_ASSERT(&test, delete_non_existent_src_file == false); Dqn_Arena_Free(&arena, false /*clear_mem*/); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); return test; @@ -229,42 +229,42 @@ Dqn_Tester Dqn_Test_FixedArray() DQN_TESTER_BEGIN_GROUP("Dqn_FixedArray"); // NOTE: Dqn_FixedArray_Init { - Dqn_TesterBegin(&test, "Initialise from raw array"); + Dqn_Tester_Begin(&test, "Initialise from raw array"); int raw_array[] = {1, 2}; auto array = Dqn_FixedArray_Init(raw_array, (int)Dqn_CArray_Count(raw_array)); DQN_TESTER_ASSERT(&test, array.size == 2); DQN_TESTER_ASSERT(&test, array[0] == 1); DQN_TESTER_ASSERT(&test, array[1] == 2); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } // NOTE: Dqn_FixedArray_EraseStable { - Dqn_TesterBegin(&test, "Erase stable 1 element from array"); + Dqn_Tester_Begin(&test, "Erase stable 1 element from array"); int raw_array[] = {1, 2, 3}; auto array = Dqn_FixedArray_Init(raw_array, (int)Dqn_CArray_Count(raw_array)); Dqn_FixedArray_EraseStable(&array, 1); DQN_TESTER_ASSERT(&test, array.size == 2); DQN_TESTER_ASSERT(&test, array[0] == 1); DQN_TESTER_ASSERT(&test, array[1] == 3); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } // NOTE: Dqn_FixedArray_EraseUnstable { - Dqn_TesterBegin(&test, "Erase unstable 1 element from array"); + Dqn_Tester_Begin(&test, "Erase unstable 1 element from array"); int raw_array[] = {1, 2, 3}; auto array = Dqn_FixedArray_Init(raw_array, (int)Dqn_CArray_Count(raw_array)); Dqn_FixedArray_EraseUnstable(&array, 0); DQN_TESTER_ASSERT(&test, array.size == 2); DQN_TESTER_ASSERT(&test, array[0] == 3); DQN_TESTER_ASSERT(&test, array[1] == 2); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } // NOTE: Dqn_FixedArray_Add { - Dqn_TesterBegin(&test, "Add 1 element to array"); + Dqn_Tester_Begin(&test, "Add 1 element to array"); int const ITEM = 2; int raw_array[] = {1}; auto array = Dqn_FixedArray_Init(raw_array, (int)Dqn_CArray_Count(raw_array)); @@ -272,17 +272,17 @@ Dqn_Tester Dqn_Test_FixedArray() DQN_TESTER_ASSERT(&test, array.size == 2); DQN_TESTER_ASSERT(&test, array[0] == 1); DQN_TESTER_ASSERT(&test, array[1] == ITEM); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } // NOTE: Dqn_FixedArray_Clear { - Dqn_TesterBegin(&test, "Clear array"); + Dqn_Tester_Begin(&test, "Clear array"); int raw_array[] = {1}; auto array = Dqn_FixedArray_Init(raw_array, (int)Dqn_CArray_Count(raw_array)); Dqn_FixedArray_Clear(&array); DQN_TESTER_ASSERT(&test, array.size == 0); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); #endif // DQN_WITH_FIXED_ARRAY @@ -297,18 +297,18 @@ Dqn_Tester Dqn_Test_FixedString() // NOTE: Dqn_FixedString_Append { - Dqn_TesterBegin(&test, "Append too much fails"); + Dqn_Tester_Begin(&test, "Append too much fails"); Dqn_FixedString<4> str = {}; DQN_TESTER_ASSERTF(&test, Dqn_FixedString_Append(&str, "abcd") == false, "We need space for the null-terminator"); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } // NOTE: Dqn_FixedString_AppendFmt { - Dqn_TesterBegin(&test, "Append format string too much fails"); + Dqn_Tester_Begin(&test, "Append format string too much fails"); Dqn_FixedString<4> str = {}; DQN_TESTER_ASSERTF(&test, Dqn_FixedString_AppendFmt(&str, "abcd") == false, "We need space for the null-terminator"); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); #endif // DQN_WITH_FIXED_STRING @@ -321,80 +321,80 @@ Dqn_Tester Dqn_Test_Hex() #if defined(DQN_WITH_HEX) DQN_TESTER_BEGIN_GROUP("Dqn_Hex"); { - Dqn_TesterBegin(&test, "Convert 0x123"); + Dqn_Tester_Begin(&test, "Convert 0x123"); uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("0x123")); DQN_TESTER_ASSERTF(&test, result == 0x123, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Convert 0xFFFF"); + Dqn_Tester_Begin(&test, "Convert 0xFFFF"); uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("0xFFFF")); DQN_TESTER_ASSERTF(&test, result == 0xFFFF, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Convert FFFF"); + Dqn_Tester_Begin(&test, "Convert FFFF"); uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("FFFF")); DQN_TESTER_ASSERTF(&test, result == 0xFFFF, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Convert abCD"); + Dqn_Tester_Begin(&test, "Convert abCD"); uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("abCD")); DQN_TESTER_ASSERTF(&test, result == 0xabCD, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Convert 0xabCD"); + Dqn_Tester_Begin(&test, "Convert 0xabCD"); uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("0xabCD")); DQN_TESTER_ASSERTF(&test, result == 0xabCD, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Convert 0x"); + Dqn_Tester_Begin(&test, "Convert 0x"); uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("0x")); DQN_TESTER_ASSERTF(&test, result == 0x0, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Convert 0X"); + Dqn_Tester_Begin(&test, "Convert 0X"); uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("0X")); DQN_TESTER_ASSERTF(&test, result == 0x0, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Convert 3"); + Dqn_Tester_Begin(&test, "Convert 3"); uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("3")); DQN_TESTER_ASSERTF(&test, result == 3, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Convert f"); + Dqn_Tester_Begin(&test, "Convert f"); uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("f")); DQN_TESTER_ASSERTF(&test, result == 0xf, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Convert g"); + Dqn_Tester_Begin(&test, "Convert g"); uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("g")); DQN_TESTER_ASSERTF(&test, result == 0, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Convert -0x3"); + Dqn_Tester_Begin(&test, "Convert -0x3"); uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("-0x3")); DQN_TESTER_ASSERTF(&test, result == 0, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); #endif // DQN_WITH_HEX @@ -407,7 +407,7 @@ Dqn_Tester Dqn_Test_M4() #if defined(DQN_WITH_MATH) DQN_TESTER_BEGIN_GROUP("Dqn_M4"); { - Dqn_TesterBegin(&test, "Simple translate and scale matrix"); + Dqn_Tester_Begin(&test, "Simple translate and scale matrix"); Dqn_M4 translate = Dqn_M4_TranslateF(1, 2, 3); Dqn_M4 scale = Dqn_M4_ScaleF(2, 2, 2); Dqn_M4 result = Dqn_M4_Mul(translate, scale); @@ -424,7 +424,7 @@ Dqn_Tester Dqn_Test_M4() "\nresult =\n%s\nexpected =\n%s", Dqn_M4_ColumnMajorString(result).data, Dqn_M4_ColumnMajorString(EXPECT).data); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); #endif // DQN_WITH_MATH @@ -437,7 +437,7 @@ Dqn_Tester Dqn_Test_DSMap() #if defined(DQN_WITH_DSMAP) DQN_TESTER_BEGIN_GROUP("Dqn_DSMap"); { - Dqn_TesterBegin(&test, "Add r-value item to map"); + Dqn_Tester_Begin(&test, "Add r-value item to map"); Dqn_DSMap map = Dqn_DSMap_Init(128); Dqn_DSMapEntry *entry = Dqn_DSMap_AddCopy(&map, 3 /*hash*/, 5 /*value*/); DQN_TESTER_ASSERTF(&test, map.size == 128, "size: %I64d", map.size); @@ -445,11 +445,11 @@ Dqn_Tester Dqn_Test_DSMap() DQN_TESTER_ASSERTF(&test, entry->hash == 3, "hash: %zu", entry->hash); DQN_TESTER_ASSERTF(&test, entry->value == 5, "value: %d", entry->value); Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Add l-value item to map"); + Dqn_Tester_Begin(&test, "Add l-value item to map"); Dqn_DSMap map = Dqn_DSMap_Init(128); int value = 5; Dqn_DSMapEntry *entry = Dqn_DSMap_Add(&map, 3 /*hash*/, value); @@ -458,50 +458,50 @@ Dqn_Tester Dqn_Test_DSMap() DQN_TESTER_ASSERTF(&test, entry->hash == 3, "hash: %zu", entry->hash); DQN_TESTER_ASSERTF(&test, entry->value == 5, "value: %d", entry->value); Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Get item from map"); + Dqn_Tester_Begin(&test, "Get item from map"); Dqn_DSMap map = Dqn_DSMap_Init(128); Dqn_DSMapEntry *entry = Dqn_DSMap_AddCopy(&map, 3 /*hash*/, 5 /*value*/); Dqn_DSMapEntry *get_entry = Dqn_DSMap_Get(&map, 3 /*hash*/); DQN_TESTER_ASSERTF(&test, get_entry == entry, "get_entry: %p, entry: %p", get_entry, entry); Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Get non-existent item from map"); + Dqn_Tester_Begin(&test, "Get non-existent item from map"); Dqn_DSMap map = Dqn_DSMap_Init(128); Dqn_DSMapEntry *entry = Dqn_DSMap_Get(&map, 3 /*hash*/); DQN_TESTER_ASSERT(&test, entry == nullptr); Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Erase item from map"); + Dqn_Tester_Begin(&test, "Erase item from map"); Dqn_DSMap map = Dqn_DSMap_Init(128); Dqn_DSMap_AddCopy(&map, 3 /*hash*/, 5 /*value*/); DQN_TESTER_ASSERTF(&test, map.count == 1, "count: %I64d", map.count); Dqn_DSMap_Erase(&map, 3 /*hash*/, Dqn_ZeroMem_No); DQN_TESTER_ASSERTF(&test, map.count == 0, "count: %I64d", map.count); Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Erase non-existent item from map"); + Dqn_Tester_Begin(&test, "Erase non-existent item from map"); Dqn_DSMap map = Dqn_DSMap_Init(128); Dqn_DSMap_Erase(&map, 3 /*hash*/, Dqn_ZeroMem_No); DQN_TESTER_ASSERTF(&test, map.count == 0, "count: %I64d", map.count); Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Test resize on maximum load"); + Dqn_Tester_Begin(&test, "Test resize on maximum load"); const Dqn_isize INIT_SIZE = 4; Dqn_DSMap map = Dqn_DSMap_Init(INIT_SIZE); Dqn_DSMap_AddCopy(&map, 0 /*hash*/, 5 /*value*/); @@ -528,7 +528,7 @@ Dqn_Tester Dqn_Test_DSMap() DQN_TESTER_ASSERTF(&test, map.slots[6].value == 5, "value: %d", map.slots[6].value); Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); #endif // DQN_WITH_DSMAP @@ -542,7 +542,7 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_BEGIN_GROUP("Dqn_Map"); Dqn_Arena arena = {}; { - Dqn_TesterBegin(&test, "Add r-value item to map"); + Dqn_Tester_Begin(&test, "Add r-value item to map"); Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); Dqn_MapEntry *entry = Dqn_Map_AddCopy(&map, 3 /*hash*/, 5 /*value*/, Dqn_MapCollideRule::Overwrite); DQN_TESTER_ASSERTF(&test, map.size == 1, "size: %I64d", map.size); @@ -553,11 +553,11 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, entry->value == 5, "value: %d", entry->value); DQN_TESTER_ASSERTF(&test, entry->next == nullptr, "next: %p", entry->next); Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Add l-value item to map"); + Dqn_Tester_Begin(&test, "Add l-value item to map"); Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); int value = 5; Dqn_MapEntry *entry = Dqn_Map_Add(&map, 3 /*hash*/, value, Dqn_MapCollideRule::Overwrite); @@ -569,11 +569,11 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, entry->value == 5, "value: %d", entry->value); DQN_TESTER_ASSERTF(&test, entry->next == nullptr, "next: %p", entry->next); Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Add r-value item and overwrite on collision"); + Dqn_Tester_Begin(&test, "Add r-value item and overwrite on collision"); Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); Dqn_MapEntry *entry_a = Dqn_Map_AddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); Dqn_MapEntry *entry_b = Dqn_Map_AddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Overwrite); @@ -586,11 +586,11 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, entry_b->value == 6, "value: %d", entry_b->value); DQN_TESTER_ASSERTF(&test, entry_b->next == nullptr, "next: %p", entry_b->next); Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Add r-value item and fail on collision"); + Dqn_Tester_Begin(&test, "Add r-value item and fail on collision"); Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); Dqn_Map_AddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); Dqn_MapEntry *entry_b = Dqn_Map_AddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Fail); @@ -600,11 +600,11 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, map.chain_count == 0, "chain_count: %zu", map.chain_count); DQN_TESTER_ASSERTF(&test, map.free_list == nullptr, "free_list: %p", map.free_list); Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Add r-value item and chain on collision"); + Dqn_Tester_Begin(&test, "Add r-value item and chain on collision"); Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); Dqn_MapEntry *entry_a = Dqn_Map_AddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); Dqn_MapEntry *entry_b = Dqn_Map_AddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Chain); @@ -618,11 +618,11 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, entry_b->value == 6, "value: %d", entry_b->value); DQN_TESTER_ASSERTF(&test, entry_b->next == nullptr, "next: %p", entry_b->next); Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Add r-value item and get them back out again"); + Dqn_Tester_Begin(&test, "Add r-value item and get them back out again"); Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); Dqn_MapEntry *entry_a = Dqn_Map_AddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); Dqn_MapEntry *entry_b = Dqn_Map_AddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Chain); @@ -636,11 +636,11 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERT(&test, entry_a_copy == entry_a); DQN_TESTER_ASSERT(&test, entry_b_copy == entry_b); Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Add r-value item and erase it"); + Dqn_Tester_Begin(&test, "Add r-value item and erase it"); Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); Dqn_Map_AddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); Dqn_Map_AddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Chain); @@ -662,11 +662,11 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, entry->next == nullptr, "next: %p", entry->next); Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Add r-value item and erase it, zeroing the memory out"); + Dqn_Tester_Begin(&test, "Add r-value item and erase it, zeroing the memory out"); Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); Dqn_Map_AddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); Dqn_Map_AddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Chain); @@ -688,7 +688,7 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, entry->next == nullptr, "next: %p", entry->next); Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } // TODO(dqn): Test free list is chained correctly @@ -707,71 +707,71 @@ Dqn_Tester Dqn_Test_Intrinsics() DQN_TESTER_BEGIN_GROUP("Dqn_Atomic_"); { - Dqn_TesterBegin(&test, "Dqn_Atomic_AddU32"); + Dqn_Tester_Begin(&test, "Dqn_Atomic_AddU32"); uint32_t val = 0; Dqn_Atomic_AddU32(&val, 1); DQN_TESTER_ASSERTF(&test, val == 1, "val: %u", val); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Dqn_Atomic_AddU64"); + Dqn_Tester_Begin(&test, "Dqn_Atomic_AddU64"); uint64_t val = 0; Dqn_Atomic_AddU64(&val, 1); DQN_TESTER_ASSERTF(&test, val == 1, "val: %zu", val); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Dqn_Atomic_SubU32"); + Dqn_Tester_Begin(&test, "Dqn_Atomic_SubU32"); uint32_t val = 1; Dqn_Atomic_SubU32(&val, 1); DQN_TESTER_ASSERTF(&test, val == 0, "val: %u", val); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Dqn_Atomic_SubU64"); + Dqn_Tester_Begin(&test, "Dqn_Atomic_SubU64"); uint64_t val = 1; Dqn_Atomic_SubU64(&val, 1); DQN_TESTER_ASSERTF(&test, val == 0, "val: %zu", val); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Dqn_Atomic_SetValue32"); + Dqn_Tester_Begin(&test, "Dqn_Atomic_SetValue32"); long a = 0; long b = 111; Dqn_Atomic_SetValue32(&a, b); DQN_TESTER_ASSERTF(&test, a == b, "a: %lu, b: %lu", a, b); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Dqn_Atomic_SetValue64"); + Dqn_Tester_Begin(&test, "Dqn_Atomic_SetValue64"); int64_t a = 0; int64_t b = 111; Dqn_Atomic_SetValue64(DQN_CAST(uint64_t *)&a, b); DQN_TESTER_ASSERTF(&test, a == b, "a: %I64i, b: %I64i", a, b); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Dqn_CPUClockCycle"); + Dqn_Tester_Begin(&test, "Dqn_CPUClockCycle"); Dqn_CPUClockCycle(); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Dqn_CompilerReadBarrierAndCPUReadFence"); + Dqn_Tester_Begin(&test, "Dqn_CompilerReadBarrierAndCPUReadFence"); Dqn_CompilerReadBarrierAndCPUReadFence; - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Dqn_CompilerWriteBarrierAndCPUWriteFence"); + Dqn_Tester_Begin(&test, "Dqn_CompilerWriteBarrierAndCPUWriteFence"); Dqn_CompilerWriteBarrierAndCPUWriteFence; - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); return test; @@ -785,7 +785,7 @@ Dqn_Tester Dqn_Test_Rect() // NOTE: Dqn_Rect_Intersection { { - Dqn_TesterBegin(&test, "No intersection"); + Dqn_Tester_Begin(&test, "No intersection"); Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2(0, 0), Dqn_V2(100, 100)); Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2(200, 0), Dqn_V2(200, 200)); Dqn_Rect ab = Dqn_Rect_Intersection(a, b); @@ -797,11 +797,11 @@ Dqn_Tester Dqn_Test_Rect() ab.min.y, ab.max.x, ab.max.y); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "A's min intersects B"); + Dqn_Tester_Begin(&test, "A's min intersects B"); Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2(50, 50), Dqn_V2(100, 100)); Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); Dqn_Rect ab = Dqn_Rect_Intersection(a, b); @@ -813,11 +813,11 @@ Dqn_Tester Dqn_Test_Rect() ab.min.y, ab.max.x, ab.max.y); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "B's min intersects A"); + Dqn_Tester_Begin(&test, "B's min intersects A"); Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2(50, 50), Dqn_V2(100, 100)); Dqn_Rect ab = Dqn_Rect_Intersection(a, b); @@ -829,11 +829,11 @@ Dqn_Tester Dqn_Test_Rect() ab.min.y, ab.max.x, ab.max.y); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "A's max intersects B"); + Dqn_Tester_Begin(&test, "A's max intersects B"); Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2(-50, -50), Dqn_V2(100, 100)); Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); Dqn_Rect ab = Dqn_Rect_Intersection(a, b); @@ -845,11 +845,11 @@ Dqn_Tester Dqn_Test_Rect() ab.min.y, ab.max.x, ab.max.y); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "B's max intersects A"); + Dqn_Tester_Begin(&test, "B's max intersects A"); Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2(-50, -50), Dqn_V2(100, 100)); Dqn_Rect ab = Dqn_Rect_Intersection(a, b); @@ -861,12 +861,12 @@ Dqn_Tester Dqn_Test_Rect() ab.min.y, ab.max.x, ab.max.y); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "B contains A"); + Dqn_Tester_Begin(&test, "B contains A"); Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2(25, 25), Dqn_V2( 25, 25)); Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); Dqn_Rect ab = Dqn_Rect_Intersection(a, b); @@ -878,11 +878,11 @@ Dqn_Tester Dqn_Test_Rect() ab.min.y, ab.max.x, ab.max.y); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "A contains B"); + Dqn_Tester_Begin(&test, "A contains B"); Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2(25, 25), Dqn_V2( 25, 25)); Dqn_Rect ab = Dqn_Rect_Intersection(a, b); @@ -894,11 +894,11 @@ Dqn_Tester Dqn_Test_Rect() ab.min.y, ab.max.x, ab.max.y); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "A equals B"); + Dqn_Tester_Begin(&test, "A equals B"); Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2(0, 0), Dqn_V2(100, 100)); Dqn_Rect b = a; Dqn_Rect ab = Dqn_Rect_Intersection(a, b); @@ -910,7 +910,7 @@ Dqn_Tester Dqn_Test_Rect() ab.min.y, ab.max.x, ab.max.y); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } } DQN_TESTER_END_GROUP(&test); @@ -923,22 +923,22 @@ Dqn_Tester Dqn_Test_PerfCounter() Dqn_Tester test = {}; DQN_TESTER_BEGIN_GROUP("Dqn_Perf_Counter"); { - Dqn_TesterBegin(&test, "Dqn_Perf_CounterNow"); + Dqn_Tester_Begin(&test, "Dqn_Perf_CounterNow"); uint64_t result = Dqn_Perf_CounterNow(); DQN_TESTER_ASSERT(&test, result != 0); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Consecutive ticks are ordered"); + Dqn_Tester_Begin(&test, "Consecutive ticks are ordered"); uint64_t a = Dqn_Perf_CounterNow(); uint64_t b = Dqn_Perf_CounterNow(); DQN_TESTER_ASSERTF(&test, b >= a, "a: %zu, b: %zu", a, b); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Ticks to time are a correct order of magnitude"); + Dqn_Tester_Begin(&test, "Ticks to time are a correct order of magnitude"); uint64_t a = Dqn_Perf_CounterNow(); uint64_t b = Dqn_Perf_CounterNow(); @@ -949,7 +949,7 @@ Dqn_Tester Dqn_Test_PerfCounter() DQN_TESTER_ASSERTF(&test, s <= ms, "s: %f, ms: %f", s, ms); DQN_TESTER_ASSERTF(&test, ms <= micro_s, "ms: %f, micro_s: %f", ms, micro_s); DQN_TESTER_ASSERTF(&test, micro_s <= ns, "micro_s: %f, ns: %f", micro_s, ns); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); return test; @@ -960,313 +960,313 @@ Dqn_Tester Dqn_Test_OS() Dqn_Tester test = {}; DQN_TESTER_BEGIN_GROUP("Dqn_OS_"); { - Dqn_TesterBegin(&test, "Generate secure RNG bytes with nullptr"); + Dqn_Tester_Begin(&test, "Generate secure RNG bytes with nullptr"); Dqn_b32 result = Dqn_OS_SecureRNGBytes(nullptr, 1); DQN_TESTER_ASSERT(&test, result == false); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Generate secure RNG 32 bytes"); + Dqn_Tester_Begin(&test, "Generate secure RNG 32 bytes"); char const ZERO[32] = {}; char buf[32] = {}; Dqn_b32 result = Dqn_OS_SecureRNGBytes(buf, Dqn_CArray_CountI(buf)); DQN_TESTER_ASSERT(&test, result); DQN_TESTER_ASSERT(&test, DQN_MEMCMP(buf, ZERO, Dqn_CArray_Count(buf)) != 0); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Generate secure RNG 0 bytes"); + Dqn_Tester_Begin(&test, "Generate secure RNG 0 bytes"); char buf[32] = {}; buf[0] = 'Z'; Dqn_b32 result = Dqn_OS_SecureRNGBytes(buf, 0); DQN_TESTER_ASSERT(&test, result); DQN_TESTER_ASSERT(&test, buf[0] == 'Z'); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Query executable directory"); + Dqn_Tester_Begin(&test, "Query executable directory"); Dqn_Arena arena = {}; Dqn_String8 result = Dqn_OS_EXEDir(Dqn_Arena_Allocator(&arena)); DQN_TESTER_ASSERT(&test, Dqn_String8_IsValid(result)); DQN_TESTER_ASSERTF(&test, Dqn_Fs_DirExists(result), "result(%zu): %.*s", result.size, DQN_STRING_FMT(result)); Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); return test; } -Dqn_Tester Dqn_Test_Str() +Dqn_Tester Dqn_Test_CString8() { Dqn_Tester test = {}; - DQN_TESTER_BEGIN_GROUP("Dqn_Str"); + DQN_TESTER_BEGIN_GROUP("Dqn_CString8"); // --------------------------------------------------------------------------------------------- // NOTE: Dqn_CString8_ToI64 // --------------------------------------------------------------------------------------------- { - Dqn_TesterBegin(&test, "To I64: Convert nullptr"); + Dqn_Tester_Begin(&test, "To I64: Convert nullptr"); int64_t result = Dqn_CString8_ToI64(nullptr); DQN_TESTER_ASSERT(&test, result == 0); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To I64: Convert empty string"); + Dqn_Tester_Begin(&test, "To I64: Convert empty string"); int64_t result = Dqn_CString8_ToI64(""); DQN_TESTER_ASSERT(&test, result == 0); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To I64: Convert \"1\""); + Dqn_Tester_Begin(&test, "To I64: Convert \"1\""); int64_t result = Dqn_CString8_ToI64("1"); DQN_TESTER_ASSERT(&test, result == 1); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To I64: Convert \"-0\""); + Dqn_Tester_Begin(&test, "To I64: Convert \"-0\""); int64_t result = Dqn_CString8_ToI64("-0"); DQN_TESTER_ASSERT(&test, result == 0); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To I64: Convert \"-1\""); + Dqn_Tester_Begin(&test, "To I64: Convert \"-1\""); int64_t result = Dqn_CString8_ToI64("-1"); DQN_TESTER_ASSERT(&test, result == -1); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To I64: Convert \"1.2\""); + Dqn_Tester_Begin(&test, "To I64: Convert \"1.2\""); int64_t result = Dqn_CString8_ToI64("1.2"); DQN_TESTER_ASSERT(&test, result == 1); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To I64: Convert \"1,234\""); + Dqn_Tester_Begin(&test, "To I64: Convert \"1,234\""); int64_t result = Dqn_CString8_ToI64("1,234"); DQN_TESTER_ASSERT(&test, result == 1234); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To I64: Convert \"1,2\""); + Dqn_Tester_Begin(&test, "To I64: Convert \"1,2\""); int64_t result = Dqn_CString8_ToI64("1,2"); DQN_TESTER_ASSERT(&test, result == 12); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To I64: Convert \"12a3\""); + Dqn_Tester_Begin(&test, "To I64: Convert \"12a3\""); int64_t result = Dqn_CString8_ToI64("12a3"); DQN_TESTER_ASSERT(&test, result == 12); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } // --------------------------------------------------------------------------------------------- // NOTE: Dqn_CString8_ToU64 // --------------------------------------------------------------------------------------------- { - Dqn_TesterBegin(&test, "To U64: Convert nullptr"); + Dqn_Tester_Begin(&test, "To U64: Convert nullptr"); uint64_t result = Dqn_CString8_ToU64(nullptr); DQN_TESTER_ASSERTF(&test, result == 0, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To U64: Convert empty string"); + Dqn_Tester_Begin(&test, "To U64: Convert empty string"); uint64_t result = Dqn_CString8_ToU64(""); DQN_TESTER_ASSERTF(&test, result == 0, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To U64: Convert \"1\""); + Dqn_Tester_Begin(&test, "To U64: Convert \"1\""); uint64_t result = Dqn_CString8_ToU64("1"); DQN_TESTER_ASSERTF(&test, result == 1, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To U64: Convert \"-0\""); + Dqn_Tester_Begin(&test, "To U64: Convert \"-0\""); uint64_t result = Dqn_CString8_ToU64("-0"); DQN_TESTER_ASSERTF(&test, result == 0, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To U64: Convert \"-1\""); + Dqn_Tester_Begin(&test, "To U64: Convert \"-1\""); uint64_t result = Dqn_CString8_ToU64("-1"); DQN_TESTER_ASSERTF(&test, result == 0, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To U64: Convert \"1.2\""); + Dqn_Tester_Begin(&test, "To U64: Convert \"1.2\""); uint64_t result = Dqn_CString8_ToU64("1.2"); DQN_TESTER_ASSERTF(&test, result == 1, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To U64: Convert \"1,234\""); + Dqn_Tester_Begin(&test, "To U64: Convert \"1,234\""); uint64_t result = Dqn_CString8_ToU64("1,234"); DQN_TESTER_ASSERTF(&test, result == 1234, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To U64: Convert \"1,2\""); + Dqn_Tester_Begin(&test, "To U64: Convert \"1,2\""); uint64_t result = Dqn_CString8_ToU64("1,2"); DQN_TESTER_ASSERTF(&test, result == 12, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "To U64: Convert \"12a3\""); + Dqn_Tester_Begin(&test, "To U64: Convert \"12a3\""); uint64_t result = Dqn_CString8_ToU64("12a3"); DQN_TESTER_ASSERTF(&test, result == 12, "result: %zu", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } // --------------------------------------------------------------------------------------------- // NOTE: Dqn_CString8_Find // --------------------------------------------------------------------------------------------- { - Dqn_TesterBegin(&test, "Find: String (char) is not in buffer"); + Dqn_Tester_Begin(&test, "Find: String (char) is not in buffer"); char const buf[] = "836a35becd4e74b66a0d6844d51f1a63018c7ebc44cf7e109e8e4bba57eefb55"; char const find[] = "2"; char const *result = Dqn_CString8_Find(buf, find, Dqn_CString8_ArrayCountI(buf), Dqn_CString8_ArrayCountI(find)); DQN_TESTER_ASSERT(&test, result == nullptr); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Find: String (char) is in buffer"); + Dqn_Tester_Begin(&test, "Find: String (char) is in buffer"); char const buf[] = "836a35becd4e74b66a0d6844d51f1a63018c7ebc44cf7e109e8e4bba57eefb55"; char const find[] = "6"; char const *result = Dqn_CString8_Find(buf, find, Dqn_CString8_ArrayCountI(buf), Dqn_CString8_ArrayCountI(find)); DQN_TESTER_ASSERT(&test, result != nullptr); DQN_TESTER_ASSERT(&test, result[0] == '6' && result[1] == 'a'); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } // NOTE: Dqn_CString8_FileNameFromPath // --------------------------------------------------------------------------------------------- { - Dqn_TesterBegin(&test, "File name from Windows path"); + Dqn_Tester_Begin(&test, "File name from Windows path"); Dqn_isize file_name_size = 0; char const buf[] = "C:\\ABC\\test.exe"; char const *result = Dqn_CString8_FileNameFromPath(buf, Dqn_CString8_ArrayCountI(buf), &file_name_size); DQN_TESTER_ASSERTF(&test, file_name_size == 8, "size: %I64d", file_name_size); DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(Dqn_String8_Init(result, file_name_size), DQN_STRING8("test.exe")), "%.*s", DQN_CAST(int)file_name_size, result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "File name from Linux path"); + Dqn_Tester_Begin(&test, "File name from Linux path"); Dqn_isize file_name_size = 0; char const buf[] = "/ABC/test.exe"; char const *result = Dqn_CString8_FileNameFromPath(buf, Dqn_CString8_ArrayCountI(buf), &file_name_size); DQN_TESTER_ASSERTF(&test, file_name_size == 8, "size: %I64d", file_name_size); DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(Dqn_String8_Init(result, file_name_size), DQN_STRING8("test.exe")), "%.*s", (int)file_name_size, result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } // NOTE: Dqn_CString8_TrimPrefix // --------------------------------------------------------------------------------------------- { - Dqn_TesterBegin(&test, "Trim prefix"); + Dqn_Tester_Begin(&test, "Trim prefix"); char const prefix[] = "@123"; char const buf[] = "@123string"; Dqn_isize trimmed_size = 0; - char const *result = Dqn_CString8_TrimPrefix(buf, Dqn_CString8_ArrayCountI(buf), prefix, Dqn_CString8_ArrayCountI(prefix), &trimmed_size); + char const *result = Dqn_CString8_TrimPrefix(buf, prefix, Dqn_CString8_ArrayCountI(buf), Dqn_CString8_ArrayCountI(prefix), Dqn_CString8EqCase::Sensitive, &trimmed_size); DQN_TESTER_ASSERTF(&test, trimmed_size == 6, "size: %I64d", trimmed_size); DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(Dqn_String8_Init(result, trimmed_size), DQN_STRING8("string")), "%.*s", (int)trimmed_size, result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Trim prefix, nullptr trimmed size"); + Dqn_Tester_Begin(&test, "Trim prefix, nullptr trimmed size"); char const prefix[] = "@123"; char const buf[] = "@123string"; - char const *result = Dqn_CString8_TrimPrefix(buf, Dqn_CString8_ArrayCountI(buf), prefix, Dqn_CString8_ArrayCountI(prefix), nullptr); + char const *result = Dqn_CString8_TrimPrefix(buf, prefix, Dqn_CString8_ArrayCountI(buf), Dqn_CString8_ArrayCountI(prefix), Dqn_CString8EqCase::Sensitive, nullptr); DQN_TESTER_ASSERT(&test, result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } // NOTE: Dqn_CString8_IsAllDigits // --------------------------------------------------------------------------------------------- { - Dqn_TesterBegin(&test, "Is all digits fails on non-digit string"); + Dqn_Tester_Begin(&test, "Is all digits fails on non-digit string"); char const buf[] = "@123string"; Dqn_b32 result = Dqn_CString8_IsAllDigits(buf, Dqn_CString8_ArrayCountI(buf)); DQN_TESTER_ASSERT(&test, result == false); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Is all digits fails on nullptr"); + Dqn_Tester_Begin(&test, "Is all digits fails on nullptr"); Dqn_b32 result = Dqn_CString8_IsAllDigits(nullptr, 0); DQN_TESTER_ASSERT(&test, result == false); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Is all digits fails on nullptr w/ size"); + Dqn_Tester_Begin(&test, "Is all digits fails on nullptr w/ size"); Dqn_b32 result = Dqn_CString8_IsAllDigits(nullptr, 1); DQN_TESTER_ASSERT(&test, result == false); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Is all digits fails on 0 size w/ string"); + Dqn_Tester_Begin(&test, "Is all digits fails on 0 size w/ string"); char const buf[] = "@123string"; Dqn_b32 result = Dqn_CString8_IsAllDigits(buf, 0); DQN_TESTER_ASSERT(&test, result == false); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Is all digits success"); + Dqn_Tester_Begin(&test, "Is all digits success"); char const buf[] = "23"; Dqn_b32 result = Dqn_CString8_IsAllDigits(buf, Dqn_CString8_ArrayCountI(buf)); DQN_TESTER_ASSERT(&test, DQN_CAST(bool)result == true); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Is all digits fails on whitespace"); + Dqn_Tester_Begin(&test, "Is all digits fails on whitespace"); char const buf[] = "23 "; Dqn_b32 result = Dqn_CString8_IsAllDigits(buf, Dqn_CString8_ArrayCountI(buf)); DQN_TESTER_ASSERT(&test, DQN_CAST(bool)result == false); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); return test; } -Dqn_Tester Dqn_Test_String() +Dqn_Tester Dqn_Test_String8() { Dqn_Tester test = {}; DQN_TESTER_BEGIN_GROUP("Dqn_String8"); { - Dqn_TesterBegin(&test, "Initialise with string literal w/ macro"); + Dqn_Tester_Begin(&test, "Initialise with string literal w/ macro"); Dqn_String8 string = DQN_STRING8("AB"); DQN_TESTER_ASSERTF(&test, string.size == 2, "size: %I64d", string.size); DQN_TESTER_ASSERTF(&test, string.data[0] == 'A', "string[0]: %c", string.data[0]); DQN_TESTER_ASSERTF(&test, string.data[1] == 'B', "string[1]: %c", string.data[1]); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Initialise with format string"); + Dqn_Tester_Begin(&test, "Initialise with format string"); Dqn_Arena arena = {}; Dqn_String8 string = Dqn_String8_Fmt(Dqn_Arena_Allocator(&arena), "%s", "AB"); DQN_TESTER_ASSERTF(&test, string.size == 2, "size: %I64d", string.size); @@ -1274,11 +1274,11 @@ Dqn_Tester Dqn_Test_String() DQN_TESTER_ASSERTF(&test, string.data[1] == 'B', "string[1]: %c", string.data[1]); DQN_TESTER_ASSERTF(&test, string.data[2] == 0, "string[2]: %c", string.data[2]); Dqn_Arena_Free(&arena, false /*clear_mem*/); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Copy string"); + Dqn_Tester_Begin(&test, "Copy string"); Dqn_Arena arena = {}; Dqn_String8 string = DQN_STRING8("AB"); Dqn_String8 copy = Dqn_String8_Copy(Dqn_Arena_Allocator(&arena), string); @@ -1287,60 +1287,60 @@ Dqn_Tester Dqn_Test_String() DQN_TESTER_ASSERTF(&test, copy.data[1] == 'B', "copy[1]: %c", copy.data[1]); DQN_TESTER_ASSERTF(&test, copy.data[2] == 0, "copy[2]: %c", copy.data[2]); Dqn_Arena_Free(&arena, false /*clear_mem*/); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Trim whitespace around string"); + Dqn_Tester_Begin(&test, "Trim whitespace around string"); Dqn_String8 string = Dqn_String8_TrimWhitespaceAround(DQN_STRING8(" AB ")); DQN_TESTER_ASSERTF(&test, string.size == 2, "size: %I64d", string.size); DQN_TESTER_ASSERTF(&test, string.data[0] == 'A', "string[0]: %c", string.data[0]); DQN_TESTER_ASSERTF(&test, string.data[1] == 'B', "string[1]: %c", string.data[1]); DQN_TESTER_ASSERTF(&test, string.data[2] == ' ', "string[1]: %c", string.data[1]); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Allocate string from arena"); + Dqn_Tester_Begin(&test, "Allocate string from arena"); Dqn_Arena arena = {}; Dqn_String8 string = Dqn_String8_Allocate(Dqn_Arena_Allocator(&arena), 2, Dqn_ZeroMem_No); DQN_TESTER_ASSERTF(&test, string.size == 2, "size: %I64d", string.size); Dqn_Arena_Free(&arena, false /*clear_mem*/); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } // NOTE: Dqn_CString8_Trim[Prefix/Suffix] // --------------------------------------------------------------------------------------------- { - Dqn_TesterBegin(&test, "Trim prefix with matching prefix"); + Dqn_Tester_Begin(&test, "Trim prefix with matching prefix"); Dqn_String8 input = DQN_STRING8("nft/abc"); Dqn_String8 result = Dqn_String8_TrimPrefix(input, DQN_STRING8("nft/")); DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(result, DQN_STRING8("abc")), "%.*s", DQN_STRING_FMT(result)); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Trim prefix with non matching prefix"); + Dqn_Tester_Begin(&test, "Trim prefix with non matching prefix"); Dqn_String8 input = DQN_STRING8("nft/abc"); Dqn_String8 result = Dqn_String8_TrimPrefix(input, DQN_STRING8(" ft/")); DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(result, input), "%.*s", DQN_STRING_FMT(result)); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Trim suffix with matching suffix"); + Dqn_Tester_Begin(&test, "Trim suffix with matching suffix"); Dqn_String8 input = DQN_STRING8("nft/abc"); Dqn_String8 result = Dqn_String8_TrimSuffix(input, DQN_STRING8("abc")); DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(result, DQN_STRING8("nft/")), "%.*s", DQN_STRING_FMT(result)); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Trim suffix with non matching suffix"); + Dqn_Tester_Begin(&test, "Trim suffix with non matching suffix"); Dqn_String8 input = DQN_STRING8("nft/abc"); Dqn_String8 result = Dqn_String8_TrimSuffix(input, DQN_STRING8("ab")); DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(result, input), "%.*s", DQN_STRING_FMT(result)); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } @@ -1348,46 +1348,46 @@ Dqn_Tester Dqn_Test_String() // NOTE: Dqn_String8_IsAllDigits // --------------------------------------------------------------------------------------------- { - Dqn_TesterBegin(&test, "Is all digits fails on non-digit string"); + Dqn_Tester_Begin(&test, "Is all digits fails on non-digit string"); Dqn_b32 result = Dqn_String8_IsAllDigits(DQN_STRING8("@123string")); DQN_TESTER_ASSERT(&test, result == false); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Is all digits fails on nullptr"); + Dqn_Tester_Begin(&test, "Is all digits fails on nullptr"); Dqn_b32 result = Dqn_String8_IsAllDigits(Dqn_String8_Init(nullptr, 0)); DQN_TESTER_ASSERT(&test, result == false); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Is all digits fails on nullptr w/ size"); + Dqn_Tester_Begin(&test, "Is all digits fails on nullptr w/ size"); Dqn_b32 result = Dqn_String8_IsAllDigits(Dqn_String8_Init(nullptr, 1)); DQN_TESTER_ASSERT(&test, result == false); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Is all digits fails on string w/ 0 size"); + Dqn_Tester_Begin(&test, "Is all digits fails on string w/ 0 size"); char const buf[] = "@123string"; Dqn_b32 result = Dqn_String8_IsAllDigits(Dqn_String8_Init(buf, 0)); DQN_TESTER_ASSERT(&test, result == false); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Is all digits success"); + Dqn_Tester_Begin(&test, "Is all digits success"); Dqn_b32 result = Dqn_String8_IsAllDigits(DQN_STRING8("23")); DQN_TESTER_ASSERT(&test, DQN_CAST(bool)result == true); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Is all digits fails on whitespace"); + Dqn_Tester_Begin(&test, "Is all digits fails on whitespace"); Dqn_b32 result = Dqn_String8_IsAllDigits(DQN_STRING8("23 ")); DQN_TESTER_ASSERT(&test, DQN_CAST(bool)result == false); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); return test; @@ -1401,16 +1401,16 @@ Dqn_Tester Dqn_Test_TicketMutex() // TODO: We don't have a meaningful test but since atomics are // implemented with a macro this ensures that we test that they are // written correctly. - Dqn_TesterBegin(&test, "Ticket mutex start and stop"); + Dqn_Tester_Begin(&test, "Ticket mutex start and stop"); Dqn_TicketMutex mutex = {}; Dqn_TicketMutex_Begin(&mutex); Dqn_TicketMutex_End(&mutex); DQN_TESTER_ASSERT(&test, mutex.ticket == mutex.serving); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "Ticket mutex start and stop w/ advanced API"); + Dqn_Tester_Begin(&test, "Ticket mutex start and stop w/ advanced API"); Dqn_TicketMutex mutex = {}; unsigned int ticket_a = Dqn_TicketMutex_MakeTicket(&mutex); unsigned int ticket_b = Dqn_TicketMutex_MakeTicket(&mutex); @@ -1424,7 +1424,7 @@ Dqn_Tester Dqn_Test_TicketMutex() DQN_TESTER_ASSERT(&test, mutex.ticket == mutex.serving); DQN_TESTER_ASSERT(&test, mutex.ticket == ticket_b + 1); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); return test; @@ -1436,35 +1436,35 @@ Dqn_Tester Dqn_Test_Win() #if defined(DQN_OS_WIN32) DQN_TESTER_BEGIN_GROUP("Dqn_Win"); { - Dqn_TesterBegin(&test, "String8 to String16 size required"); + Dqn_Tester_Begin(&test, "String8 to String16 size required"); int result = Dqn_Win_String8ToCString16(DQN_STRING8("a"), nullptr, 0); DQN_TESTER_ASSERTF(&test, result == 2, "Size returned: %d. This size should include the null-terminator", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "String16 to String8 size required"); + Dqn_Tester_Begin(&test, "String16 to String8 size required"); int result = Dqn_Win_String16ToCString8(DQN_STRING16(L"a"), nullptr, 0); DQN_TESTER_ASSERTF(&test, result == 2, "Size returned: %d. This size should include the null-terminator", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "String8 to String16 size required"); + Dqn_Tester_Begin(&test, "String8 to String16 size required"); int result = Dqn_Win_String8ToCString16(DQN_STRING8("String"), nullptr, 0); DQN_TESTER_ASSERTF(&test, result == 7, "Size returned: %d. This size should include the null-terminator", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "String16 to String8 size required"); + Dqn_Tester_Begin(&test, "String16 to String8 size required"); int result = Dqn_Win_String16ToCString8(DQN_STRING16(L"String"), nullptr, 0); DQN_TESTER_ASSERTF(&test, result == 7, "Size returned: %d. This size should include the null-terminator", result); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "String8 to String16"); + Dqn_Tester_Begin(&test, "String8 to String16"); Dqn_Arena arena = {}; Dqn_String8 const INPUT = DQN_STRING8("String"); int size_required = Dqn_Win_String8ToCString16(INPUT, nullptr, 0); @@ -1480,11 +1480,11 @@ Dqn_Tester Dqn_Test_Win() DQN_TESTER_ASSERTF(&test, size_returned == Dqn_CArray_Count(EXPECTED), "string_size: %d, expected: %zu", size_returned, Dqn_CArray_Count(EXPECTED)); DQN_TESTER_ASSERT(&test, DQN_MEMCMP(EXPECTED, string, sizeof(EXPECTED)) == 0); Dqn_Arena_Free(&arena, false /*clear_mem*/); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } { - Dqn_TesterBegin(&test, "String16 to String8: No null-terminate"); + Dqn_Tester_Begin(&test, "String16 to String8: No null-terminate"); Dqn_Arena arena = {}; Dqn_String16 INPUT = DQN_STRING16(L"String"); int size_required = Dqn_Win_String16ToCString8(INPUT, nullptr, 0); @@ -1500,7 +1500,7 @@ Dqn_Tester Dqn_Test_Win() DQN_TESTER_ASSERTF(&test, size_returned == Dqn_CArray_Count(EXPECTED), "string_size: %d, expected: %zu", size_returned, Dqn_CArray_Count(EXPECTED)); DQN_TESTER_ASSERT(&test, DQN_MEMCMP(EXPECTED, string, sizeof(EXPECTED)) == 0); Dqn_Arena_Free(&arena, false /*clear_mem*/); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); #endif // DQN_OS_WIN32 @@ -1701,12 +1701,12 @@ Dqn_Tester Dqn_Test_Keccak() for (Dqn_String8 input : INPUTS) { - Dqn_TesterBegin(&test, "%.*s - Input: %.*s", DQN_STRING_FMT(DQN_TESTS__HASH_STRING[hash_type]), DQN_CAST(int)DQN_MIN(input.size, 54), input.data); + Dqn_Tester_Begin(&test, "%.*s - Input: %.*s", DQN_STRING_FMT(DQN_TESTS__HASH_STRING[hash_type]), DQN_CAST(int)DQN_MIN(input.size, 54), input.data); Dqn_Test__KeccakDispatch(&test, hash_type, input); - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } - Dqn_TesterBegin(&test, "%.*s - Deterministic random inputs", DQN_STRING_FMT(DQN_TESTS__HASH_STRING[hash_type])); + Dqn_Tester_Begin(&test, "%.*s - Deterministic random inputs", DQN_STRING_FMT(DQN_TESTS__HASH_STRING[hash_type])); for (int index = 0; index < 128; index++) { char src[4096] = {}; @@ -1718,7 +1718,7 @@ Dqn_Tester Dqn_Test_Keccak() Dqn_String8 input = Dqn_String8_Init(src, src_size); Dqn_Test__KeccakDispatch(&test, hash_type, input); } - Dqn_TesterEnd(&test); + Dqn_Tester_End(&test); } DQN_TESTER_END_GROUP(&test); #endif // DQN_KECCAK_H @@ -1742,16 +1742,15 @@ void Dqn_Test_RunSuite() Dqn_Test_PerfCounter(), Dqn_Test_OS(), Dqn_Test_Keccak(), - Dqn_Test_Str(), - Dqn_Test_String(), + Dqn_Test_CString8(), + Dqn_Test_String8(), Dqn_Test_TicketMutex(), Dqn_Test_Win(), }; int total_tests = 0; int total_good_tests = 0; - for (Dqn_Tester &test : tests) - { + for (Dqn_Tester &test : tests) { total_tests += test.num_tests_in_group; total_good_tests += test.num_tests_ok_in_group; }