Browse Source

remove trailing dot from erlang term

Namdak Tonpa 5 years ago
parent
commit
6c10d4a404
3 changed files with 4 additions and 3 deletions
  1. 2 1
      src/rest.erl
  2. 1 1
      src/rest_kvs.erl
  3. 1 1
      src/ts.erl

+ 2 - 1
src/rest.erl

@@ -198,8 +198,9 @@ to_binary(I) when is_integer(I) -> to_binary(integer_to_list(I));
 to_binary(F) when is_float(F) -> float_to_binary(F,[{decimals,9},compact]);
 to_binary(F) when is_float(F) -> float_to_binary(F,[{decimals,9},compact]);
 to_binary(L) when is_list(L) ->  iolist_to_binary(L).
 to_binary(L) when is_list(L) ->  iolist_to_binary(L).
 
 
+parse(String) when is_binary(String) -> parse(binary_to_list(String));
 parse(String) ->
 parse(String) ->
-    {ok,Tokens,_EndLine} = erl_scan:string(String),
+    {ok,Tokens,_EndLine} = erl_scan:string(String ++ "."),
     {ok,AbsForm} = erl_parse:parse_exprs(Tokens),
     {ok,AbsForm} = erl_parse:parse_exprs(Tokens),
     {value,Value,_Bs} = erl_eval:exprs(AbsForm, erl_eval:new_bindings()),
     {value,Value,_Bs} = erl_eval:exprs(AbsForm, erl_eval:new_bindings()),
     Value.
     Value.

+ 1 - 1
src/rest_kvs.erl

@@ -35,7 +35,7 @@ parse_id(Id) ->
   List = binary_to_list(Id),
   List = binary_to_list(Id),
   Parsed = case string:tokens(List,",") of
   Parsed = case string:tokens(List,",") of
      [X] -> Id;
      [X] -> Id;
-       _ -> rest:parse(lists:concat(["{",List,"}."]))
+       _ -> rest:parse(lists:concat(["{",List,"}"]))
   end.
   end.
 
 
 resource_exists(#{bindings := #{resource := Module, id := Id}} = Req, State) ->
 resource_exists(#{bindings := #{resource := Module, id := Id}} = Req, State) ->

+ 1 - 1
src/ts.erl

@@ -2,7 +2,7 @@
 -include_lib("bpe/include/bpe.hrl").
 -include_lib("bpe/include/bpe.hrl").
 -compile(export_all).
 -compile(export_all).
 new() -> {ts,{{0,0,0},{0,0,0}}}.
 new() -> {ts,{{0,0,0},{0,0,0}}}.
-to_json(#ts{time=X}) -> [{<<"time">>,lists:flatten(io_lib:format("~p.",[X]))}].
+to_json(#ts{time=X}) -> [{<<"time">>,iolist_to_binary(lists:flatten(io_lib:format("~p",[X])))}].
 from_json([{<<"time">>,X}],_) -> #ts{time = rest:parse(X) };
 from_json([{<<"time">>,X}],_) -> #ts{time = rest:parse(X) };
 from_json([{time,X}],_) -> #ts{time = rest:parse(X) }.
 from_json([{time,X}],_) -> #ts{time = rest:parse(X) }.