Skip to content

Commit cfebf7f

Browse files
committed
elli_bstr: cosmetic tweaks
1 parent 61c5be8 commit cfebf7f

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

src/elli_bstr.erl

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
%% Licensed under the Apache License, Version 2.0 (the "License");
1111
%% you may not use this file except in compliance with the License.
1212
%% You may obtain a copy of the License at
13-
%%
13+
%%
1414
%% http://www.apache.org/licenses/LICENSE-2.0
15-
%%
15+
%%
1616
%% Unless required by applicable law or agreed to in writing, software
1717
%% distributed under the License is distributed on an "AS IS" BASIS,
1818
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,17 +22,19 @@
2222
-module(elli_bstr).
2323

2424
-export([
25-
to_lower/1,
26-
is_equal_ci/2,
27-
lchr/1,
25+
to_lower/1,
26+
is_equal_ci/2,
27+
lchr/1,
28+
29+
trim_left/1,
30+
trim_right/1,
31+
trim/1
32+
]).
2833

29-
trim_left/1,
30-
trim_right/1,
31-
trim/1
32-
]).
3334

3435
-define(IS_WS(C), (C =:= $\s orelse C=:=$\t orelse C=:= $\r orelse C =:= $\n)).
3536

37+
3638
%%
3739
%% Types
3840
%%
@@ -44,26 +46,27 @@
4446
%% Functions
4547
%%
4648

47-
% @doc Convert ascii Bin to lowercase
49+
%% @doc Convert ascii Bin to lowercase
4850
-spec to_lower(Bin :: binary()) -> binary().
4951
to_lower(Bin) ->
5052
<< <<(lchr(C))>> || <<C>> <= Bin >>.
5153

5254

53-
% @doc Compare two binary values, return true iff they are equal by a caseless compare.
55+
%% @doc Compare two binary values.
56+
%% Return true iff they are equal by a caseless compare.
5457
-spec is_equal_ci(binary(), binary()) -> boolean().
5558
is_equal_ci(Bin, Bin) ->
56-
% Quick match with an Erlang pattern match
59+
%% Quick match with an Erlang pattern match
5760
true;
5861
is_equal_ci(Bin1, Bin2) when is_binary(Bin1) andalso is_binary(Bin2)
59-
andalso size(Bin1) =:= size(Bin2) ->
60-
% Both binaries are the same length, do a good check
62+
andalso size(Bin1) =:= size(Bin2) ->
63+
%% Both binaries are the same length, do a good check
6164
equal_ci(Bin1, Bin2);
6265
is_equal_ci(_, _) ->
6366
false.
6467

6568

66-
% @doc convert character to lowercase.
69+
%% @doc convert character to lowercase.
6770
-spec lchr(ascii_char()) -> ascii_char().
6871
lchr($A) -> $a;
6972
lchr($B) -> $b;
@@ -93,26 +96,30 @@ lchr($Y) -> $y;
9396
lchr($Z) -> $z;
9497
lchr(Chr) -> Chr.
9598

96-
% @doc Remove leading whitespace from Bin
97-
trim_left(<<C, Rest/binary>>) when ?IS_WS(C) ->
99+
100+
%% @doc Remove leading whitespace from Bin
101+
trim_left(<<C, Rest/binary>>) when ?IS_WS(C) ->
98102
trim_left(Rest);
99103
trim_left(Bin) ->
100104
Bin.
101105

102-
% @doc Remove trailing whitespace from Bin
106+
107+
%% @doc Remove trailing whitespace from Bin
103108
trim_right(<<>>) -> <<>>;
104109
trim_right(Bin) ->
105110
case binary:last(Bin) of
106111
C when ?IS_WS(C) ->
107112
trim_right(binary:part(Bin, {0, size(Bin)-1}));
108-
_ ->
113+
_ ->
109114
Bin
110115
end.
111116

112-
% @doc Remove leading and trailing whitespace.
117+
118+
%% @doc Remove leading and trailing whitespace.
113119
trim(Bin) ->
114120
trim_left(trim_right(Bin)).
115121

122+
116123
%%
117124
%% Helpers
118125
%%
@@ -123,8 +130,8 @@ equal_ci(<<C, Rest1/binary>>, <<C, Rest2/binary>>) ->
123130
equal_ci(Rest1, Rest2);
124131
equal_ci(<<C1, Rest1/binary>>, <<C2, Rest2/binary>>) ->
125132
case lchr(C1) =:= lchr(C2) of
126-
true ->
127-
equal_ci(Rest1, Rest2);
128-
false ->
129-
false
133+
true ->
134+
equal_ci(Rest1, Rest2);
135+
false ->
136+
false
130137
end.

0 commit comments

Comments
 (0)