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)

sbool formatXYZ_quotedVars;

static S formatXYZ(S pattern, L<S> args) {
  ret join(formatXYZ(javaTok(pattern), args));
}

// modifies tok!
static L<S> formatXYZ(L<S> tok, L<S> args) {
  for (int i = 1; i < l(tok); i += 2) {
    S t = tok.get(i);
    if (formatXYZ_quotedVars && isQuoted(t)) {
      int idx = formatXYZ_varToIndex(unquote(t))-1;
      if (idx >= 0 && l(args) > idx)
        tok.set(i, quote(args.get(idx)));
    }
    int idx = formatXYZ_varToIndex(t)-1;
    if (idx >= 0 && l(args) > idx)
      tok.set(i, args.get(idx));
  }
  ret tok;
}

static S formatXYZ(S pattern, S... args) {
  ret formatXYZ(pattern, asList(args));
}

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