minecraft-pi-reborn/libreborn/include/libreborn/string.h

42 lines
848 B
C
Raw Normal View History

2021-06-17 21:32:24 +00:00
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "util.h"
// Set obj To NULL On asprintf() Failure
#define safe_asprintf(obj, ...) \
{ \
if (asprintf(obj, __VA_ARGS__) == -1) { \
*obj = NULL; \
} \
ALLOC_CHECK(*obj); \
}
// Dynamic String Append Macro
#define string_append(str, format, ...) \
{ \
char *old = *str; \
2022-04-22 23:38:15 +00:00
safe_asprintf(str, "%s" format, *str == NULL ? "" : *str, ##__VA_ARGS__); \
2021-06-17 21:32:24 +00:00
ALLOC_CHECK(*str); \
if (old != NULL && old != *str) { \
free(old); \
} \
}
2022-03-14 23:09:25 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2021-06-17 21:32:24 +00:00
// Sanitize String
2022-03-14 23:09:25 +00:00
void sanitize_string(char **str, int max_length, unsigned int allow_newlines);
2022-03-25 02:47:34 +00:00
// Starts With
int starts_with(const char *str, const char *prefix);
2022-03-14 23:09:25 +00:00
#ifdef __cplusplus
2021-06-17 21:32:24 +00:00
}
2022-03-14 23:09:25 +00:00
#endif