add text Separator in TextBlock and TextLine

This commit is contained in:
BobLd
2020-05-23 19:39:23 +01:00
committed by Eliot Jones
parent 5f75205e41
commit bb94348127
2 changed files with 20 additions and 4 deletions

View File

@@ -11,6 +11,11 @@
/// </summary>
public class TextBlock
{
/// <summary>
/// The separator used between lines in the block.
/// </summary>
public readonly string Separator;
/// <summary>
/// The text of the block.
/// </summary>
@@ -39,8 +44,9 @@
/// <summary>
/// Create a new <see cref="TextBlock"/>.
/// </summary>
/// <param name="lines"></param>
public TextBlock(IReadOnlyList<TextLine> lines)
/// <param name="lines">The words contained in the line, in the correct order.</param>
/// <param name="separator">The separator used between lines in the block.</param>
public TextBlock(IReadOnlyList<TextLine> lines, string separator = "\n")
{
if (lines == null)
{
@@ -52,6 +58,8 @@
throw new ArgumentException("Empty lines provided.", nameof(lines));
}
Separator = separator;
ReadingOrder = -1;
TextLines = lines;

View File

@@ -11,6 +11,11 @@
/// </summary>
public class TextLine
{
/// <summary>
/// The separator used between words in the line.
/// </summary>
public readonly string Separator;
/// <summary>
/// The text of the line.
/// </summary>
@@ -34,8 +39,9 @@
/// <summary>
/// Create a new <see cref="TextLine"/>.
/// </summary>
/// <param name="words">The words contained in the line.</param>
public TextLine(IReadOnlyList<Word> words)
/// <param name="words">The words contained in the line, in the correct order.</param>
/// <param name="separator">The separator used between words in the line.</param>
public TextLine(IReadOnlyList<Word> words, string separator = " ")
{
if (words == null)
{
@@ -47,6 +53,8 @@
throw new ArgumentException("Empty words provided.", nameof(words));
}
Separator = separator;
Words = words;
Text = string.Join(" ", words.Where(s => !string.IsNullOrWhiteSpace(s.Text)).Select(x => x.Text));