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

20
LINES

< > BotCompany Repo | #1001250 // format3

JavaX fragment (include)

  static S format3(S pat, O... args) {
    if (args.length == 0) return pat;
    
    L<S> tok = javaTokPlusPeriod(pat);
    int argidx = 0;
    for (int i = 1; i < tok.size(); i += 2)
      if (tok.get(i).equals("*"))
        tok.set(i, format3_formatArg(argidx < args.length ? args[argidx++] : "null"));
    return join(tok);
  }
  
  static S format3_formatArg(O arg) {
    if (arg == null) return "null";
    if (arg instanceof String) {
      S s = (S) arg;
      ret isIdentifier(s) || isNonNegativeInteger(s) ? s : quote(s);
    }
    if (arg instanceof Integer || arg instanceof Long) ret String.valueOf(arg);
    return quote(structure(arg));
  }
  

download  show line numbers  debug dex  old transpilations   

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, jozkyjcghlvl, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney

No comments. add comment

Snippet ID: #1001250
Snippet name: format3
Eternal ID of this version: #1001250/1
Text MD5: 81654dcbdaa209319012fa6a37dc1a4e
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-18 18:06:02
Source code size: 680 bytes / 20 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 851 / 8709
Referenced in: #1001891 - format - synonym of format3 (formatter for sentences)
#1002427 - Accellerating 629 (SPIKE)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1021066 - format3_curly
#1026623 - format_quoteAll
#1028873 - format_flex - with argument formatter
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)