mirror of
https://github.com/thepigeongenerator/mcaselector-lite
synced 2026-02-08 07:33:35 +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 <endian.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "../util/types.h"
|
#include "../util/types.h"
|
||||||
|
|
||||||
@@ -10,6 +11,19 @@ static inline u16 nbt_strlen(u8 const *restrict buf) {
|
|||||||
return be16toh(*(u16 *)(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) {
|
int nbt_proc(void **restrict datout, u8 const *restrict buf, size_t len) {
|
||||||
|
|
||||||
// first byte should be a compound tag
|
// first byte should be a compound tag
|
||||||
|
|||||||
Reference in New Issue
Block a user