From 528dc1b9c536062003265590f6868cfd4d5221ac Mon Sep 17 00:00:00 2001 From: voluntas Date: Sun, 2 Jun 2024 14:47:09 +0900 Subject: [PATCH 1/3] =?UTF-8?q?list=5Fstring=20=E3=81=AB=20lowercase=20?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 7 +++++++ include/kvconf.hrl | 4 +++- src/kvconf_validate.erl | 25 +++++++++++++++---------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6914074..e53ebb0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,13 @@ ## develop +- [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_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. From 077c5b9b3deb02a9185b3edbd10ad47504df7998 Mon Sep 17 00:00:00 2001 From: voluntas Date: Sun, 2 Jun 2024 14:54:00 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=82=92=E4=B8=8A=E3=81=92=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kvconf.app.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, []}, From c9b6c3c9a61208ec40b9e086503f91ee9425a684 Mon Sep 17 00:00:00 2001 From: voluntas Date: Sun, 2 Jun 2024 14:54:28 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A4=89=E6=9B=B4=E5=B1=A5=E6=AD=B4?= =?UTF-8?q?=E3=82=92=E6=9B=B4=E6=96=B0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index e53ebb0..f30ab5c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,8 @@ ## develop +## 2024.2.0 + - [ADD] `#kvc_list_string{}` に lowercase を追加する - true にすると lowercase で返す