Skip to content

Commit deafb32

Browse files
authored
Merge pull request #69 from esl/modernise
Modernise
2 parents 74263a9 + 3df87ca commit deafb32

File tree

9 files changed

+133
-138
lines changed

9 files changed

+133
-138
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,33 @@ on:
99

1010
jobs:
1111
test:
12-
name: OTP ${{matrix.otp}}
12+
name: OTP ${{matrix.otp_vsn}}
1313
strategy:
1414
matrix:
15-
otp: ['25.0', '24.3', '23.3', '22.3', '21.3']
16-
runs-on: 'ubuntu-20.04'
15+
otp_vsn: ['26.2', '25.3', '24.3']
16+
rebar_vsn: ['3.22.0']
17+
runs-on: 'ubuntu-22.04'
1718
env:
1819
OTPVER: ${{ matrix.otp }}
1920
steps:
20-
- uses: actions/checkout@v2
21-
- uses: ErlGang/setup-erlang@v1.0.0
21+
- uses: actions/checkout@v4
22+
- uses: erlef/setup-beam@v1
2223
with:
23-
otp-version: ${{ matrix.otp }}
24-
- run: make rebar3
25-
- run: make deps
26-
- run: make test
27-
- run: make dialyzer
28-
if: ${{ matrix.otp == '25.0' }}
29-
- run: make codecov
30-
if: ${{ matrix.otp == '25.0' }}
31-
- run: make gcov
32-
if: ${{ matrix.otp == '25.0' }}
33-
- run: pip install --user codecov
34-
if: ${{ matrix.otp == '25.0' }}
35-
- run: /home/runner/.local/bin/codecov
36-
if: ${{ matrix.otp == '25.0' }}
24+
otp-version: ${{ matrix.otp_vsn }}
25+
rebar3-version: ${{ matrix.rebar_vsn }}
26+
- uses: actions/cache@v3
27+
name: Cache
28+
with:
29+
path: _build
30+
key: ${{ runner.os }}-build-${{ matrix.otp_vsn }}-${{ hashFiles(format('rebar.lock')) }}-1
31+
restore-keys: ${{ runner.os }}-build-${{ matrix.otp_vsn }}-1-
32+
- run: rebar3 as test compile -d
33+
- run: rebar3 eunit
34+
- run: rebar3 dialyzer
35+
- run: rebar3 as test codecov analyze
36+
- run: gcov -o c_src exml
37+
- uses: codecov/codecov-action@v3
38+
with:
39+
name: Upload coverage reports to Codecov
40+
token: ${{ secrets.CODECOV_TOKEN }}
41+
fail_ci_if_error: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ _build/
1212
*.beam
1313
*.lock
1414
/rebar3
15+
doc/

Makefile

Lines changed: 0 additions & 45 deletions
This file was deleted.

rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{proper, "1.4.0"}
1515
]},
1616
{plugins, [
17-
{rebar3_codecov, "0.3.0"}
17+
{rebar3_codecov, "0.6.0"}
1818
]},
1919
{port_env, [
2020
{"CXXFLAGS", "$CXXFLAGS -O3 -std=c++11 -g -Wall -Wextra -fPIC --coverage"},

src/exml.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{modules, []},
1111
{maintainers, ["ESL"]},
1212
{pkg_name, "hexml"},
13-
{licenses, ["Apache 2.0", "Boost Software License 1.0 (C++ code)", "GPL (tests)"]},
13+
{licenses, ["Apache-2.0", "BSL-1.0", "GPL (tests)"]},
1414
{links, [{"GitHub", "https://github.com/esl/exml/"}]},
1515
{exclude_files, ["c_src/exml.d"]}
1616
]}.

src/exml.erl

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%%%-------------------------------------------------------------------
2-
%%% @copyright (C) 2011-2021, Erlang Solutions Ltd.
2+
%%% @copyright (C) 2011-2024, Erlang Solutions Ltd.
33
%%% @doc
44
%%% @end
55
%%% Created : 12 Jul 2011 by Michal Ptaszek <michal.ptaszek@erlang-solutions.com>
@@ -31,6 +31,7 @@
3131
-type item() :: element() | attr() | cdata() | exml_stream:start() | exml_stream:stop().
3232
-type prettify() :: pretty | not_pretty.
3333

34+
%% @doc Calculate the length of the original XML payload
3435
-spec xml_size(item() | [item()]) -> non_neg_integer().
3536
xml_size([]) ->
3637
0;
@@ -54,14 +55,15 @@ xml_size({Key, Value}) ->
5455
+ 4 % ="" and whitespace before
5556
+ byte_size(Value).
5657

57-
%% @doc Sort a (list of) `xmlel()'.
58+
%% @doc Sort in ascending order a list of xml `t:item()'.
5859
%%
5960
%% Sorting is defined as calling `lists:sort/1' at:
60-
%% * all the `xmlel's provided (if there is a list of them) AND
61-
%% * all the `xmlel' elements' attributes recursively (the root and descendants) AND
62-
%% * all the `xmlel' children recursively (the root and descendants).
63-
%% The order is ascending.
64-
%%
61+
%% <ul>
62+
%% <li>all the `xmlel's provided (if there is a list of them) AND</li>
63+
%% <li>all the `xmlel' elements' attributes recursively (the root and descendants) AND</li>
64+
%% <li>all the `xmlel' children recursively (the root and descendants).</li>
65+
%% </ul>
66+
%% @end
6567
%% The implementation of this function is a subtle modification of
6668
%% https://github.com/erszcz/rxml/commit/e8483408663f0bc2af7896e786c1cdea2e86e43d
6769
-spec xml_sort(item() | [item()]) -> item() | [item()].
@@ -99,31 +101,19 @@ to_iolist(Element) ->
99101
to_pretty_iolist(Element) ->
100102
to_iolist(Element, pretty).
101103

104+
%% @doc Parses a binary or a list of binaries into an XML `t:element()'.
102105
-spec parse(binary() | [binary()]) -> {ok, exml:element()} | {error, any()}.
103106
parse(XML) ->
104107
exml_nif:parse(XML).
105108

106-
%% @doc Turn a –list of– exml element into iodata for IO interactions.
109+
%% @doc Turn a –list of– exml elements into iodata for IO interactions.
107110
%%
108111
%% The `Pretty' argument indicates if the generated XML should have new lines and indentation,
109112
%% which is useful for the debugging eye, or should rather be a minified version,
110-
%% which is better for IO.
111-
-spec to_iolist(exml_stream:element() | [exml_stream:element()], prettify()) -> iodata().
113+
%% which is better for IO performance.
114+
-spec to_iolist(cdata() | exml_stream:element() | [exml_stream:element()], prettify()) -> iodata().
112115
to_iolist(#xmlel{} = Element, Pretty) ->
113116
to_binary_nif(Element, Pretty);
114-
to_iolist([Element], Pretty) ->
115-
to_iolist(Element, Pretty);
116-
to_iolist([Head | _] = Elements, Pretty) ->
117-
[Last | RevChildren] = lists:reverse(tl(Elements)),
118-
case {Head, Last} of
119-
{#xmlstreamstart{name = Name, attrs = Attrs},
120-
#xmlstreamend{name = Name}} ->
121-
Element = #xmlel{name = Name, attrs = Attrs,
122-
children = lists:reverse(RevChildren)},
123-
to_binary_nif(Element, Pretty);
124-
_ ->
125-
[to_iolist(El, Pretty) || El <- Elements]
126-
end;
127117
to_iolist(#xmlstreamstart{name = Name, attrs = Attrs}, _Pretty) ->
128118
Result = to_binary_nif(#xmlel{name = Name, attrs = Attrs}, not_pretty),
129119
FrontSize = byte_size(Result) - 2,
@@ -132,7 +122,21 @@ to_iolist(#xmlstreamstart{name = Name, attrs = Attrs}, _Pretty) ->
132122
to_iolist(#xmlstreamend{name = Name}, _Pretty) ->
133123
[<<"</">>, Name, <<">">>];
134124
to_iolist(#xmlcdata{content = Content}, _Pretty) ->
135-
exml_nif:escape_cdata(Content).
125+
exml_nif:escape_cdata(Content);
126+
to_iolist([Element], Pretty) ->
127+
to_iolist(Element, Pretty);
128+
to_iolist([#xmlstreamstart{name = Name, attrs = Attrs} | Tail] = Elements, Pretty) ->
129+
[Last | RevChildren] = lists:reverse(Tail),
130+
case Last of
131+
#xmlstreamend{name = Name} ->
132+
%% Add extra nesting for streams so pretty-printing would be indented properly
133+
Element = #xmlel{name = Name, attrs = Attrs, children = lists:reverse(RevChildren)},
134+
to_binary_nif(Element, Pretty);
135+
_ ->
136+
[to_iolist(El, Pretty) || El <- Elements]
137+
end;
138+
to_iolist(Elements, Pretty) when is_list(Elements) ->
139+
[to_iolist(El, Pretty) || El <- Elements].
136140

137141
-spec to_binary_nif(element(), prettify()) -> binary().
138142
to_binary_nif(#xmlel{} = Element, Pretty) ->

src/exml_nif.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%%%-------------------------------------------------------------------
2-
%%% @copyright (C) 2018-2022, Erlang Solutions Ltd.
2+
%%% @copyright (C) 2018-2024, Erlang Solutions Ltd.
33
%%% @private
44
%%%-------------------------------------------------------------------
55

0 commit comments

Comments
 (0)