Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #45 from kc3hack/feat/#17-3
Browse files Browse the repository at this point in the history
SplitBraceの修正、whiteSpace文の挿入阻止
  • Loading branch information
aiueo-1234 authored Feb 24, 2024
2 parents 20eb8cf + 59325b4 commit 6396cb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Epub/KoeBook.Epub/ScrapingAozora.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public async Task<EpubDocument> ScrapingAsync(string url, string coverFilePath,
{
if (nextNode.NodeType == NodeType.Text)
{
if (nextNode.Text() != "\n")
if (!string.IsNullOrWhiteSpace(nextNode.Text()))
{
previous = true;

Expand Down Expand Up @@ -522,7 +522,7 @@ private static string TextProcess(IElement element)
{
if (node.NodeType == NodeType.Text)
{
if (node.Text() != "\n")
if (!string.IsNullOrWhiteSpace(node.Text()))
{
text += TextReplace(node.Text());
}
Expand All @@ -546,14 +546,14 @@ private static string TextProcess(IElement element)
}
else
{
if ((item.TextContent != "\n") && (!string.IsNullOrEmpty(item.TextContent)))
if (!string.IsNullOrWhiteSpace(item.TextContent) && (!string.IsNullOrEmpty(item.TextContent)))
{
text += TextReplace(item.TextContent);
}
}
if (item.NextSibling != null)
{
if ((item.NextSibling.TextContent != "\n") && (!string.IsNullOrEmpty(item.NextSibling.TextContent)))
if (!string.IsNullOrWhiteSpace(item.NextSibling.TextContent) && (!string.IsNullOrEmpty(item.NextSibling.TextContent)))
{
text += TextReplace(item.NextSibling.Text());
}
Expand Down
14 changes: 11 additions & 3 deletions Epub/KoeBook.Epub/ScrapingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace KoeBook.Epub;

internal static class ScrapingHelper
public static class ScrapingHelper
{
internal static void checkChapter(EpubDocument document)
{
Expand Down Expand Up @@ -46,6 +46,10 @@ internal static void checkParagraph(EpubDocument document, int chapterNum, int s

public static List<string> SplitBrace(string text)
{
if (text.Length == 1 && text != "「" && text != "」")
{
return new List<string>() { text };
}
var result = new List<string>();
int bracket = 0;
var brackets = new List<int>();
Expand All @@ -62,19 +66,23 @@ public static List<string> SplitBrace(string text)
brackets[i] -= mn;
if (text[i] == '「' && brackets[i] == 1 && i != 0)
{
result.Add(text[startIdx..(i - startIdx)]);
result.Add(text[startIdx..i]);
startIdx = i;
}
if (text[i] == '」' && brackets[i] == 0 && i != 0)
{
result.Add(text[startIdx..(i - startIdx + 1)]);
result.Add(text[startIdx..(i + 1)]);
startIdx = i + 1;
}
}
if (startIdx != text.Length - 1)
{
result.Add(text[startIdx..]);
}
if (result[^1] == "")
{
result.RemoveAt(result.Count - 1);
}

return result;
}
Expand Down

0 comments on commit 6396cb3

Please sign in to comment.