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;
|
end;
|
||||||
coerce({_, _, char}, Val, _Direction) when is_integer(Val) ->
|
coerce({_, _, char}, Val, _Direction) when is_integer(Val) ->
|
||||||
{ok, 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({O, N, {bytes, [Count]}}, Bytes, _Direction) when is_bitstring(Bytes) ->
|
||||||
coerce_bytes(O, N, Count, Bytes);
|
coerce_bytes(O, N, Count, Bytes);
|
||||||
coerce({_, _, bits}, {bits, Num}, from_fate) ->
|
coerce({_, _, bits}, {bits, Num}, from_fate) ->
|
||||||
@ -2546,6 +2558,12 @@ coerce_char_test() ->
|
|||||||
{ok, Type} = annotate_type(char, #{}),
|
{ok, Type} = annotate_type(char, #{}),
|
||||||
try_coerce(Type, $?, $?).
|
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
|
%%% Complex AACI paramter and namespace tests
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user