1/* Copyright 2026 uint (and contributors)
2
3Permission to use, copy, modify, and distribute this software for any
4purpose with or without fee is hereby granted, provided that the above
5copyright notice and this permission notice appear in all copies.
6
7THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15/* uleutf is based on utf8.h on https://github.com/sheredom/utf8.h
16 Implementations are their work, not mine. This is just an ANSI C rewrite */
17
18#ifndef ULEUTF_H
19#define ULEUTF_H
20
21#include "uletypes.h"
22
23/* Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 >
24 src2 respectively, case insensitive */
25int uleutf_casecmp(const char* src1, const char* src2);
26
27/* Append the utf8 string src onto the utf8 string dst */
28char* uleutf_cat(char* dst, const char* src);
29
30/* Find the first match of the utf8 codepoint chr in the utf8 string src */
31char* uleutf_chr(const char* src, ule_i32 chr);
32
33/* Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2,
34 src1 > src2 respectively */
35int uleutf_cmp(const char* src1, const char* src2, size_t n);
36
37/* Return less than 0, 0, greater than 0 if src1 < src2,
38 src1 == src2, src1 > src2 respectively. Checking at most n
39 bytes of each utf8 string */
40int uleutf_ncmp(const char* src1, const char* src2, size_t n);
41
42/* The position of the utf8 string needle in the utf8 string haystack */
43char* uleutf_str(const char* haystack, const char* needle);
44
45/* Sets out_codepoint to the current utf8 codepoint in str, and returns the
46 address of the next utf8 codepoint after the current one in str */
47char* uleutf_codepoint(const char* str, ule_i32* out_codepoint);
48
49/* Calculates the size of the next utf8 codepoint in str */
50size_t uleutf_codepointcalcsize(const char* str);
51
52/* Returns the size of the given codepoint in bytes */
53size_t uleutf_codepointsize(ule_i32 chr);
54
55/* Returns the number of terminal columns the given codepoint occupies when
56 printed with a fixed-width font: 0 for zero-width codepoints (the null
57 codepoint and combining marks), 2 for wide (double-width) codepoints, 1 for
58 ordinary codepoints, and -1 for non-printable control codepoints */
59int uleutf_codepointvisualwidth(ule_i32 chr);
60
61/* TODO */
62char* uleutf_cpy(char* dst, const char* src);
63size_t uleutf_cspn(const char* src, const char* reject);
64char* uleutf_dup(const char* src);
65size_t uleutf_len(const char* str);
66size_t uleutf_nlen(const char* str, size_t n);
67int uleutf_ncasecmp(const char* src1, const char* src2, size_t n);
68char* uleutf_ncat(char* dst, const char* src, size_t n);
69char* uleutf_ncpy(char* dst, const char* src, size_t n);
70char* uleutf_ndup(const char* src, size_t n);
71char* uleutf_pbrk(const char* str, const char* accept);
72char* uleutf_rchr(const char* src, ule_i32 chr);
73size_t uleutf_size(const char* str);
74size_t uleutf_size_lazy(const char* str);
75size_t uleutf_nsize_lazy(const char* str, size_t n);
76size_t uleutf_spn(const char* src, const char* accept);
77char* uleutf_casestr(const char* haystack, const char* needle);
78char* uleutf_valid(const char* str);
79char* uleutf_nvalid(const char* str, size_t n);
80int uleutf_makevalid(char* str, ule_i32 replacement);
81char* uleutf_catcodepoint(char* str, ule_i32 chr, size_t n);
82int uleutf_islower(ule_i32 chr);
83int uleutf_isupper(ule_i32 chr);
84void uleutf_lwr(char* str);
85void uleutf_upr(char* str);
86ule_i32 uleutf_lwrcodepoint(ule_i32 cp);
87ule_i32 uleutf_uprcodepoint(ule_i32 cp);
88char* uleutf_rcodepoint(const char* str, ule_i32* out_codepoint);
89char* uleutf_dup_ex(const char* src, char* (*alloc_func_ptr)(char*, size_t), char* user_data);
90char* uleutf_ndup_ex(const char* src, size_t n, char* (*alloc_func_ptr)(char*, size_t), char* user_data);
91
92#endif /* ULEUTF_H */
93