wix-on-linux/uchars.c
Simon Tatham 39faf94ea2 Move the char16 functions into their own file.
This completes the removal of the monolithic fake-lib.[ch].
2017-05-18 07:16:21 +01:00

29 lines
691 B
C

#include "memory.h"
#include "uchars.h"
char *ascii(const char16_t *wstr, bool translate_slashes)
{
size_t len = 0;
for (const char16_t *wp = wstr; *wp; wp++)
len++;
char *ret = snewn(len + 1, char);
char *p = ret;
for (const char16_t *wp = wstr; *wp; wp++)
*p++ = (*wp == '\\' && translate_slashes ? '/' :
*wp < 0x80 ? *wp :
'?');
*p = '\0';
return ret;
}
void c16cpy(char16_t *out, uint32_t *outsize, char *s)
{
uint32_t retlen = 0;
while (retlen < *outsize) {
char16_t c = (out[retlen] = (unsigned char)*s++);
if (!c)
break;
retlen++;
}
*outsize = retlen;
}