include/mgba-util/string.h (view raw)
1/* Copyright (c) 2013-2014 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef UTIL_STRING_H
7#define UTIL_STRING_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#ifndef HAVE_STRNDUP
14// This is sometimes a macro
15char* strndup(const char* start, size_t len);
16#endif
17
18#ifndef HAVE_STRDUP
19char* strdup(const char* str);
20#endif
21
22#ifndef HAVE_STRLCPY
23size_t strlcpy(char* restrict dst, const char* restrict src, size_t dstsize);
24#endif
25
26char* strnrstr(const char* restrict s1, const char* restrict s2, size_t len);
27bool endswith(const char* restrict s1, const char* restrict end);
28bool startswith(const char* restrict s1, const char* restrict start);
29
30size_t toUtf8(uint32_t unichar, char* buffer);
31int utfcmp(const uint16_t* utf16, const char* utf8, size_t utf16Length, size_t utf8Length);
32char* utf16to8(const uint16_t* utf16, size_t length);
33uint32_t utf8Char(const char** unicode, size_t* length);
34uint32_t utf16Char(const uint16_t** unicode, size_t* length);
35char* gbkToUtf8(const char* gbk, size_t length);
36
37int hexDigit(char digit);
38const char* hex32(const char* line, uint32_t* out);
39const char* hex24(const char* line, uint32_t* out);
40const char* hex16(const char* line, uint16_t* out);
41const char* hex12(const char* line, uint16_t* out);
42const char* hex8(const char* line, uint8_t* out);
43const char* hex4(const char* line, uint8_t* out);
44
45void rtrim(char* string);
46
47ssize_t parseQuotedString(const char* unparsed, ssize_t unparsedLen, char* parsed, ssize_t parsedLen);
48bool wildcard(const char* search, const char* string);
49
50CXX_GUARD_END
51
52#endif