public asciify

This commit is contained in:
2026-05-27 09:58:19 -03:00
parent 74a5ef63b0
commit 902e29dc93
2 changed files with 16 additions and 3 deletions

View File

@@ -16,8 +16,7 @@
/* Internal helpers -- kept private to this translation unit. */ /* Internal helpers -- kept private to this translation unit. */
static int uselesschar(int c); static int uselesschar(int c);
/* trim is public (declared in lib11sht.h) */ /* trim and asciify are public (declared in lib11sht.h) */
static void asciify(const char *src, char *dest, size_t dest_size);
static int ulen(unsigned char c); static int ulen(unsigned char c);
static float shit11(char *s1, char *s2); static float shit11(char *s1, char *s2);
static float fmin3(float a, float b, float c); static float fmin3(float a, float b, float c);
@@ -210,7 +209,7 @@ static int ulen(unsigned char c)
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
static void asciify(const char *src, char *dest, size_t dest_size) void asciify(const char *src, char *dest, size_t dest_size)
{ {
int len, i, k, j, found; int len, i, k, j, found;
char ch[5]; /* UTF8 multibyte char */ char ch[5]; /* UTF8 multibyte char */

View File

@@ -92,4 +92,18 @@ int fequal(float a, float b, float delta);
* be NUL-terminated. */ * be NUL-terminated. */
void trim(char *s); void trim(char *s);
/* Transliterate accented Latin chars to plain ASCII. Walks src as UTF-8,
* mapping known accented chars (a-acute, c-cedilla, n-tilde, NBSP, ...)
* to their ASCII equivalents and copying ASCII bytes verbatim. Output is
* always pure ASCII and NUL-terminated. Bytes that don't match the
* transliteration table are skipped.
*
* Parameters:
* src input UTF-8 string (NUL-terminated)
* dest output buffer (filled with NUL-terminated ASCII)
* dest_size size of dest in bytes (writes capped at dest_size-1 + final NUL)
*
* Safe for NULL / zero-size args (no-op). */
void asciify(const char *src, char *dest, size_t dest_size);
#endif /* LIB11SHT_H */ #endif /* LIB11SHT_H */