Also coerce unicode strings to FATE
This is mainly so that gajudesk can pass text box content to hz as-is, but also allows users to pass utf8 binaries in, if they want to, for some reason.
This commit is contained in:
parent
68a0c3d623
commit
6506fc91bd
18
src/hz.erl
18
src/hz.erl
@ -1850,6 +1850,18 @@ coerce({O, N, string}, Str, Direction) ->
|
||||
end;
|
||||
coerce({_, _, char}, Val, _Direction) when is_integer(Val) ->
|
||||
{ok, Val};
|
||||
coerce({O, N, char}, Str, to_fate) ->
|
||||
Result = unicode:characters_to_list(Str),
|
||||
case Result of
|
||||
{error, _, _} ->
|
||||
single_error({invalid, O, N, Str});
|
||||
{incomplete, _, _} ->
|
||||
single_error({invalid, O, N, Str});
|
||||
[C] ->
|
||||
{ok, C};
|
||||
_ ->
|
||||
single_error({invalid, O, N, Str})
|
||||
end;
|
||||
coerce({O, N, {bytes, [Count]}}, Bytes, _Direction) when is_bitstring(Bytes) ->
|
||||
coerce_bytes(O, N, Count, Bytes);
|
||||
coerce({_, _, bits}, {bits, Num}, from_fate) ->
|
||||
@ -2546,6 +2558,12 @@ coerce_char_test() ->
|
||||
{ok, Type} = annotate_type(char, #{}),
|
||||
try_coerce(Type, $?, $?).
|
||||
|
||||
coerce_unicode_test() ->
|
||||
{ok, Type} = annotate_type(char, #{}),
|
||||
% Latin Small Letter C with cedilla and acute
|
||||
{ok, $ḉ} = coerce(Type, <<"ḉ"/utf8>>, to_fate),
|
||||
ok.
|
||||
|
||||
|
||||
%%% Complex AACI paramter and namespace tests
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user