ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
utf8.h
Go to the documentation of this file.
1
41
42#pragma once
43
44#include <stdbool.h>
45#include <stddef.h>
46#include <stdint.h>
47#include <stdio.h>
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53/* ============================================================================
54 * UTF-8 Decoding Functions
55 * ========================================================================== */
56
92int utf8_decode(const uint8_t *s, uint32_t *codepoint);
93
94/* ============================================================================
95 * UTF-8 Display Width Calculation
96 * ========================================================================== */
97
131int utf8_display_width(const char *str);
132
156int utf8_display_width_n(const char *str, size_t max_bytes);
157
172size_t utf8_prefix_bytes_for_width(const char *str, size_t max_bytes,
173 int max_width);
174
184bool utf8_output_enabled(void);
185
186/* ============================================================================
187 * UTF-8 Validation Functions
188 * ========================================================================== */
189
213bool utf8_is_valid(const char *str);
214
242bool utf8_is_ascii_only(const char *str);
243
275size_t utf8_char_count(const char *str);
276
319size_t utf8_to_codepoints(const char *str, uint32_t *out_codepoints,
320 size_t max_codepoints);
321
347int utf8_next_char_bytes(const char *str, size_t max_bytes);
348
349/* ============================================================================
350 * UTF-8 String Search Functions
351 * ========================================================================== */
352
388const char *utf8_strcasestr(const char *haystack, const char *needle);
389
429void utf8_write_lowercase(FILE *output, const char *text);
430
431#ifdef __cplusplus
432}
433#endif
unsigned int uint32_t
unsigned char uint8_t
int utf8_display_width_n(const char *str, size_t max_bytes)
Calculate terminal display width of a UTF-8 string up to byte limit.
Definition utf8.c:106
bool utf8_is_ascii_only(const char *str)
Check if a string contains only ASCII characters.
Definition utf8.c:141
bool utf8_is_valid(const char *str)
Check if a string is valid UTF-8.
Definition utf8.c:132
int utf8_decode(const uint8_t *s, uint32_t *codepoint)
Decode a UTF-8 sequence to a Unicode codepoint.
Definition utf8.c:28
size_t utf8_to_codepoints(const char *str, uint32_t *out_codepoints, size_t max_codepoints)
Convert UTF-8 string to array of Unicode codepoints.
Definition utf8.c:161
bool utf8_output_enabled(void)
Return whether terminal output should use UTF-8 according to –utf8.
Definition utf8.c:22
void utf8_write_lowercase(FILE *output, const char *text)
Write UTF-8 string to file with ASCII lowercase conversion.
Definition utf8.c:305
int utf8_display_width(const char *str)
Calculate terminal display width of a UTF-8 string.
Definition utf8.c:102
int utf8_next_char_bytes(const char *str, size_t max_bytes)
Get byte length of next UTF-8 character.
Definition utf8.c:183
const char * utf8_strcasestr(const char *haystack, const char *needle)
Case-insensitive substring search with full Unicode support.
Definition utf8.c:212
size_t utf8_char_count(const char *str)
Count UTF-8 characters (not bytes).
Definition utf8.c:112
size_t utf8_prefix_bytes_for_width(const char *str, size_t max_bytes, int max_width)
Return the byte length of a prefix fitting a terminal column limit.
Definition utf8.c:96