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

9
LINES

< > BotCompany Repo | #1030433 // replaceDollarVars_dyn - does not use a tokenizer

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

Libraryless. Click here for Pure Java version (2725L/17K).

// f takes variable without $ sign. if it returns null, variable is kept
sS replaceDollarVars_dyn(S s, IF1<S> f) {
  if (f == null) ret s;
  ret regexpReplaceIC(s, "\\$(\\w+)", matcher -> {
    S var = matcher.group(1);
    S val = f.get(var);
    ret val == null ? matcher.group() : str(val);
  });
}

Author comment

Began life as a copy of #1028680

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1030433
Snippet name: replaceDollarVars_dyn - does not use a tokenizer
Eternal ID of this version: #1030433/1
Text MD5: 7b86bc8bb41da08e4f7aed4d6fece1ed
Transpilation MD5: b9d295ae79cb239151c98e2527f7580a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-12-16 23:12:31
Source code size: 309 bytes / 9 lines
Pitched / IR pitched: No / No
Views / Downloads: 252 / 336
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1030662 - replaceDollarVars2_dyn - does not use a tokenizer. also supports ${name}