diff --git a/src/hz.erl b/src/hz.erl index a15c75e..8215779 100644 --- a/src/hz.erl +++ b/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