Skip to content

Commit

Permalink
BERT 2.0 Proposal: New complex type - {bert, string, Encoding, Binary} (
Browse files Browse the repository at this point in the history
  • Loading branch information
stleon authored Dec 2, 2018
1 parent e5ac243 commit 0762054
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/bert.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ encode_term(Term) ->
TList = tuple_to_list(Tuple),
TList2 = lists:map((fun encode_term/1), TList),
list_to_tuple(TList2);
{bert, string, String} when is_list(String) ->
%% Unicode list to binary utf8
Bin = unicode:characters_to_binary(String, utf8),
{bert, string, Bin};
_Else -> Term
end.

Expand All @@ -57,6 +61,8 @@ decode_term(Term) ->
{bert, false} -> false;
{bert, dict, Dict} ->
dict:from_list(Dict);
{bert, string, L} when is_list(L) ->
L;
{bert, Other} ->
{bert, Other};
List when is_list(Term) ->
Expand All @@ -66,4 +72,4 @@ decode_term(Term) ->
TList2 = lists:map((fun decode_term/1), TList),
list_to_tuple(TList2);
_Else -> Term
end.
end.

0 comments on commit 0762054

Please sign in to comment.