Skip to content

Commit d0a56c8

Browse files
committed
Small fixes.
1 parent 208cd7e commit d0a56c8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

rascal-lsp/src/main/rascal/library/util/Format.rsc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ set[str] newLineCharacters = {
1616
"\u2029" // PS
1717
};
1818

19-
private bool bySize(str a, str b) = size(a) > size(b);
19+
private bool bySize(str a, str b) = size(a) < size(b);
2020
2121
str mostUsedNewline(str input, set[str] lineseps = newLineCharacters, str(set[str]) tieBreaker = getFirstFrom) {
2222
linesepCounts = (nl: 0 | nl <- lineseps);
23-
for (nl <- reverse(sort(lineseps, bySize))) {
23+
for (nl <- sort(lineseps, bySize)) {
2424
int count = size(findAll(input, nl));
2525
linesepCounts[nl] = count;
2626
// subtract all occurrences of substrings that we counted before
2727
for (str snl <- substrings(nl), linesepCounts[snl]?) {
2828
linesepCounts[snl] = linesepCounts[snl] - count;
2929
}
30-
3130
}
31+
3232
byCount = invert(linesepCounts);
3333
return tieBreaker(byCount[max(domain(byCount))]);
3434
}
@@ -38,16 +38,16 @@ tuple[str indentation, str rest] splitIndentation(/^<indentation:\s*><rest:.*>/)
3838
3939
str(str) indentSpacesAsTabs(int tabSize) {
4040
str spaces = ("" | it + " " | _ <- [0..tabSize]);
41-
return str(str s) {
42-
parts = splitIndentation(s);
41+
return str(str line) {
42+
parts = splitIndentation(line);
4343
return "<replaceAll(parts.indentation, spaces, "\t")><parts.rest>";
4444
};
4545
}
4646
4747
str(str) indentTabsAsSpaces(int tabSize) {
4848
str spaces = ("" | it + " " | _ <- [0..tabSize]);
49-
return str(str s) {
50-
parts = splitIndentation(s);
49+
return str(str line) {
50+
parts = splitIndentation(line);
5151
return "<replaceAll(parts.indentation, "\t", spaces)><parts.rest>";
5252
};
5353
}
@@ -83,7 +83,7 @@ test bool insertFinalNewlineTestMixed()
8383
== "a\nb\r\n";
8484
8585
str trimFinalNewline(str input, set[str] lineseps = newLineCharacters) {
86-
orderedSeps = sort(lineseps, bySize);
86+
orderedSeps = reverse(sort(lineseps, bySize));
8787
while (nl <- orderedSeps, endsWith(input, nl)) {
8888
input = input[0..-size(nl)];
8989
}
@@ -100,7 +100,7 @@ test bool trimFinalNewlineTestWhiteSpace()
100100
= trimFinalNewline("a\n\n\nb\n\n ") == "a\n\n\nb\n\n ";
101101
102102
list[tuple[str, str]] separateLines(str input, set[str] lineseps = newLineCharacters) {
103-
orderedSeps = sort(lineseps, bySize);
103+
orderedSeps = reverse(sort(lineseps, bySize));
104104
105105
list[tuple[str, str]] lines = [];
106106
int next = 0;

0 commit comments

Comments
 (0)