Libraryless. Click here for Pure Java version (2735L/16K).
1 | // f takes variable without $ sign. if it returns null, variable is kept |
2 | sS replaceDollarVars2_dyn(S s, IF1<S> f) { |
3 | if (f == null) ret s; |
4 | ret regexpReplace(s, "\\$(\\w+)|\\$\\{(.+?)\\}", matcher -> { |
5 | S var = or(matcher.group(1), matcher.group(2)); |
6 | S val = f.get(var); |
7 | ret val == null ? matcher.group() : str(val); |
8 | }); |
9 | } |
Began life as a copy of #1030433
download show line numbers debug dex old transpilations
Travelled to 5 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030662 |
Snippet name: | replaceDollarVars2_dyn - does not use a tokenizer. also supports ${name} |
Eternal ID of this version: | #1030662/5 |
Text MD5: | 8c9bf832e4e5432e6b782ebf77931dfc |
Transpilation MD5: | aed7d5fc0803320e39cf8748f96596ab |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-02-22 13:09:43 |
Source code size: | 345 bytes / 9 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 215 / 395 |
Version history: | 4 change(s) |
Referenced in: | [show references] |