diff --git a/CHANGES.md b/CHANGES.md index 6914074..f30ab5c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 に上げる diff --git a/include/kvconf.hrl b/include/kvconf.hrl index a46280a..02b3422 100644 --- a/include/kvconf.hrl +++ b/include/kvconf.hrl @@ -8,7 +8,9 @@ -record(kvc_string, {}). --record(kvc_list_string, {}). +-record(kvc_list_string, { + lowercase = false :: boolean() + }). -record(kvc_integer, { min :: integer(), diff --git a/src/kvconf.app.src b/src/kvconf.app.src index 975930c..25b3bd0 100644 --- a/src/kvconf.app.src +++ b/src/kvconf.app.src @@ -1,6 +1,6 @@ {application, kvconf, [{description, "kvconf"}, - {vsn, "2024.1.0"}, + {vsn, "2024.2.0"}, {registered, []}, {applications, [kernel, stdlib]}, {env, []}, diff --git a/src/kvconf_validate.erl b/src/kvconf_validate.erl index 93bfbd6..6b90c4d 100644 --- a/src/kvconf_validate.erl +++ b/src/kvconf_validate.erl @@ -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) -> @@ -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. @@ -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.