@@ -767,7 +767,7 @@ str trimFinalNewlines(str input, list[str] lineseps = newLineCharacters) {
767767}
768768
769769@synopsis {Split a string in <text, newline> pairs for each line.}
770- list [tuple [str , str ]] separateLines (str input , list [str ] lineseps = newLineCharacters ) {
770+ list [tuple [str , str ]] separateLines (str input , bool includeEmptyLastLine = false , list [str ] lineseps = newLineCharacters ) {
771771 orderedSeps = reverse (sort (lineseps , bySize ));
772772
773773 list [tuple [str , str ]] lines = [];
@@ -781,8 +781,8 @@ list[tuple[str, str]] separateLines(str input, list[str] lineseps = newLineChara
781781 }
782782
783783 // last line
784- if (str nl <- orderedSeps , nl == input [- size (nl )..] ) {
785- lines += <input [next ..next + size ( nl ) ], "" > ;
784+ if (next < size (input ) || includeEmptyLastLine ) {
785+ lines += <input [next ..], "" > ;
786786 }
787787
788788 return lines ;
@@ -793,8 +793,8 @@ str mergeLines(list[tuple[str, str]] lines)
793793 = ("" | it + line + sep | <line , sep > <- lines );
794794
795795@synopsis {Process the text of a string per line, maintaining the original newline characters.}
796- str perLine (str input , str (str ) lineFunc , list [str ] lineseps = newLineCharacters )
797- = mergeLines ([<lineFunc (l ), nl > | <l , nl > <- separateLines (input , lineseps =lineseps )]);
796+ str perLine (str input , str (str ) lineFunc , bool includeEmptyLastLine = false , list [str ] lineseps = newLineCharacters )
797+ = mergeLines ([<lineFunc (l ), nl > | <l , nl > <- separateLines (input , includeEmptyLastLine = includeEmptyLastLine , lineseps =lineseps )]);
798798
799799@synopsis {Trim trailing non-newline whitespace from each line in a multi-line string.}
800800str trimTrailingWhitespace (str input , list [str ] lineseps = newLineCharacters ) {
0 commit comments