@@ -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
2121str 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
3939str (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
4747str (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\n b\r\n " ;
8484
8585str 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\n b\n\n " ) == "a\n\n\n b\n\n " ;
101101
102102list [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