Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#4 #10

Merged
merged 10 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions Epub/KoeBook.Epub/Utility/ScrapingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class ScrapingHelper
{
public static List<string> SplitBrace(string text)
{
if (text.Length == 1 && text != "「" && text != "」")
if (text.Length == 1 && (text == "「" || text == "」"))
return [text];

var bracket = 0;
Expand All @@ -23,25 +23,21 @@ public static List<string> 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)
if (startIdx != text.Length)
{
result.Add(text[startIdx..]);
}
if (result[^1] == "")
{
result.RemoveAt(result.Count - 1);
}

return result;
}
Expand Down
44 changes: 44 additions & 0 deletions KoeBook.Test/Epub/ScrapingHelperTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using KoeBook.Epub.Utility;

namespace KoeBook.Test.Epub;

public class ScrapingHelperTest
{
public static object[][] TestCases()
{
(string, List<string>)[] 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「abc", ["abc", "「abc「abc"]),
("abc」abc」abc", ["abc」abc」", "abc"])
];
return cases.Select(c => new object[] { c.Item1, c.Item2 }).ToArray();
}

[Theory]
[MemberData(nameof(TestCases))]
public void SplitBraceTest(string text, List<string> expected)
{
Assert.Equal(expected, ScrapingHelper.SplitBrace(text));

}
}
10 changes: 0 additions & 10 deletions KoeBook.Test/UnitTest1.cs

This file was deleted.

Loading