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).

1  
// e.g. s = "hello $1" and m = Matches("world")
2  
static S expandDollarRefsToMatches(S s, Matches m) {
3  
  ret expandDollarRefsToMatches(s, m, false);
4  
}
5  
6  
static S expandDollarRefsToMatches(S s, Matches m, bool alwaysQuote) {
7  
  L<S> tok = javaTok(s);
8  
  for (int i = 1; i < l(tok); i += 2) {
9  
    S t = tok.get(i);
10  
    if (!t.startsWith("$")) continue;
11  
    t = dropFirst(t);
12  
    int j = parseIntAtEnd(t);
13  
    if (j < 1) continue;
14  
    S x = get(m.m, j-1);
15  
    if (x == null) continue;
16  
    if (alwaysQuote || startsWith(t, "q"))
17  
      x = quote(x);
18  
    tok.set(i, x);
19  
  }
20  
  ret join(tok);
21  
}

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: 361 / 417
Version history: 7 change(s)
Referenced in: [show references]