ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
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 <stdint.h>
45#include <stddef.h>
46#include <stdbool.h>
47#include <stdio.h>
48
49/* ============================================================================
50 * UTF-8 Decoding Functions
51 * ========================================================================== */
52
85int utf8_decode(const uint8_t *s, uint32_t *codepoint);
86
87/* ============================================================================
88 * UTF-8 Display Width Calculation
89 * ========================================================================== */
90
123int utf8_display_width(const char *str);
124
146int utf8_display_width_n(const char *str, size_t max_bytes);
147
161size_t utf8_prefix_bytes_for_width(const char *str, size_t max_bytes, int max_width);
162
172bool utf8_output_enabled(void);
173
174/* ============================================================================
175 * UTF-8 Validation Functions
176 * ========================================================================== */
177
200bool utf8_is_valid(const char *str);
201
228bool utf8_is_ascii_only(const char *str);
229
260size_t utf8_char_count(const char *str);
261
302size_t utf8_to_codepoints(const char *str, uint32_t *out_codepoints, size_t max_codepoints);
303
329int utf8_next_char_bytes(const char *str, size_t max_bytes);
330
331/* ============================================================================
332 * UTF-8 String Search Functions
333 * ========================================================================== */
334
368const char *utf8_strcasestr(const char *haystack, const char *needle);
369
405void utf8_write_lowercase(FILE *output, const char *text);
unsigned int uint32_t
Definition common.h:62
unsigned char uint8_t
Definition common.h:60
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:102
bool utf8_is_ascii_only(const char *str)
Check if a string contains only ASCII characters.
Definition utf8.c:137
bool utf8_is_valid(const char *str)
Check if a string is valid UTF-8.
Definition utf8.c:128
int utf8_decode(const uint8_t *s, uint32_t *codepoint)
Decode a UTF-8 sequence to a Unicode codepoint.
Definition utf8.c:27
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:157
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:293
int utf8_display_width(const char *str)
Calculate terminal display width of a UTF-8 string.
Definition utf8.c:98
int utf8_next_char_bytes(const char *str, size_t max_bytes)
Get byte length of next UTF-8 character.
Definition utf8.c:177
const char * utf8_strcasestr(const char *haystack, const char *needle)
Case-insensitive substring search with full Unicode support.
Definition utf8.c:205
size_t utf8_char_count(const char *str)
Count UTF-8 characters (not bytes).
Definition utf8.c:108
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:93