Libraryless. Click here for Pure Java version (2967L/19K).
1 | /* input e.g. [[ |
2 | Inputs: |
3 | |
4 | "Where is the code repository?" |
5 | "Where is the fork?" |
6 | |
7 | Expected output: |
8 | |
9 | "Where is the *?" |
10 | ]] */ |
11 | |
12 | static SS parseColonHeadingSections(S text) { |
13 | LS lines = lines(text); |
14 | L<Int> l = indicesOfEndingWithTrim(lines, ":"); |
15 | new LinkedHashMap<S> out; |
16 | if (nempty(l)) |
17 | mapPutIfNemptyValue(out, "", rtrim(lines(takeFirst(lines, first(l))))); |
18 | for i over l: { |
19 | int i1 = get(l, i); |
20 | int i2 = or(get(l, i+1), l(lines)+1); |
21 | S heading = dropSuffix(":", trim(lines.get(i1))); |
22 | out.put(heading, lines(subList(lines, i1+1, i2))); |
23 | } |
24 | ret out; |
25 | } |
Began life as a copy of #1027381
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030024 |
Snippet name: | parseColonHeadingSections |
Eternal ID of this version: | #1030024/1 |
Text MD5: | a290aa87127c894444e42da08ffc2356 |
Transpilation MD5: | fa22019a2302af73318049fe468e5623 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-10-30 11:19:17 |
Source code size: | 599 bytes / 25 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 226 / 283 |
Referenced in: | [show references] |