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

28
LINES

< > BotCompany Repo | #1017695 // matchDollarVarsIC_underscores - use match() with dollar vars, underscore indicates word break. now also supports $_q_name for quoted values

JavaX fragment (include)

static SS matchDollarVarsIC_underscores(S pat, S s) {
 pcall {
  if (pat == null || s == null) null;
  new L<S> vars;
  S pat2 = dropSuffix("...", dollarVarsToStars_underscoresWithDollarQ(pat, vars));
  s = dropSuffix("...", s);
  new Matches m;
  if (!match(pat2, s, m)) null;
  new SS map;
  int v = 0;
  for (int i = 0; i < l(m.m); ) {
    S var = vars.get(v++);
    bool quoted = startsWith(var, "$_q_");
    if (quoted) {
      S value = m.m[i++];
      if (!isQuoted(value)) null;
      var = "$" + substring(var, 4);
      if (!strictPutIC(map, var, unquote(value))) null;
    } else {
      int n = underscoreWordCount(var);
      S value = joinWithSpace(subStringArray(m.m, i, i+n));
      if (!strictPutIC(map, var, value)) null;
      i += n;
    }
  }
  ret map;
 } null;
}

Author comment

Began life as a copy of #1010862

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017695
Snippet name: matchDollarVarsIC_underscores - use match() with dollar vars, underscore indicates word break. now also supports $_q_name for quoted values
Eternal ID of this version: #1017695/13
Text MD5: 66bbc8e013f1ca18df19988003223d8f
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-08-20 19:18:40
Source code size: 812 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 450 / 504
Version history: 12 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)