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

49 lines
1.0 KiB
C
Raw Normal View History

2021-06-17 21:32:24 +00:00
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
2022-07-20 06:58:14 +00:00
#include <iconv.h>
#include <stdint.h>
2021-06-17 21:32:24 +00:00
#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-07-20 06:58:14 +00:00
// CP437
void safe_iconv(iconv_t cd, char *input, size_t input_size, char *output, size_t output_size);
char *to_cp437(const char *input);
char *from_cp437(const char *input);
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