Files
Roman ChojnackiandClaude Opus 5.5 dfc310f1cb Notify: reaktor_utf8_clean_dup, REAKTOR_HAVE_GIBUS
A cleaned copy is one call next to reaktor_utf8_clean. Notifications
use it, pass NULL for the session's error, and test the same define the
runtime does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 16:48:41 +01:00

31 lines
627 B
C

#include <string.h>
#include <SDL3/SDL.h>
#include "util.h"
size_t reaktor_utf8_clean(char *dst, const char *src, size_t cap)
{
size_t left = strlen(src), n = 0;
char ch[4];
if (!cap) return 0;
while (left) {
size_t k = (size_t)(SDL_UCS4ToUTF8(SDL_StepUTF8(&src, &left), ch) - ch);
if (n + k >= cap) break;
memcpy(dst + n, ch, k);
n += k;
}
dst[n] = 0;
return n;
}
char *reaktor_utf8_clean_dup(const char *src)
{
size_t cap = strlen(src) * 3 + 1;
char *dst = (char *)SDL_malloc(cap);
if (dst) reaktor_utf8_clean(dst, src, cap);
return dst;
}