Skip to content

Commit

Permalink
Capitalise first char of line
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-cooper committed Oct 4, 2022
1 parent d8dd694 commit 257ba1a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
17 changes: 14 additions & 3 deletions 70_Poetry/csharp/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -34,6 +35,7 @@ public int GroupNumber
public void WritePhrase()
{
Phrase.GetPhrase(this).Write(_io, this);
_atStartOfLine = false;
}

public void MaybeWriteComma()
Expand All @@ -55,7 +57,7 @@ public void WriteSpaceOrNewLine()
}
else
{
_io.WriteLine();
EndLine();
PhraseCount = 0;
}
}
Expand All @@ -75,10 +77,10 @@ public void MaybeIndent()
}
}

public void ResetGroup(IReadWrite io)
public void ResetGroup()
{
_groupNumber = 0;
io.WriteLine();
EndLine();
}

public bool MaybeCompleteStanza()
Expand All @@ -94,5 +96,14 @@ public bool MaybeCompleteStanza()
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;
}
}
2 changes: 1 addition & 1 deletion 70_Poetry/csharp/Phrase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void Write(IReadWrite io, Context context)
{
if (_condition.Invoke(context))
{
io.Write(_text);
io.Write(context.MaybeCapitalise(_text));
}

_update.Invoke(context);
Expand Down
2 changes: 1 addition & 1 deletion 70_Poetry/csharp/Poem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal static void Compose(IReadWrite io, IRandom random)

if (context.GroupNumberIsValid) { break; }

context.ResetGroup(io);
context.ResetGroup();

if (context.MaybeCompleteStanza()) { break; }
}
Expand Down

0 comments on commit 257ba1a

Please sign in to comment.