mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(string): add SStrCmp
This commit is contained in:
parent
e74eb83854
commit
0d07d79ed0
3 changed files with 26 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#include "storm/String.hpp"
|
#include "storm/String.hpp"
|
||||||
#include "storm/Error.hpp"
|
#include "storm/Error.hpp"
|
||||||
#include "storm/string/bjhash.hpp"
|
#include "storm/string/bjhash.hpp"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
uint8_t bytesFromUTF8[256] = {
|
uint8_t bytesFromUTF8[256] = {
|
||||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
|
|
@ -128,6 +129,10 @@ void GetNextTextUpper(uint32_t* orig, const char** string, uint32_t* upper) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t SStrCmp(const char* string1, const char* string2, size_t maxchars) {
|
||||||
|
return strncmp(string1, string2, maxchars);
|
||||||
|
}
|
||||||
|
|
||||||
size_t SStrCopy(char* dest, const char* source, size_t destsize) {
|
size_t SStrCopy(char* dest, const char* source, size_t destsize) {
|
||||||
STORM_ASSERT(dest);
|
STORM_ASSERT(dest);
|
||||||
STORM_ASSERT(source);
|
STORM_ASSERT(source);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#define STORM_MAX_PATH 260
|
#define STORM_MAX_PATH 260
|
||||||
#define STORM_MAX_STR 0x7FFFFFFF
|
#define STORM_MAX_STR 0x7FFFFFFF
|
||||||
|
|
||||||
|
int32_t SStrCmp(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);
|
||||||
|
|
||||||
uint32_t SStrHashHT(const char* string);
|
uint32_t SStrHashHT(const char* string);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,25 @@
|
||||||
#include "storm/String.hpp"
|
#include "storm/String.hpp"
|
||||||
#include "test/Test.hpp"
|
#include "test/Test.hpp"
|
||||||
|
|
||||||
|
TEST_CASE("SStrCmp", "[string]") {
|
||||||
|
SECTION("compares two strings that exactly match correctly") {
|
||||||
|
auto compare = SStrCmp("foo", "foo", STORM_MAX_STR);
|
||||||
|
REQUIRE(compare == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("compares two strings that partially match correctly") {
|
||||||
|
auto compare1 = SStrCmp("bar", "foobar", STORM_MAX_STR);
|
||||||
|
auto compare2 = SStrCmp("foobar", "bar", STORM_MAX_STR);
|
||||||
|
REQUIRE(compare1 < 0);
|
||||||
|
REQUIRE(compare2 > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("compares two strings that do not match correctly") {
|
||||||
|
auto compare = SStrCmp("bar", "xyzzy", STORM_MAX_STR);
|
||||||
|
REQUIRE(compare < 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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