Libraryless. Click here for Pure Java version (2664L/17K).
1 | static IterableIterator<S> toLines(File f) {
|
2 | ret linesFromFile(f); |
3 | } |
4 | |
5 | static List<String> toLines(String s) {
|
6 | List<String> lines = new ArrayList<String>(); |
7 | if (s == null) return lines; |
8 | int start = 0; |
9 | while (true) {
|
10 | int i = toLines_nextLineBreak(s, start); |
11 | if (i < 0) {
|
12 | if (s.length() > start) lines.add(s.substring(start)); |
13 | break; |
14 | } |
15 | |
16 | lines.add(s.substring(start, i)); |
17 | if (s.charAt(i) == '\r' && i+1 < s.length() && s.charAt(i+1) == '\n') |
18 | i += 2; |
19 | else |
20 | ++i; |
21 | |
22 | start = i; |
23 | } |
24 | return lines; |
25 | } |
26 | |
27 | static int toLines_nextLineBreak(String s, int start) {
|
28 | int n = s.length(); |
29 | for (int i = start; i < n; i++) {
|
30 | char c = s.charAt(i); |
31 | if (c == '\r' || c == '\n') |
32 | return i; |
33 | } |
34 | return -1; |
35 | } |
Began life as a copy of #2000326
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1001950 |
| Snippet name: | toLines (function) |
| Eternal ID of this version: | #1001950/4 |
| Text MD5: | 592ac762ff1e4b02b6942fddf9975432 |
| Transpilation MD5: | b8863a3fec0b2a046b035d0595085606 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-05-27 13:20:11 |
| Source code size: | 793 bytes / 35 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 1348 / 5332 |
| Version history: | 3 change(s) |
| Referenced in: | [show references] |