1 | static L<S> switcheroo_themap = ll( |
2 | "mine", "yours", |
3 | "my", "your", |
4 | "you are", "i am", |
5 | "are you", "am i", |
6 | "you're", "i'm", |
7 | "you've", "i've", |
8 | "me", "you", |
9 | "i", "you", |
10 | ); |
11 | |
12 | static S switcheroo(S s) { |
13 | L<S> tok = nlTok5(s); |
14 | for (int i = 1; i < l(tok); i += 2) { |
15 | for (int j = 0; j < l(switcheroo_themap); j += 2) { |
16 | S x = switcheroo_themap.get(j), y = switcheroo_themap.get(j+1); |
17 | L<S> tokx = nlTok5(x), toky = nlTok5(y); |
18 | switcheroo_matchReplace(tok, i, tokx, toky); |
19 | switcheroo_matchReplace(tok, i, toky, tokx); |
20 | } |
21 | } |
22 | ret join(map(f switcheroo_dropAsterisk, tok)); |
23 | } |
24 | |
25 | sS switcheroo_dropAsterisk(S t) { |
26 | ret startsWith(t, "*") && l(t) > 1 ? substring(t, 1) : t; |
27 | } |
28 | |
29 | static void switcheroo_matchReplace(L<S> tok, int i, L<S> tokx, L<S> toky) { |
30 | //printFormat("Matching * * *", i, get(tok, i), tokx); |
31 | if (switcheroo_tokRegionMatch(tok, i, tokx)) { |
32 | //printFormat("Replacing * *", tokx, toky); |
33 | for (int j = 0; j*2+1 < l(tokx); j++) |
34 | tok.set(i+j*2, "*" + toky.get(1+j*2)); |
35 | } |
36 | } |
37 | |
38 | static bool switcheroo_tokRegionMatch(L<S> tok, int i, L<S> tokx) { |
39 | for (int j = 0; j*2+1 < l(tokx); j++) |
40 | if (!eqic(get(tok, i+j*2), get(tokx, 1+j*2))) |
41 | ret false; |
42 | ret true; |
43 | } |
Began life as a copy of #1009569
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1027401 |
Snippet name: | switcheroo (old) - switch first/second person |
Eternal ID of this version: | #1027401/1 |
Text MD5: | 716ffa8d0f211f7f9862fff972c8473d |
Author: | stefan |
Category: | nl |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-03-17 22:41:07 |
Source code size: | 1265 bytes / 43 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 212 / 210 |
Referenced in: | [show references] |