Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support nested list of child elements

  • Loading branch information...
commit cff232a98e83fdd6001429608785281dc43605e1 1 parent a11df1c
@onkel-dirtus onkel-dirtus authored
Showing with 22 additions and 0 deletions.
  1. +22 −0 src/jorge.erl
View
22 src/jorge.erl
@@ -72,9 +72,18 @@ jorge_list([], Acc) ->
lists:reverse(Acc);
jorge_list([undefined | Rest], Acc) ->
jorge_list(Rest, Acc);
+jorge_list([List | Rest], Acc) when is_list(List) ->
+ jorge_nested_list(List, Rest, Acc);
jorge_list([Head | Rest], Acc) ->
jorge_list(Rest, [jorge_node(Head) | Acc]).
+jorge_nested_list([], Siblings, Acc) ->
+ jorge_list(Siblings, Acc);
+jorge_nested_list([undefined | Rest], Siblings, Acc) ->
+ jorge_nested_list(Rest, Siblings, Acc);
+jorge_nested_list([Head | Rest], Siblings, Acc) ->
+ jorge_nested_list(Rest, Siblings, [jorge_node(Head) | Acc]).
+
-ifdef(TEST).
jorge_test() ->
@@ -98,6 +107,19 @@ jorge_test() ->
{spam, fun() -> eggs end}
]}
}
+ ),
+
+ Nested = [<<"<nested>">>,
+ [[<<"<foo>">>, <<"bar">>, <<"</foo>">>],
+ [<<"<abc>">>, <<"123">>, <<"</abc>">>],
+ [<<"<def>">>, <<"456">>, <<"</def>">>]],
+ <<"</nested>">>],
+
+ Nested = jorge(
+ {nested, [
+ {foo, bar},
+ [{abc, 123}, undefined, {def, 456}]
+ ]}
).
-endif.
Please sign in to comment.
Something went wrong with that request. Please try again.