2018-05-15 02:27:25 +02:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2018-05-15 02:27:25 +02:00
|
|
|
* See COPYING for further information.
|
|
|
|
* ---
|
2024-05-16 23:30:41 +02:00
|
|
|
* Copyright (c) 2011-2024, Lukas Weber <laochailan@web.de>.
|
|
|
|
* Copyright (c) 2012-2024, Andrei Alexeyev <akari@taisei-project.org>.
|
2018-05-15 02:27:25 +02:00
|
|
|
*/
|
|
|
|
|
2021-08-12 23:09:01 +02:00
|
|
|
#pragma once
|
2018-05-15 02:27:25 +02:00
|
|
|
#include "taisei.h"
|
|
|
|
|
2024-09-07 11:19:23 +02:00
|
|
|
#include "memory/arena.h"
|
|
|
|
#include "systime.h"
|
|
|
|
|
2018-05-15 02:27:25 +02:00
|
|
|
#include <time.h>
|
2018-05-28 10:10:41 +02:00
|
|
|
#include <SDL.h>
|
2018-05-15 02:27:25 +02:00
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
#define UNICODE_UNKNOWN 0xFFFD
|
|
|
|
#define UNICODE_BOM_NATIVE 0xFEFF
|
|
|
|
#define UNICODE_BOM_SWAPPED 0xFFFE
|
2019-01-04 23:59:39 +01:00
|
|
|
#define UNICODE_ELLIPSIS 0x2026
|
2018-06-29 23:36:51 +02:00
|
|
|
|
2018-05-15 02:27:25 +02:00
|
|
|
#undef strlcat
|
|
|
|
#define strlcat SDL_strlcat
|
|
|
|
|
|
|
|
#undef strlcpy
|
|
|
|
#define strlcpy SDL_strlcpy
|
|
|
|
|
2022-02-22 19:55:50 +01:00
|
|
|
#ifndef TAISEI_BUILDCONF_HAVE_STRTOK_R
|
2018-05-15 02:27:25 +02:00
|
|
|
#undef strtok_r
|
|
|
|
#define strtok_r _ts_strtok_r
|
2022-02-22 19:55:50 +01:00
|
|
|
char *strtok_r(char *str, const char *delim, char **nextp);
|
|
|
|
#endif
|
2018-05-15 02:27:25 +02:00
|
|
|
|
2022-02-22 20:00:46 +01:00
|
|
|
#ifndef TAISEI_BUILDCONF_HAVE_MEMRCHR
|
|
|
|
#undef memrchr
|
|
|
|
#define memrchr _ts_memrchr
|
|
|
|
void *memrchr(const void *s, int c, size_t n);
|
|
|
|
#endif
|
|
|
|
|
2022-08-27 01:40:55 +02:00
|
|
|
#ifndef TAISEI_BUILDCONF_HAVE_MEMMEM
|
|
|
|
#undef memmem
|
|
|
|
#define memmem _ts_memmem
|
|
|
|
void *memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen)
|
|
|
|
attr_nonnull_all;
|
|
|
|
#endif
|
|
|
|
|
2019-03-18 05:41:12 +01:00
|
|
|
#undef strcasecmp
|
|
|
|
#define strcasecmp SDL_strcasecmp
|
|
|
|
|
2018-05-15 02:27:25 +02:00
|
|
|
bool strendswith(const char *s, const char *e) attr_pure;
|
|
|
|
bool strstartswith(const char *s, const char *p) attr_pure;
|
|
|
|
bool strendswith_any(const char *s, const char **earray) attr_pure;
|
|
|
|
bool strstartswith_any(const char *s, const char **earray) attr_pure;
|
|
|
|
void stralloc(char **dest, const char *src);
|
2019-08-04 00:29:41 +02:00
|
|
|
char* strjoin(const char *first, ...) attr_sentinel attr_returns_allocated;
|
|
|
|
char* vstrfmt(const char *fmt, va_list args) attr_returns_allocated;
|
|
|
|
char* strfmt(const char *fmt, ...) attr_printf(1, 2) attr_returns_allocated;
|
2024-09-07 11:19:23 +02:00
|
|
|
char* vstrfmt_arena(MemArena *arena, const char *fmt, va_list args) attr_returns_allocated;
|
|
|
|
char* strfmt_arena(MemArena *arena, const char *fmt, ...) attr_printf(2, 3) attr_returns_allocated;
|
2024-07-12 01:39:43 +02:00
|
|
|
char* strappend(char **dst, const char *src);
|
2019-08-04 00:29:41 +02:00
|
|
|
char* strftimealloc(const char *fmt, const struct tm *timeinfo) attr_returns_allocated;
|
2019-03-11 00:21:43 +01:00
|
|
|
void expand_escape_sequences(char *str);
|
2018-05-15 02:27:25 +02:00
|
|
|
|
2023-01-09 04:19:31 +01:00
|
|
|
uint32_t* ucs4chr(const uint32_t *ucs4, uint32_t chr) attr_dealloc(SDL_free, 1);
|
2018-05-15 02:27:25 +02:00
|
|
|
size_t ucs4len(const uint32_t *ucs4);
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
void utf8_to_ucs4(const char *utf8, size_t bufsize, uint32_t buf[bufsize]) attr_nonnull(1, 3);
|
2019-08-04 00:29:41 +02:00
|
|
|
uint32_t* utf8_to_ucs4_alloc(const char *utf8) attr_nonnull(1) attr_returns_allocated attr_nonnull(1);
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
void ucs4_to_utf8(const uint32_t *ucs4, size_t bufsize, char buf[bufsize]) attr_nonnull(1, 3);
|
2019-08-04 00:29:41 +02:00
|
|
|
char* ucs4_to_utf8_alloc(const uint32_t *ucs4) attr_nonnull(1) attr_returns_allocated attr_nonnull(1);
|
2018-05-15 02:27:25 +02:00
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
uint32_t utf8_getch(const char **src) attr_nonnull(1);
|
|
|
|
|
2020-03-09 02:31:17 +01:00
|
|
|
void format_huge_num(uint digits, uint64_t num, size_t bufsize, char buf[bufsize]);
|
2024-08-30 11:08:41 +02:00
|
|
|
void hexdigest(const uint8_t *input, size_t input_size, char *output, size_t output_size);
|
2019-01-04 23:59:39 +01:00
|
|
|
|
2018-05-28 10:10:41 +02:00
|
|
|
#define FILENAME_TIMESTAMP_MIN_BUF_SIZE 23
|
|
|
|
size_t filename_timestamp(char *buf, size_t buf_size, const SystemTime time) attr_nonnull(1);
|
2022-08-27 02:14:00 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test if string matches a simple 'glob'-like pattern.
|
|
|
|
*
|
|
|
|
* Only '*' is supported as a metacharacter in the glob.
|
|
|
|
* '*' matches zero or more characters lazily.
|
|
|
|
* If the glob is not empty and does not end with a *, the last segment is matched greedily.
|
|
|
|
* An empty glob matches everything.
|
|
|
|
*/
|
|
|
|
bool strnmatch(size_t globsize, const char glob[globsize], size_t insize, const char input[insize]);
|
|
|
|
bool strmatch(const char *glob, const char *input);
|