I guess that string_bytes/3 may still be under construction, so please disregard if this is too early to send errors. I just ran the unit tests from within msys2 and the conversion to utf16 failed (should just return aap):
string_bytes(S, [0, 97, 0, 97, 0, 112], utf16be).
S = "aap\u0000瓩퍧".
?- string_bytes(S, [97, 0, 97, 0, 112, 0], utf16le).
S = "aap戀瑹獥".
The problem is also seen in the “daily build for Windows, 64 bit” from the swi-prolog homepage.
I tried to track it a bit down, in pl-string.c, line 247 etc.
if ( PL_get_nchars(A2, &len, &s, CVT_LIST|REP_ISO_LATIN_1|CVT_EXCEPTION) )
{ if ( len % unit_length(enc) != 0 )
return PL_syntax_error("incomplete_multibyte_sequence", NULL);
t.text.t = s;
t.length = len/unit_length(enc);
t.encoding = enc;
t.canonical = FALSE;
t.storage = PL_CHARS_HEAP;
// printf("len=%ld, unitlength=%d\n", len, unit_length(enc)) ; % Linux
printf("len=%lld, unitlength=%d\n", len, unit_length(enc)) ; % Windows
return PL_unify_text(A1, 0, &t, PL_STRING);
}
Len is 6, unitlength is 1 under both Linux and Windows.