commit 9e845cc

uint  ·  2026-10-18 21:29:18 +0000 UTC
parent 24fe1a2
UTF: Import (clean) function signatures
1 files changed,  +47, -191
+47, -191
  1@@ -17,196 +17,52 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  2 #ifndef ULEUTF_H
  3 #define ULEUTF_H
  4 
  5-/* Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 >
  6- * src2 respectively, case insensitive. */
  7-utf8_constexpr14 utf8_nonnull utf8_pure int
  8-utf8casecmp(const utf8_int8_t *src1, const utf8_int8_t *src2);
  9-
 10-/* Append the utf8 string src onto the utf8 string dst. */
 11-utf8_nonnull utf8_weak utf8_int8_t *
 12-utf8cat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src);
 13-
 14-/* Find the first match of the utf8 codepoint chr in the utf8 string src. */
 15-utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *
 16-utf8chr(const utf8_int8_t *src, utf8_int32_t chr);
 17-
 18-/* Return less than 0, 0, greater than 0 if src1 < src2,
 19- * src1 == src2, src1 > src2 respectively. */
 20-utf8_constexpr14 utf8_nonnull utf8_pure int utf8cmp(const utf8_int8_t *src1,
 21-                                                    const utf8_int8_t *src2);
 22-
 23-/* Copy the utf8 string src onto the memory allocated in dst. */
 24-utf8_nonnull utf8_weak utf8_int8_t *
 25-utf8cpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src);
 26-
 27-/* Number of utf8 codepoints in the utf8 string src that consists entirely
 28- * of utf8 codepoints not from the utf8 string reject. */
 29-utf8_constexpr14 utf8_nonnull utf8_pure size_t
 30-utf8cspn(const utf8_int8_t *src, const utf8_int8_t *reject);
 31-
 32-/* Duplicate the utf8 string src by getting its size, malloc'ing a new buffer
 33- * copying over the data, and returning that. Or 0 if malloc failed. */
 34-utf8_weak utf8_int8_t *utf8dup(const utf8_int8_t *src);
 35-
 36-/* Number of utf8 codepoints in the utf8 string str,
 37- * excluding the null terminating byte. */
 38-utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8len(const utf8_int8_t *str);
 39-
 40-/* Similar to utf8len, except that only at most n bytes of src are looked. */
 41-utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8nlen(const utf8_int8_t *str,
 42-                                                        size_t n);
 43-
 44-/* Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 >
 45- * src2 respectively, case insensitive. Checking at most n bytes of each utf8
 46- * string. */
 47-utf8_constexpr14 utf8_nonnull utf8_pure int
 48-utf8ncasecmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n);
 49-
 50-/* Append the utf8 string src onto the utf8 string dst,
 51- * writing at most n+1 bytes. Can produce an invalid utf8
 52- * string if n falls partway through a utf8 codepoint. */
 53-utf8_nonnull utf8_weak utf8_int8_t *
 54-utf8ncat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src,
 55-         size_t n);
 56-
 57-/* Return less than 0, 0, greater than 0 if src1 < src2,
 58- * src1 == src2, src1 > src2 respectively. Checking at most n
 59- * bytes of each utf8 string. */
 60-utf8_constexpr14 utf8_nonnull utf8_pure int
 61-utf8ncmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n);
 62-
 63-/* Copy the utf8 string src onto the memory allocated in dst.
 64- * Copies at most n bytes. If n falls partway through a utf8
 65- * codepoint, or if dst doesn't have enough room for a null
 66- * terminator, the final string will be cut short to preserve
 67- * utf8 validity. */
 68-
 69-utf8_nonnull utf8_weak utf8_int8_t *
 70-utf8ncpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src,
 71-         size_t n);
 72-
 73-/* Similar to utf8dup, except that at most n bytes of src are copied. If src is
 74- * longer than n, only n bytes are copied and a null byte is added.
 75- *
 76- * Returns a new string if successful, 0 otherwise */
 77-utf8_weak utf8_int8_t *utf8ndup(const utf8_int8_t *src, size_t n);
 78-
 79-/* Locates the first occurrence in the utf8 string str of any byte in the
 80- * utf8 string accept, or 0 if no match was found. */
 81-utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *
 82-utf8pbrk(const utf8_int8_t *str, const utf8_int8_t *accept);
 83-
 84-/* Find the last match of the utf8 codepoint chr in the utf8 string src. */
 85-utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *
 86-utf8rchr(const utf8_int8_t *src, utf8_int32_t chr);
 87-
 88-/* Number of bytes in the utf8 string str,
 89- * including the null terminating byte. */
 90-utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8size(const utf8_int8_t *str);
 91-
 92-/* Similar to utf8size, except that the null terminating byte is excluded. */
 93-utf8_constexpr14 utf8_nonnull utf8_pure size_t
 94-utf8size_lazy(const utf8_int8_t *str);
 95-
 96-/* Similar to utf8size, except that only at most n bytes of src are looked and
 97- * the null terminating byte is excluded. */
 98-utf8_constexpr14 utf8_nonnull utf8_pure size_t
 99-utf8nsize_lazy(const utf8_int8_t *str, size_t n);
100-
101-/* Number of utf8 codepoints in the utf8 string src that consists entirely
102- * of utf8 codepoints from the utf8 string accept. */
103-utf8_constexpr14 utf8_nonnull utf8_pure size_t
104-utf8spn(const utf8_int8_t *src, const utf8_int8_t *accept);
105-
106-/* The position of the utf8 string needle in the utf8 string haystack. */
107-utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *
108-utf8str(const utf8_int8_t *haystack, const utf8_int8_t *needle);
109-
110-/* The position of the utf8 string needle in the utf8 string haystack, case
111- * insensitive. */
112-utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *
113-utf8casestr(const utf8_int8_t *haystack, const utf8_int8_t *needle);
114-
115-/* Return 0 on success, or the position of the invalid
116- * utf8 codepoint on failure. */
117-utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *
118-utf8valid(const utf8_int8_t *str);
119-
120-/* Similar to utf8valid, except that only at most n bytes of src are looked. */
121-utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *
122-utf8nvalid(const utf8_int8_t *str, size_t n);
123-
124-/* Given a null-terminated string, makes the string valid by replacing invalid
125- * codepoints with a 1-byte replacement. Returns 0 on success. */
126-utf8_nonnull utf8_weak int utf8makevalid(utf8_int8_t *str,
127-                                         const utf8_int32_t replacement);
128-
129-/* Sets out_codepoint to the current utf8 codepoint in str, and returns the
130- * address of the next utf8 codepoint after the current one in str. */
131-utf8_constexpr14 utf8_nonnull utf8_int8_t *
132-utf8codepoint(const utf8_int8_t *utf8_restrict str,
133-              utf8_int32_t *utf8_restrict out_codepoint);
134-
135-/* Calculates the size of the next utf8 codepoint in str. */
136-utf8_constexpr14 utf8_nonnull utf8_pure size_t
137-utf8codepointcalcsize(const utf8_int8_t *str);
138-
139-/* Returns the size of the given codepoint in bytes. */
140-utf8_constexpr14 utf8_pure size_t utf8codepointsize(utf8_int32_t chr);
141-
142-/* Returns the number of terminal columns the given codepoint occupies when
143- * printed with a fixed-width font: 0 for zero-width codepoints (the null
144- * codepoint and combining marks), 2 for wide (double-width) codepoints, 1 for
145- * ordinary codepoints, and -1 for non-printable control codepoints. */
146-utf8_constexpr14 utf8_pure int utf8codepointvisualwidth(utf8_int32_t chr);
147-
148-/* Write a codepoint to the given string, and return the address to the next
149- * place after the written codepoint. Pass how many bytes left in the buffer to
150- * n. If there is not enough space for the codepoint, this function returns
151- * null. */
152-utf8_nonnull utf8_weak utf8_int8_t *
153-utf8catcodepoint(utf8_int8_t *str, utf8_int32_t chr, size_t n);
154-
155-/* Returns 1 if the given character is lowercase, or 0 if it is not. */
156-utf8_constexpr14 utf8_pure int utf8islower(utf8_int32_t chr);
157-
158-/* Returns 1 if the given character is uppercase, or 0 if it is not. */
159-utf8_constexpr14 utf8_pure int utf8isupper(utf8_int32_t chr);
160-
161-/* Transform the given string into all lowercase codepoints in place. This
162- * function does not allocate memory. All currently supported case mappings
163- * preserve the number of bytes in the encoded string. */
164-utf8_nonnull utf8_weak void utf8lwr(utf8_int8_t *utf8_restrict str);
165-
166-/* Transform the given string into all uppercase codepoints in place. This
167- * function does not allocate memory. All currently supported case mappings
168- * preserve the number of bytes in the encoded string. */
169-utf8_nonnull utf8_weak void utf8upr(utf8_int8_t *utf8_restrict str);
170-
171-/* Make a codepoint lower case if possible. */
172-utf8_constexpr14 utf8_pure utf8_int32_t utf8lwrcodepoint(utf8_int32_t cp);
173-
174-/* Make a codepoint upper case if possible. */
175-utf8_constexpr14 utf8_pure utf8_int32_t utf8uprcodepoint(utf8_int32_t cp);
176-
177-/* Sets out_codepoint to the current utf8 codepoint in str, and returns the
178- * address of the previous utf8 codepoint before the current one in str. */
179-utf8_constexpr14 utf8_nonnull utf8_int8_t *
180-utf8rcodepoint(const utf8_int8_t *utf8_restrict str,
181-               utf8_int32_t *utf8_restrict out_codepoint);
182-
183-/* Duplicate the utf8 string src by getting its size, calling alloc_func_ptr to
184- * copy over data to a new buffer, and returning that. Or 0 if alloc_func_ptr
185- * returned null. */
186-utf8_weak utf8_int8_t *utf8dup_ex(const utf8_int8_t *src,
187-                                  utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *,
188-                                                                 size_t),
189-                                  utf8_int8_t *user_data);
190-
191-/* Similar to utf8dup, except that at most n bytes of src are copied. If src is
192- * longer than n, only n bytes are copied and a null byte is added.
193- *
194- * Returns a new string if successful, 0 otherwise. */
195-utf8_weak utf8_int8_t *utf8ndup_ex(const utf8_int8_t *src, size_t n, utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, size_t), utf8_int8_t *user_data);
196+#include "uletypes.h"
197+
198+typedef char    utf8_int8_t;
199+typedef ule_i32 utf8_int32_t;
200+
201+/* Implemented */
202+
203+/* TODO */
204+int uleutf_casecmp(const char* src1, const char* src2);
205+char* uleutf_cat(char* dst, const char* src);
206+char* uleutf_chr(const char* src, ule_i32 chr);
207+int uleutf_cmp(const char* src1, const char* src2);
208+char* uleutf_cpy(char* dst, const char* src);
209+size_t uleutf_cspn(const char* src, const char* reject);
210+char* uleutf_dup(const char* src);
211+size_t uleutf_len(const char* str);
212+size_t uleutf_nlen(const char* str, size_t n);
213+int uleutf_ncasecmp(const char* src1, const char* src2, size_t n);
214+char* uleutf_ncat(char* dst, const char* src, size_t n);
215+int uleutf_ncmp(const char* src1, const char* src2, size_t n);
216+char* uleutf_ncpy(char* dst, const char* src, size_t n);
217+char* uleutf_ndup(const char* src, size_t n);
218+char* uleutf_pbrk(const char* str, const char* accept);
219+char* uleutf_rchr(const char* src, ule_i32 chr);
220+size_t uleutf_size(const char* str);
221+size_t uleutf_size_lazy(const char* str);
222+size_t uleutf_nsize_lazy(const char* str, size_t n);
223+size_t uleutf_spn(const char* src, const char* accept);
224+char* uleutf_str(const char* haystack, const char* needle);
225+char* uleutf_casestr(const char* haystack, const char* needle);
226+char* uleutf_valid(const char* str);
227+char* uleutf_nvalid(const char* str, size_t n);
228+int uleutf_makevalid(char* str, ule_i32 replacement);
229+char* uleutf_codepoint(const char* str, ule_i32* out_codepoint);
230+size_t uleutf_codepointcalcsize(const char* str);
231+size_t uleutf_codepointsize(ule_i32 chr);
232+int uleutf_codepointvisualwidth(ule_i32 chr);
233+char* uleutf_catcodepoint(char* str, ule_i32 chr, size_t n);
234+int uleutf_islower(ule_i32 chr);
235+int uleutf_isupper(ule_i32 chr);
236+void uleutf_lwr(char* str);
237+void uleutf_upr(char* str);
238+ule_i32 uleutf_lwrcodepoint(ule_i32 cp);
239+ule_i32 uleutf_uprcodepoint(ule_i32 cp);
240+char* uleutf_rcodepoint(const char* str, ule_i32* out_codepoint);
241+char* uleutf_dup_ex(const char* src, char* (*alloc_func_ptr)(char*, size_t), char* user_data);
242+char* uleutf_ndup_ex(const char* src, size_t n, char* (*alloc_func_ptr)(char*, size_t), char* user_data);
243 
244 #endif /* ULEUTF_H */