Capitalise first char of line

This commit is contained in:
Andrew Cooper
2022-10-05 07:45:50 +11:00
parent d8dd694ea4
commit 257ba1ab17
3 changed files with 16 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ internal class Context
private bool _skipComma;
private int _lineCount;
private bool _useGroup2;
private bool _atStartOfLine = true;
public Context(IReadWrite io, IRandom random)
{
@@ -34,6 +35,7 @@ internal class Context
public void WritePhrase()
{
Phrase.GetPhrase(this).Write(_io, this);
_atStartOfLine = false;
}
public void MaybeWriteComma()
@@ -55,7 +57,7 @@ internal class Context
}
else
{
_io.WriteLine();
EndLine();
PhraseCount = 0;
}
}
@@ -75,10 +77,10 @@ internal class Context
}
}
public void ResetGroup(IReadWrite io)
public void ResetGroup()
{
_groupNumber = 0;
io.WriteLine();
EndLine();
}
public bool MaybeCompleteStanza()
@@ -94,5 +96,14 @@ internal class Context
return false;
}
internal string MaybeCapitalise(string text) =>
_atStartOfLine ? (char.ToUpper(text[0]) + text[1..]) : text;
public void SkipNextComma() => _skipComma = true;
public void EndLine()
{
_io.WriteLine();
_atStartOfLine = true;
}
}

View File

@@ -70,7 +70,7 @@ internal class Phrase
{
if (_condition.Invoke(context))
{
io.Write(_text);
io.Write(context.MaybeCapitalise(_text));
}
_update.Invoke(context);

View File

@@ -23,7 +23,7 @@ internal class Poem
if (context.GroupNumberIsValid) { break; }
context.ResetGroup(io);
context.ResetGroup();
if (context.MaybeCompleteStanza()) { break; }
}