Skip to content

Commit

Permalink
Merge branch 'release/2024.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Jun 2, 2024
2 parents 9793777 + c9b6c3c commit f44d17f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@

## develop

## 2024.2.0

- [ADD] `#kvc_list_string{}` に lowercase を追加する

- true にすると lowercase で返す
- @voluntas

## 2024.1.0

- [ADD] `,` 区切りの文字列リストを読み込める `#kvc_list_string{}` を追加
- @voluntas
- [UPDATE] rebar3 を 3.23.0 に上げる
Expand Down
4 changes: 3 additions & 1 deletion include/kvconf.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

-record(kvc_string, {}).

-record(kvc_list_string, {}).
-record(kvc_list_string, {
lowercase = false :: boolean()
}).

-record(kvc_integer, {
min :: integer(),
Expand Down
2 changes: 1 addition & 1 deletion src/kvconf.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, kvconf,
[{description, "kvconf"},
{vsn, "2024.1.0"},
{vsn, "2024.2.0"},
{registered, []},
{applications, [kernel, stdlib]},
{env, []},
Expand Down
25 changes: 15 additions & 10 deletions src/kvconf_validate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ validate_type(#kvc_list_atom{}, Value) ->
validate_list_atom(Value);
validate_type(#kvc_string{}, Value) ->
validate_string(Value);
validate_type(#kvc_list_string{}, Value) ->
validate_list_string(Value);
validate_type(#kvc_list_string{lowercase = Lowercase}, Value) ->
validate_list_string(Value, Lowercase);
validate_type(#kvc_integer{min = Min, max = Max}, Value) ->
validate_integer(Value, Min, Max);
validate_type(#kvc_float{min = Min, max = Max}, Value) ->
Expand Down Expand Up @@ -291,14 +291,16 @@ validate_string(_Value) ->
invalid_value.


validate_list_string(Value) when is_binary(Value) ->
validate_list_string(Value, true) when is_binary(Value) ->
validate_list_string(list_to_binary(string:to_lower(binary_to_list(Value))), false);
validate_list_string(Value, false) when is_binary(Value) ->
case binary:split(Value, [<<",">>, <<$\s>>], [trim_all, global]) of
[] ->
{ok, []};
Values ->
{ok, Values}
end;
validate_list_string(_Values) ->
validate_list_string(_Values, _Lowercase) ->
invalid_value.


Expand Down Expand Up @@ -627,18 +629,21 @@ validate_one_test() ->

validate_list_string_test() ->
?assertEqual({ok, [~"x-abc-efg", ~"x-y-z"]},
validate_list_string(~"x-abc-efg, x-y-z")),
validate_list_string(~"X-ABC-EFG, X-Y-Z", true)),

?assertEqual({ok, [~"x-abc-efg", ~"x-y-z"]},
validate_list_string(~"x-abc-efg, x-y-z", false)),
?assertEqual({ok, []},
validate_list_string(~",,,")),
validate_list_string(~",,,", false)),
?assertEqual({ok, []},
validate_list_string(~"")),
validate_list_string(~"", false)),
?assertEqual({ok, [~"a", ~"b"]},
validate_list_string(~"a, , , b")),
validate_list_string(~"a, , , b", false)),
?assertEqual({ok, [~"a", ~"b"]},
validate_list_string(~" a, , , b ")),
validate_list_string(~" a, , , b ", false)),

?assertEqual(invalid_value,
validate_list_string(1)),
validate_list_string(1, false)),

ok.

Expand Down

0 comments on commit f44d17f

Please sign in to comment.