mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 03:25:45 +01:00
add function for comparing an NBT string with a C string
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <endian.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../util/types.h"
|
||||
|
||||
@@ -10,6 +11,19 @@ static inline u16 nbt_strlen(u8 const *restrict buf) {
|
||||
return be16toh(*(u16 *)(buf));
|
||||
}
|
||||
|
||||
/* compares the string in `buf` to `matstr`.
|
||||
* returns `=0` if equal, `>0` if buf is greater, `<0` if matstr is greater. */
|
||||
static int nbt_cmpstr(char const *restrict matstr, u8 const *restrict buf) {
|
||||
u16 len = nbt_strlen(buf);
|
||||
|
||||
// allocate and copy bytes
|
||||
char str[len + 1];
|
||||
memcpy(str, buf + 2, len);
|
||||
str[len] = '\0';
|
||||
|
||||
return strncmp(str, matstr, len);
|
||||
}
|
||||
|
||||
int nbt_proc(void **restrict datout, u8 const *restrict buf, size_t len) {
|
||||
|
||||
// first byte should be a compound tag
|
||||
|
||||
Reference in New Issue
Block a user