mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 10:32:29 +00:00
feat(string): add SStrDupA
This commit is contained in:
parent
d3f3c10aa5
commit
399e3f02d6
3 changed files with 25 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
#include "storm/String.hpp"
|
#include "storm/String.hpp"
|
||||||
#include "storm/Error.hpp"
|
#include "storm/Error.hpp"
|
||||||
|
#include "storm/Memory.hpp"
|
||||||
#include "storm/string/bjhash.hpp"
|
#include "storm/string/bjhash.hpp"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
@ -171,6 +172,14 @@ size_t SStrCopy(char* dest, const char* source, size_t destsize) {
|
||||||
return static_cast<size_t>(destbuf - dest);
|
return static_cast<size_t>(destbuf - dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* SStrDupA(const char* string, const char* filename, uint32_t linenumber) {
|
||||||
|
size_t len = SStrLen(string) + 1;
|
||||||
|
char* dup = static_cast<char*>(SMemAlloc(len, filename, linenumber, 0x0));
|
||||||
|
memcpy(dup, string, len);
|
||||||
|
|
||||||
|
return dup;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t SStrHashHT(const char* string) {
|
uint32_t SStrHashHT(const char* string) {
|
||||||
char normalized[0x400];
|
char normalized[0x400];
|
||||||
char* buf = normalized;
|
char* buf = normalized;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ int32_t SStrCmpI(const char* string1, const char* string2, size_t maxchars);
|
||||||
|
|
||||||
size_t SStrCopy(char* dest, const char* source, size_t destsize);
|
size_t SStrCopy(char* dest, const char* source, size_t destsize);
|
||||||
|
|
||||||
|
char* SStrDupA(const char* string, const char* filename, uint32_t linenumber);
|
||||||
|
|
||||||
uint32_t SStrHashHT(const char* string);
|
uint32_t SStrHashHT(const char* string);
|
||||||
|
|
||||||
size_t SStrLen(const char* string);
|
size_t SStrLen(const char* string);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "storm/String.hpp"
|
#include "storm/String.hpp"
|
||||||
|
#include "storm/Memory.hpp"
|
||||||
#include "test/Test.hpp"
|
#include "test/Test.hpp"
|
||||||
|
|
||||||
TEST_CASE("SStrCmp", "[string]") {
|
TEST_CASE("SStrCmp", "[string]") {
|
||||||
|
|
@ -37,6 +38,19 @@ TEST_CASE("SStrCmpI", "[string]") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("SStrDupA", "[string]") {
|
||||||
|
SECTION("duplicates string correctly") {
|
||||||
|
auto string1 = "foo bar";
|
||||||
|
auto string2 = SStrDupA(string1, __FILE__, __LINE__);
|
||||||
|
auto compare = SStrCmp(string1, string2, STORM_MAX_STR);
|
||||||
|
auto newPtr = string1 != string2;
|
||||||
|
SMemFree(string2);
|
||||||
|
|
||||||
|
REQUIRE(compare == 0);
|
||||||
|
REQUIRE(newPtr == true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("SStrHashHT", "[string]") {
|
TEST_CASE("SStrHashHT", "[string]") {
|
||||||
SECTION("hashes simple string correctly") {
|
SECTION("hashes simple string correctly") {
|
||||||
auto hash = SStrHashHT("foo");
|
auto hash = SStrHashHT("foo");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue