Skip to content

Commit affd5b1

Browse files
authored
Merge pull request #13 from samcamwilliams/twilson63/repair-merge-with-ar_utils
fix(ar_util): fix a duplicate code issue as a result of a merge
2 parents fb414a7 + b2c1fa5 commit affd5b1

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

src/ar_util.erl

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,69 @@
11
-module(ar_util).
2-
-export([id/1, encode/1, decode/1, safe_encode/1, safe_decode/1, find_value/2, find_value/3]).
2+
3+
-export([id/1, encode/1, decode/1, safe_encode/1, safe_decode/1, find_value/2,
4+
find_value/3]).
35
-export([remove_common/2]).
4-
-include("include/ao.hrl").
56

6-
%% @doc Encode an ID in any format to a normalized, b64u 43 character binary.
7-
id(Bin) when is_binary(Bin) andalso byte_size(Bin) == 43 ->
8-
Bin;
9-
id(Bin) when is_binary(Bin) andalso byte_size(Bin) == 32 ->
10-
b64fast:encode(Bin);
11-
id(Data) when is_list(Data) ->
12-
id(list_to_binary(Data)).
7+
-include("include/ao.hrl").
138

149
%% @doc Encode an ID in any format to a normalized, b64u 43 character binary.
1510
id(Bin) when is_binary(Bin) andalso byte_size(Bin) == 43 ->
16-
Bin;
11+
Bin;
1712
id(Bin) when is_binary(Bin) andalso byte_size(Bin) == 32 ->
18-
b64fast:encode(Bin);
13+
b64fast:encode(Bin);
1914
id(Data) when is_list(Data) ->
20-
id(list_to_binary(Data)).
15+
id(list_to_binary(Data)).
2116

2217
%% @doc Encode a binary to URL safe base64 binary string.
2318
encode(Bin) ->
24-
b64fast:encode(Bin).
19+
b64fast:encode(Bin).
2520

2621
%% @doc Try to decode a URL safe base64 into a binary or throw an error when
2722
%% invalid.
2823
decode(Input) ->
29-
b64fast:decode(Input).
24+
b64fast:decode(Input).
3025

3126
safe_encode(Bin) when is_binary(Bin) ->
32-
encode(Bin);
27+
encode(Bin);
3328
safe_encode(Bin) ->
34-
Bin.
29+
Bin.
3530

3631
%% @doc Safely decode a URL safe base64 into a binary returning an ok or error
3732
%% tuple.
3833
safe_decode(E) ->
39-
try
40-
D = decode(E),
41-
{ok, D}
42-
catch
43-
_:_ ->
44-
{error, invalid}
45-
end.
34+
try
35+
D = decode(E),
36+
{ok, D}
37+
catch
38+
_:_ ->
39+
{error, invalid}
40+
end.
4641

4742
%% @doc Find the value associated with a key in parsed a JSON structure list.
4843
find_value(Key, List) ->
49-
ar_util:find_value(Key, List, undefined).
44+
ar_util:find_value(Key, List, undefined).
45+
5046
find_value(Key, Map, Default) when is_map(Map) ->
51-
case maps:find(Key, Map) of
52-
{ok, Value} -> Value;
53-
error -> Default
54-
end;
47+
case maps:find(Key, Map) of
48+
{ok, Value} ->
49+
Value;
50+
error ->
51+
Default
52+
end;
5553
find_value(Key, List, Default) ->
56-
case lists:keyfind(Key, 1, List) of
57-
{Key, Val} -> Val;
58-
false -> Default
59-
end.
54+
case lists:keyfind(Key, 1, List) of
55+
{Key, Val} ->
56+
Val;
57+
false ->
58+
Default
59+
end.
6060

61-
remove_common(<< X:8, Rest1/binary>>, << X:8, Rest2/binary>>) ->
62-
?c({common_prefix, X}),
63-
remove_common(Rest1, Rest2);
64-
remove_common([X|Rest1], [X|Rest2]) ->
65-
remove_common(Rest1, Rest2);
66-
remove_common([$/|Path], _) -> Path;
67-
remove_common(Rest, _) -> Rest.
61+
remove_common(<<X:8, Rest1/binary>>, <<X:8, Rest2/binary>>) ->
62+
?c({common_prefix, X}),
63+
remove_common(Rest1, Rest2);
64+
remove_common([X | Rest1], [X | Rest2]) ->
65+
remove_common(Rest1, Rest2);
66+
remove_common([$/ | Path], _) ->
67+
Path;
68+
remove_common(Rest, _) ->
69+
Rest.

0 commit comments

Comments
 (0)