From ad94645a5004ceae3c9a2396c1c551f681984b9e Mon Sep 17 00:00:00 2001 From: TakenPt Date: Sun, 3 Mar 2024 16:35:09 +0900 Subject: [PATCH 01/10] =?UTF-8?q?SplitBrace=E3=81=AE=E5=85=88=E9=A0=AD(?= =?UTF-8?q?=E5=85=A5=E5=8A=9B=E3=81=8C1=E6=96=87=E5=AD=97=E3=81=AE?= =?UTF-8?q?=E6=99=82)=E3=81=AE=E6=9D=A1=E4=BB=B6=E5=BC=8F=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=80=82=20SplitBrace=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Epub/KoeBook.Epub/Utility/ScrapingHelper.cs | 2 +- KoeBook.Test/UnitTest1.cs | 27 ++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs b/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs index ba8ff41..9838850 100644 --- a/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs +++ b/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs @@ -4,7 +4,7 @@ public static class ScrapingHelper { public static List SplitBrace(string text) { - if (text.Length == 1 && text != "「" && text != "」") + if (text.Length == 1 && (text == "「" || text == "」")) return [text]; var bracket = 0; diff --git a/KoeBook.Test/UnitTest1.cs b/KoeBook.Test/UnitTest1.cs index 217ca16..8342f41 100644 --- a/KoeBook.Test/UnitTest1.cs +++ b/KoeBook.Test/UnitTest1.cs @@ -1,10 +1,31 @@ -namespace KoeBook.Test; +using KoeBook.Epub.Utility; + +namespace KoeBook.Test; public class UnitTest1 { - [Fact] - public void Test1() + public static IEnumerable Data() + { + yield return new object[] { "「", new List { "「" } }; + yield return new object[] { "」", new List { "」" } }; + yield return new object[] { "abc「abc」abc" , new List { "abc", "「abc」", "abc" } }; + yield return new object[] { "abc「abc」", new List { "abc", "「abc」" } }; + yield return new object[] { "「abc」abc", new List { "「abc」", "abc", } }; + yield return new object[] { "abc「abc」", new List { "abc", "「abc」" } }; + yield return new object[] { "「abc」", new List { "「abc」", } }; + yield return new object[] { "abc「abc", new List { "abc", "「abc" } }; + yield return new object[] { "abc「", new List { "abc", "「" } }; + yield return new object[] { "「abc", new List { "「abc" } }; + yield return new object[] { "abc」abc", new List { "abc」", "abc" } }; + yield return new object[] { "abc」", new List { "abc」"} }; + yield return new object[] { "」abc", new List { "」", "abc" } }; + } + + [Theory] + [MemberData(nameof(Data))] + public void SplitBraceTest(string text, List expected) { + Assert.Equal(expected, ScrapingHelper.SplitBrace(text)); } } From dba4de34461d86c4b20665dbd9f9cf45ebd73998 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Sun, 3 Mar 2024 16:38:11 +0900 Subject: [PATCH 02/10] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=88=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook.Test/UnitTest1.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KoeBook.Test/UnitTest1.cs b/KoeBook.Test/UnitTest1.cs index 8342f41..1a4ef89 100644 --- a/KoeBook.Test/UnitTest1.cs +++ b/KoeBook.Test/UnitTest1.cs @@ -8,7 +8,7 @@ public static IEnumerable Data() { yield return new object[] { "「", new List { "「" } }; yield return new object[] { "」", new List { "」" } }; - yield return new object[] { "abc「abc」abc" , new List { "abc", "「abc」", "abc" } }; + yield return new object[] { "abc「abc」abc", new List { "abc", "「abc」", "abc" } }; yield return new object[] { "abc「abc」", new List { "abc", "「abc」" } }; yield return new object[] { "「abc」abc", new List { "「abc」", "abc", } }; yield return new object[] { "abc「abc」", new List { "abc", "「abc」" } }; @@ -17,7 +17,7 @@ public static IEnumerable Data() yield return new object[] { "abc「", new List { "abc", "「" } }; yield return new object[] { "「abc", new List { "「abc" } }; yield return new object[] { "abc」abc", new List { "abc」", "abc" } }; - yield return new object[] { "abc」", new List { "abc」"} }; + yield return new object[] { "abc」", new List { "abc」" } }; yield return new object[] { "」abc", new List { "」", "abc" } }; } From ac4a234695b0b492ae709c027d7bd2f548fa682b Mon Sep 17 00:00:00 2001 From: TakenPt Date: Sun, 3 Mar 2024 17:13:45 +0900 Subject: [PATCH 03/10] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook.Test/{UnitTest1.cs => Epub/ScrapingHelperTest.cs} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename KoeBook.Test/{UnitTest1.cs => Epub/ScrapingHelperTest.cs} (95%) diff --git a/KoeBook.Test/UnitTest1.cs b/KoeBook.Test/Epub/ScrapingHelperTest.cs similarity index 95% rename from KoeBook.Test/UnitTest1.cs rename to KoeBook.Test/Epub/ScrapingHelperTest.cs index 1a4ef89..aa5e7e6 100644 --- a/KoeBook.Test/UnitTest1.cs +++ b/KoeBook.Test/Epub/ScrapingHelperTest.cs @@ -1,8 +1,8 @@ using KoeBook.Epub.Utility; -namespace KoeBook.Test; +namespace KoeBook.Test.Epub; -public class UnitTest1 +public class ScrapingHelperTest { public static IEnumerable Data() { From 58a8b1539ed8e25cade3550f15c5b31766943e7e Mon Sep 17 00:00:00 2001 From: TakenPt Date: Sun, 3 Mar 2024 17:25:24 +0900 Subject: [PATCH 04/10] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook.Test/Epub/ScrapingHelperTest.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/KoeBook.Test/Epub/ScrapingHelperTest.cs b/KoeBook.Test/Epub/ScrapingHelperTest.cs index aa5e7e6..6c3a5ec 100644 --- a/KoeBook.Test/Epub/ScrapingHelperTest.cs +++ b/KoeBook.Test/Epub/ScrapingHelperTest.cs @@ -8,6 +8,7 @@ public static IEnumerable Data() { yield return new object[] { "「", new List { "「" } }; yield return new object[] { "」", new List { "」" } }; + yield return new object[] { "a", new List { "a" } }; yield return new object[] { "abc「abc」abc", new List { "abc", "「abc」", "abc" } }; yield return new object[] { "abc「abc」", new List { "abc", "「abc」" } }; yield return new object[] { "「abc」abc", new List { "「abc」", "abc", } }; @@ -19,6 +20,10 @@ public static IEnumerable Data() yield return new object[] { "abc」abc", new List { "abc」", "abc" } }; yield return new object[] { "abc」", new List { "abc」" } }; yield return new object[] { "」abc", new List { "」", "abc" } }; + yield return new object[] { "abc「abc」abc「abc」abc", new List { "abc", "「abc」", "abc", "「abc」", "abc" } }; + yield return new object[] { "「abc」abc「abc」abc", new List { "「abc」", "abc", "「abc」", "abc" } }; + yield return new object[] { "abc「abc」「abc」abc", new List { "abc", "「abc」", "「abc」", "abc" } }; + yield return new object[] { "abc「abc」abc「abc」", new List { "abc", "「abc」", "abc", "「abc」" } }; } [Theory] From 9a717b9e24a4916ab2e5b09ee5abb3ba27231a79 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Sun, 3 Mar 2024 17:30:39 +0900 Subject: [PATCH 05/10] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook.Test/Epub/ScrapingHelperTest.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/KoeBook.Test/Epub/ScrapingHelperTest.cs b/KoeBook.Test/Epub/ScrapingHelperTest.cs index 6c3a5ec..d13cfef 100644 --- a/KoeBook.Test/Epub/ScrapingHelperTest.cs +++ b/KoeBook.Test/Epub/ScrapingHelperTest.cs @@ -24,6 +24,10 @@ public static IEnumerable Data() yield return new object[] { "「abc」abc「abc」abc", new List { "「abc」", "abc", "「abc」", "abc" } }; yield return new object[] { "abc「abc」「abc」abc", new List { "abc", "「abc」", "「abc」", "abc" } }; yield return new object[] { "abc「abc」abc「abc」", new List { "abc", "「abc」", "abc", "「abc」" } }; + yield return new object[] { "abc「abc「abc」abc", new List { "abc", "「abc「abc」abc" } }; + yield return new object[] { "abc「abc」abc」abc", new List { "abc「abc」abc」", "abc" } }; + yield return new object[] { "abc「abc「abc", new List { "abc", "「abc「abc" } }; + yield return new object[] { "abc」abc」abc", new List { "abc」abc」", "abc" } }; } [Theory] From 680a90592d953c468a8966062e18173e2b28e05c Mon Sep 17 00:00:00 2001 From: TakenPt Date: Sun, 3 Mar 2024 18:14:15 +0900 Subject: [PATCH 06/10] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook.Test/Epub/ScrapingHelperTest.cs | 51 +++++++++++++------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/KoeBook.Test/Epub/ScrapingHelperTest.cs b/KoeBook.Test/Epub/ScrapingHelperTest.cs index d13cfef..54e41b5 100644 --- a/KoeBook.Test/Epub/ScrapingHelperTest.cs +++ b/KoeBook.Test/Epub/ScrapingHelperTest.cs @@ -4,34 +4,37 @@ namespace KoeBook.Test.Epub; public class ScrapingHelperTest { - public static IEnumerable Data() + public static object[][] TestCases() { - yield return new object[] { "「", new List { "「" } }; - yield return new object[] { "」", new List { "」" } }; - yield return new object[] { "a", new List { "a" } }; - yield return new object[] { "abc「abc」abc", new List { "abc", "「abc」", "abc" } }; - yield return new object[] { "abc「abc」", new List { "abc", "「abc」" } }; - yield return new object[] { "「abc」abc", new List { "「abc」", "abc", } }; - yield return new object[] { "abc「abc」", new List { "abc", "「abc」" } }; - yield return new object[] { "「abc」", new List { "「abc」", } }; - yield return new object[] { "abc「abc", new List { "abc", "「abc" } }; - yield return new object[] { "abc「", new List { "abc", "「" } }; - yield return new object[] { "「abc", new List { "「abc" } }; - yield return new object[] { "abc」abc", new List { "abc」", "abc" } }; - yield return new object[] { "abc」", new List { "abc」" } }; - yield return new object[] { "」abc", new List { "」", "abc" } }; - yield return new object[] { "abc「abc」abc「abc」abc", new List { "abc", "「abc」", "abc", "「abc」", "abc" } }; - yield return new object[] { "「abc」abc「abc」abc", new List { "「abc」", "abc", "「abc」", "abc" } }; - yield return new object[] { "abc「abc」「abc」abc", new List { "abc", "「abc」", "「abc」", "abc" } }; - yield return new object[] { "abc「abc」abc「abc」", new List { "abc", "「abc」", "abc", "「abc」" } }; - yield return new object[] { "abc「abc「abc」abc", new List { "abc", "「abc「abc」abc" } }; - yield return new object[] { "abc「abc」abc」abc", new List { "abc「abc」abc」", "abc" } }; - yield return new object[] { "abc「abc「abc", new List { "abc", "「abc「abc" } }; - yield return new object[] { "abc」abc」abc", new List { "abc」abc」", "abc" } }; + (string, List)[] cases = [ + ("「", ["「"]), + ("」", ["」"]), + ("a", ["a"]), + ("abc「abc」abc", ["abc", "「abc」", "abc"]), + ("abc「abc」", ["abc", "「abc」"]), + ("「abc」abc", ["「abc」", "abc",]), + ("abc「abc」", ["abc", "「abc」"]), + ("「abc」", ["「abc」",]), + ("abc「abc", ["abc", "「abc"]), + ("abc「", ["abc", "「"]), + ("「abc", ["「abc"]), + ("abc」abc", ["abc」", "abc"]), + ("abc」", ["abc」"]), + ("」abc", ["」", "abc"]), + ("abc「abc」abc「abc」abc", ["abc", "「abc」", "abc", "「abc」", "abc"]), + ("「abc」abc「abc」abc", ["「abc」", "abc", "「abc」", "abc"]), + ("abc「abc」「abc」abc", ["abc", "「abc」", "「abc」", "abc"]), + ("abc「abc」abc「abc」", ["abc", "「abc」", "abc", "「abc」"]), + ("abc「abc「abc」abc", ["abc", "「abc「abc」abc"]), + ("abc「abc」abc」abc", ["abc「abc」abc」", "abc"]), + ("abc「abc「abc", ["abc", "「abc「abc"]), + ("abc」abc」abc", ["abc」abc」", "abc"]) + ]; + return cases.Select(c => new object[] { c.Item1, c.Item2 }).ToArray(); } [Theory] - [MemberData(nameof(Data))] + [MemberData(nameof(TestCases))] public void SplitBraceTest(string text, List expected) { Assert.Equal(expected, ScrapingHelper.SplitBrace(text)); From c41e4af389db0a6f33f3f33baebafc47ffc47e55 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Sun, 3 Mar 2024 18:19:55 +0900 Subject: [PATCH 07/10] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B1?= =?UTF-8?q?=E3=83=BC=E3=82=B9=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook.Test/Epub/ScrapingHelperTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/KoeBook.Test/Epub/ScrapingHelperTest.cs b/KoeBook.Test/Epub/ScrapingHelperTest.cs index 54e41b5..394315e 100644 --- a/KoeBook.Test/Epub/ScrapingHelperTest.cs +++ b/KoeBook.Test/Epub/ScrapingHelperTest.cs @@ -25,6 +25,7 @@ public static object[][] TestCases() ("「abc」abc「abc」abc", ["「abc」", "abc", "「abc」", "abc"]), ("abc「abc」「abc」abc", ["abc", "「abc」", "「abc」", "abc"]), ("abc「abc」abc「abc」", ["abc", "「abc」", "abc", "「abc」"]), + ("abc「abc「abc」abc」abc", ["abc", "「abc「abc」abc」", "abc"]), ("abc「abc「abc」abc", ["abc", "「abc「abc」abc"]), ("abc「abc」abc」abc", ["abc「abc」abc」", "abc"]), ("abc「abc「abc", ["abc", "「abc「abc"]), From 73f9424f95454f6616eca029495c5bfb131e52a3 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Sun, 3 Mar 2024 18:27:19 +0900 Subject: [PATCH 08/10] =?UTF-8?q?ScrapingHelper=E3=81=AE=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E5=BC=8F=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Epub/KoeBook.Epub/Utility/ScrapingHelper.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs b/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs index 9838850..f988e9c 100644 --- a/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs +++ b/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs @@ -23,21 +23,18 @@ public static List SplitBrace(string text) for (var i = 0; i < brackets.Length; i++) { brackets[i] -= mn; - if (text[i] == '「' && brackets[i] == 1 && i != 0) + if (text[i] == '「' && brackets[i] == 1 && i != 0 && startIdx != i) { result.Add(text[startIdx..i]); startIdx = i; } - if (text[i] == '」' && brackets[i] == 0 && i != 0) + if (text[i] == '」' && brackets[i] == 0) { result.Add(text[startIdx..(i + 1)]); startIdx = i + 1; } } - if (startIdx != text.Length - 1) - { - result.Add(text[startIdx..]); - } + result.Add(text[startIdx..]); if (result[^1] == "") { result.RemoveAt(result.Count - 1); From 326914a4d8e21f3375f7bfc581ae45cda495038c Mon Sep 17 00:00:00 2001 From: TakenPt Date: Sun, 3 Mar 2024 19:31:02 +0900 Subject: [PATCH 09/10] =?UTF-8?q?SplitBrace=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Epub/KoeBook.Epub/Utility/ScrapingHelper.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs b/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs index f988e9c..e70067c 100644 --- a/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs +++ b/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs @@ -34,10 +34,9 @@ public static List SplitBrace(string text) startIdx = i + 1; } } - result.Add(text[startIdx..]); - if (result[^1] == "") + if (startIdx != brackets.Length) { - result.RemoveAt(result.Count - 1); + result.Add(text[startIdx..]); } return result; From 1307ed91a48ba55fba59282a1336ad27f7f12d56 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Sun, 3 Mar 2024 19:37:42 +0900 Subject: [PATCH 10/10] =?UTF-8?q?brackets.Length=20=E3=82=92=20text.Length?= =?UTF-8?q?=20=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Epub/KoeBook.Epub/Utility/ScrapingHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs b/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs index e70067c..7b7a337 100644 --- a/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs +++ b/Epub/KoeBook.Epub/Utility/ScrapingHelper.cs @@ -34,7 +34,7 @@ public static List SplitBrace(string text) startIdx = i + 1; } } - if (startIdx != brackets.Length) + if (startIdx != text.Length) { result.Add(text[startIdx..]); }