Skip to content

Commit

Permalink
SplitBraceと ScrapingBase を string のほかに List<string> を引数として使えるよう変更
Browse files Browse the repository at this point in the history
  • Loading branch information
TakenPt committed Mar 15, 2024
1 parent c529ade commit 0eebe90
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Epub/KoeBook.Epub/Models/ScrapingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,30 @@ namespace KoeBook.Epub.Models;

public abstract class ScrapingBase
{
protected StringBuilder stringBuilder = new();
protected List<StringBuilder> stringBuilders = new();

internal void AddText(string text)
{
stringBuilder.Append(text);
stringBuilders[^1].Append(text);
}

internal string GetText()
internal void AddText(List<string> texts)
{
var result = stringBuilder.ToString();
stringBuilder.Clear();
stringBuilders[^1].Append(texts[0]);
for (int i = 1; i < texts.Count; i++)
{
stringBuilders.Add(new StringBuilder(texts[i]));
}
}

internal List<string> GetText()
{
List<string> result = new List<string>();
foreach (StringBuilder stringBuilder in stringBuilders)
{
result.Add(stringBuilder.ToString());
}
stringBuilders.Clear();
return result;
}
}
9 changes: 9 additions & 0 deletions Epub/KoeBook.Epub/Utility/ScrapingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ public static List<string> SplitBrace(string text)
{
result.Add(text[startIdx..]);
}
return result;
}

public static List<string> SplitBrace(List<string> texts)
{
var result = new List<string>();
foreach (var text in texts)
{
result.AddRange(SplitBrace(text));
}
return result;
}
}

0 comments on commit 0eebe90

Please sign in to comment.