Save Manager

This commit is contained in:
2022-12-17 23:18:06 -08:00
parent 4090e61406
commit 1dbfd9f42e
23 changed files with 574 additions and 15 deletions

35
src/dawn/util/string.hpp Normal file
View File

@ -0,0 +1,35 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "assert/assert.hpp"
/**
* Finds the next instance of a character within a string, safely (with a
* limit). The returned pointer will be NULL if not found, or a pointer to a
* point within the string where the instance is.
*
* @param haystack String to search.
* @param needle Character to search for.
* @param limit Max length you want to search for to limit yourself to.
* @return Pointer to the character found, or NULL if not found.
*/
static inline char * stringFindNext(
char *haystack,
char needle,
size_t limit
) {
char *p;
assertNotNull(haystack);
assertTrue(limit > 0);
for(p = haystack; (size_t)(p - haystack) < limit; p++) {
if(*p == needle) return p;
assertFalse(*p == '\0');// We don't allow you to have a limit > strlen
}
return NULL;
}