1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 | package Torello.Java;
// Note: StrIndent already has a "RightTrimAll" function. This is completely unnecessary.
// However, I'm not going to delete it at the moment
//
// I am going to have to further investigate both of these, eventually.
class RightTrimAll2
{
// Chat-GPT wrote this for me:
// https://chatgpt.com/share/69beecb8-4b08-8005-8b6a-9071ed8e102b
//
// I just didn't have the patience. Also, Sam Altman is "in charge" of the LLM's parameter
// training
static String run(final String srcCode)
{
if (srcCode.length() == 0) return srcCode;
final char[] cArr = srcCode.toCharArray();
int out = 0;
int lineStart = 0;
int lastNonWS = -1;
for (int i = 0; i < cArr.length; i++)
{
final char c = cArr[i];
if (c == '\n')
{
final int end = (lastNonWS >= lineStart)
? (lastNonWS + 1)
: lineStart;
for (int j = lineStart; j < end; j++)
cArr[out++] = cArr[j];
cArr[out++] = '\n';
lineStart = i + 1;
lastNonWS = -1;
}
else if (
(c != ' ')
&& (c != '\t')
&& (c != '\r')
)
lastNonWS = i;
}
final int end = (lastNonWS >= lineStart)
? (lastNonWS + 1)
: lineStart;
for (int j = lineStart; j < end; j++)
cArr[out++] = cArr[j];
return new String(cArr, 0, out);
}
}
|