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

21
LINES

< > BotCompany Repo | #1014442 // expandDollarRefsToMatches - allows $1 and $q1/$quoted1

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2729L/17K).

// e.g. s = "hello $1" and m = Matches("world")
static S expandDollarRefsToMatches(S s, Matches m) {
  ret expandDollarRefsToMatches(s, m, false);
}

static S expandDollarRefsToMatches(S s, Matches m, bool alwaysQuote) {
  L<S> tok = javaTok(s);
  for (int i = 1; i < l(tok); i += 2) {
    S t = tok.get(i);
    if (!t.startsWith("$")) continue;
    t = dropFirst(t);
    int j = parseIntAtEnd(t);
    if (j < 1) continue;
    S x = get(m.m, j-1);
    if (x == null) continue;
    if (alwaysQuote || startsWith(t, "q"))
      x = quote(x);
    tok.set(i, x);
  }
  ret join(tok);
}

Author comment

Began life as a copy of #1004949

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1014442
Snippet name: expandDollarRefsToMatches - allows $1 and $q1/$quoted1
Eternal ID of this version: #1014442/8
Text MD5: de144fd583344520eaf5e5f651dc6699
Transpilation MD5: e6d4fbfb05364a63e7fbe639e26cd5bc
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-04-20 21:01:08
Source code size: 603 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 353 / 405
Version history: 7 change(s)
Referenced in: [show references]