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

43
LINES

< > BotCompany Repo | #1027401 // switcheroo (old) - switch first/second person

JavaX fragment (include)

static L<S> switcheroo_themap = ll(
  "mine", "yours",
  "my", "your",
  "you are", "i am",
  "are you", "am i",
  "you're", "i'm",
  "you've", "i've",
  "me", "you",
  "i", "you",
);

static S switcheroo(S s) {
  L<S> tok = nlTok5(s);
  for (int i = 1; i < l(tok); i += 2) {
    for (int j = 0; j < l(switcheroo_themap); j += 2) {
      S x = switcheroo_themap.get(j), y = switcheroo_themap.get(j+1);
      L<S> tokx = nlTok5(x), toky = nlTok5(y);
      switcheroo_matchReplace(tok, i, tokx, toky);
      switcheroo_matchReplace(tok, i, toky, tokx);
    }
  }
  ret join(map(f switcheroo_dropAsterisk, tok));
}

sS switcheroo_dropAsterisk(S t) {
  ret startsWith(t, "*") && l(t) > 1 ? substring(t, 1) : t;
}

static void switcheroo_matchReplace(L<S> tok, int i, L<S> tokx, L<S> toky) {
  //printFormat("Matching * * *", i, get(tok, i), tokx);
  if (switcheroo_tokRegionMatch(tok, i, tokx)) {
    //printFormat("Replacing * *", tokx, toky);
    for (int j = 0; j*2+1 < l(tokx); j++)
      tok.set(i+j*2, "*" + toky.get(1+j*2));
  }
}

static bool switcheroo_tokRegionMatch(L<S> tok, int i, L<S> tokx) {
  for (int j = 0; j*2+1 < l(tokx); j++)
    if (!eqic(get(tok, i+j*2), get(tokx, 1+j*2)))
      ret false;
  ret true;
}

Author comment

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: 101 / 126
Referenced in: [show references]