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

12
LINES

< > BotCompany Repo | #1030499 // structWithReplacements

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

Libraryless. Click here for Pure Java version (10113L/58K).

// We assume all elements of the replacements array are just identifiers
// (or similarly simple) so there is no tokenization conflict
// between javaTok and javaTokForStruct
sS structWithReplacements(O object, S... replacements) {
  S s = struct(object);
  LS tok = javaTokForStruct(s);
  bool change;
  for (int i = 0; i < l(replacements); i += 2)
    if (jreplace(tok, replacements[i], replacements[i+1]))
      set change;
  ret change ? join(tok) : s;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030499
Snippet name: structWithReplacements
Eternal ID of this version: #1030499/3
Text MD5: 09c8fd9b51385888d001b2ed6858324d
Transpilation MD5: 6babc8d635e3cad01984398a8b3f9789
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-01 17:04:54
Source code size: 469 bytes / 12 lines
Pitched / IR pitched: No / No
Views / Downloads: 199 / 289
Version history: 2 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)