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

25
LINES

< > BotCompany Repo | #1007412 // formatXYZ - recognizes X, Y, Z, AA, AB, AC, AD, ...

JavaX fragment (include)

1  
sbool formatXYZ_quotedVars;
2  
3  
static S formatXYZ(S pattern, L<S> args) {
4  
  ret join(formatXYZ(javaTok(pattern), args));
5  
}
6  
7  
// modifies tok!
8  
static L<S> formatXYZ(L<S> tok, L<S> args) {
9  
  for (int i = 1; i < l(tok); i += 2) {
10  
    S t = tok.get(i);
11  
    if (formatXYZ_quotedVars && isQuoted(t)) {
12  
      int idx = formatXYZ_varToIndex(unquote(t))-1;
13  
      if (idx >= 0 && l(args) > idx)
14  
        tok.set(i, quote(args.get(idx)));
15  
    }
16  
    int idx = formatXYZ_varToIndex(t)-1;
17  
    if (idx >= 0 && l(args) > idx)
18  
      tok.set(i, args.get(idx));
19  
  }
20  
  ret tok;
21  
}
22  
23  
static S formatXYZ(S pattern, S... args) {
24  
  ret formatXYZ(pattern, asList(args));
25  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1007412
Snippet name: formatXYZ - recognizes X, Y, Z, AA, AB, AC, AD, ...
Eternal ID of this version: #1007412/10
Text MD5: bd84b88a5448ea9bf30f37d118983ee3
Author: stefan
Category: javax / formatting
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-24 19:57:51
Source code size: 667 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 616 / 584
Version history: 9 change(s)
Referenced in: [show references]