public static List<String> toLinesTrim(String s) {
List<String> lines = new ArrayList<String>();
int start = 0;
while (true) {
int i = toLinesTrim_nextLineBreak(s, start);
if (i < 0) {
if (s.length() > start) lines.add(rtrim(s.substring(start)));
break;
}
lines.add(rtrim(s.substring(start, i)));
if (s.charAt(i) == '\r' && i+1 < s.length() && s.charAt(i+1) == '\n')
i += 2;
else
++i;
start = i;
}
return lines;
}
private static int toLinesTrim_nextLineBreak(String s, int start) {
for (int i = start; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '\r' || c == '\n')
return i;
}
return -1;
}Began life as a copy of #2000476
Snippet is not live.
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
| ID | Author/Program | Comment | Date |
|---|---|---|---|
| 1215 | stefan | Actually I think it only trim()s. | 2016-04-27 01:14:15 |
| Snippet ID: | #2000478 |
| Snippet name: | toLinesTrim (function) |
| Eternal ID of this version: | #2000478/1 |
| Text MD5: | 58b04eb912d8c2b289523332d21922db |
| Author: | stefan |
| Category: | javax |
| Type: | New Tinybrain snippet |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-08-01 18:42:43 |
| Source code size: | 763 bytes / 29 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 1150 / 542 |
| Referenced in: | #1002427 - Accellerating 629 (SPIKE) #1006654 - Standard functions list 2 (LIVE, continuation of #761) #3000382 - Answer for ferdie (>> t = 1, f = 0) #3000383 - Answer for funkoverflow (>> t=1, f=0 okay) |