Libraryless. Click here for Pure Java version (1046L/8K/23K).
1 | !747 |
2 | !pcall {
|
3 | |
4 | m {
|
5 | static S inputID = "#1001532"; // Eins etc. |
6 | |
7 | static new L<S> fields; |
8 | static new L<Map<S, S>> rows; |
9 | |
10 | p {
|
11 | for (S line : toLinesFullTrim(loadSnippet(inputID))) try {
|
12 | new Matches m; |
13 | |
14 | if (match3("a structure with * fields: ...", line, m)) {
|
15 | fields.clear(); |
16 | for (int i = 1; i < l(m.m); i++) {
|
17 | S s = m.unq(i); |
18 | if (!eq(s, ",")) |
19 | fields.add(s); |
20 | } |
21 | print(l(fields) + " field(s)"); |
22 | } else {
|
23 | L<S> tok = javaTok(line); |
24 | new Map<S, S> row; |
25 | for (int i = 1; i < l(tok); i += 2) {
|
26 | S field = unquote(tok.get(i)); |
27 | if (!eq(tok.get(i+2), "=")) fail("huh?");
|
28 | i += 4; |
29 | S val = unquote(tok.get(i)); |
30 | row.put(field, val); |
31 | if (i+2 < l(tok)) {
|
32 | i += 2; |
33 | if (!eq(tok.get(i), ",")) fail("huh 2?");
|
34 | } |
35 | } |
36 | rows.add(row); |
37 | } |
38 | } catch (Exception e) {
|
39 | e.printStackTrace(); |
40 | print("Was parsing: " + quote(line));
|
41 | } |
42 | |
43 | print(l(fields) + " field(s), " + l(rows) + " row(s)."); |
44 | } |
45 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1001533 |
| Snippet name: | Structure Holder (developing) |
| Eternal ID of this version: | #1001533/1 |
| Text MD5: | d6953957e6aeef9693ce7b3b8e729caf |
| Transpilation MD5: | e7b7f0fccf00a691a7245a1dbbbcc7c0 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-10-25 00:59:10 |
| Source code size: | 1166 bytes / 45 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 912 / 981 |
| Referenced in: | [show references] |