Skip to content

Commit b0c93e7

Browse files
committed
Small fixes (h/t @rodinaarssen)
1 parent e573e26 commit b0c93e7

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/org/rascalmpl/library/String.rsc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,9 @@ list[tuple[str, str]] separateLines(str input, list[str] lineseps = newLineChara
772772
773773
list[tuple[str, str]] lines = [];
774774
int next = 0;
775-
for (int i <- [0..size(input)]) {
775+
for (int i <- [0..size(input)], i >= next) {
776776
// greedily match line separators (longest first)
777-
if (i >= next, str nl <- orderedSeps, nl == input[i..i+size(nl)]) {
777+
if (str nl <- orderedSeps, nl == input[i..i+size(nl)]) {
778778
lines += <input[next..i], nl>;
779779
next = i + size(nl); // skip to the start of the next line
780780
}
@@ -797,9 +797,9 @@ str perLine(str input, str(str) lineFunc, list[str] lineseps = newLineCharacters
797797
= mergeLines([<lineFunc(l), nl> | <l, nl> <- separateLines(input, lineseps=lineseps)]);
798798
799799
@synopsis{Trim trailing non-newline whitespace from each line in a multi-line string.}
800-
str trimTrailingWhitespace(str input) {
800+
str trimTrailingWhitespace(str input, list[str] lineseps = newLineCharacters) {
801801
str trimLineTrailingWs(/^<nonWhiteSpace:.*\S>\s*$/) = nonWhiteSpace;
802802
default str trimLineTrailingWs(/^\s*$/) = "";
803803
804-
return perLine(input, trimLineTrailingWs);
804+
return perLine(input, trimLineTrailingWs, lineseps=lineseps);
805805
}

src/org/rascalmpl/library/lang/rascal/tests/library/String.rsc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ test bool testBase32AllChars4() = testBase32("zxcvbnm,./ZXCVBNM\<\>? ");
265265
// mostUsedNewLline
266266
test bool mostUsedNewlineTestMixed() = mostUsedNewline("\r\n\n\r\n\t\t\t\t") == "\r\n";
267267
test bool mostUsedNewlineTestTie() = mostUsedNewline("\n\n\r\n\r\n") == "\n";
268+
test bool mostUsedNewlineTestNone() = mostUsedNewline("abcdefg") == "\n";
268269
test bool mostUsedNewlineTestGreedy() = mostUsedNewline("\r\n\r\n\n") == "\r\n";
269270

270271
// insertFinalNewline

0 commit comments

Comments
 (0)