diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-04-29 14:32:32 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-04-29 14:32:32 -0700 |
commit | 1ca136f653d66cd271a33c37ea17cf836f7197b4 (patch) | |
tree | 0477fb7c9e5604a52baea117cb2b1b2a1810e9a3 /utf8.c | |
parent | 17d4160a2e6dcb07d2d7d09f8682ec120034a084 (diff) | |
download | txr-1ca136f653d66cd271a33c37ea17cf836f7197b4.tar.gz txr-1ca136f653d66cd271a33c37ea17cf836f7197b4.tar.bz2 txr-1ca136f653d66cd271a33c37ea17cf836f7197b4.zip |
ffi: conv between strings and char/wchar_t arrays.
* ffi.c (struct txr_ffi_type): New bitfield members
char_conv, wchar_conv.
(ffi_array_put): Check char_conv and wchar_conv flags
and perform conversion to string, watching out for the
presence or absence of null termination.
(ffi_type_compile): When compiling array, check for the
str and wstr element type, and set the flags.
* utf8.c (ut8f_dup_from_buf): New function.
* utf8.c (ut8f_dup_from_buf): Declared.
Diffstat (limited to 'utf8.c')
-rw-r--r-- | utf8.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -207,6 +207,14 @@ wchar_t *utf8_dup_from(const char *str) return wstr; } +wchar_t *utf8_dup_from_buf(const char *str, size_t size) +{ + size_t nchar = utf8_from_buf(0, coerce(const unsigned char *, str), size); + wchar_t *wstr = chk_wmalloc(nchar); + utf8_from_buf(wstr, coerce(const unsigned char *, str), size); + return wstr; +} + unsigned char *utf8_dup_to_buf(const wchar_t *wstr, size_t *pnbytes, int null_term) { |