Skip to content

Commit a41b62f

Browse files
committed
Refactor linebreak appending check in UltraStarSongWriter
Now a single loop with index check, as requested in PR review.
1 parent 5e4cec8 commit a41b62f

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

  • UltraStar Play/Packages/playshared/Runtime/Songs/UltraStarSongFormat/UltraStarSongWriter

UltraStar Play/Packages/playshared/Runtime/Songs/UltraStarSongFormat/UltraStarSongWriter/UltraStarSongWriter.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ private static void AppendVoice(StringBuilder sb, Voice voice, bool appendVoiceI
5858
sb.AppendLine(voice.Id.ToString());
5959
}
6060
List<Sentence> sortedSentences = SongMetaUtils.GetSortedSentences(voice);
61-
// Process the last sentence separately. A linebreak should not be appended after the last sentence.
62-
foreach (Sentence sentence in sortedSentences.SkipLast(1))
61+
for (int i = 0; i < sortedSentences.Count; i++)
6362
{
64-
AppendSentence(sb, sentence, true);
65-
}
66-
if (sortedSentences.Count > 0)
67-
{
68-
AppendSentence(sb, sortedSentences.Last(), false);
63+
Sentence sentence = sortedSentences[i];
64+
// A linebreak should not be appended after the last sentence.
65+
bool appendLinebreak = i < sortedSentences.Count - 1;
66+
AppendSentence(sb, sentence, appendLinebreak);
6967
}
7068
}
7169

0 commit comments

Comments
 (0)