Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

43
LINES

< > BotCompany Repo | #1017523 // switcheroo_noMech - switch first/second person (old version without mech list)

JavaX fragment (include)

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_noMech(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  
}

Author comment

Began life as a copy of #1009569

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017523
Snippet name: switcheroo_noMech - switch first/second person (old version without mech list)
Eternal ID of this version: #1017523/1
Text MD5: 47194fc97ed9ec4e206bb1fa6f053da1
Author: stefan
Category: nl
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-25 16:46:19
Source code size: 1272 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 327 / 341
Referenced in: [show references]