Exemple #1
0
static int name_callback (const UChar *name, const UChar *name_end,
      int ngroups, int *groupnumlist, regex_t *reg, void *arg)
{
  (void) ngroups;
  (void) groupnumlist;
  TNameArg *A = (TNameArg*)arg;
  int num = onig_name_to_backref_number(reg, name, name_end, A->ud->region);
  lua_pushlstring (A->L, (const char*)name, name_end - name);
  ALG_PUSHSUB_OR_FALSE (A->L, A->ud, A->text, num);
  lua_rawset (A->L, -3);
  return 0;
}
Exemple #2
0
/* the target table must be on lua stack top */
static void do_named_subpatterns (lua_State *L, TPcre *ud, const char *text) {
  int i, namecount, name_entry_size;
  unsigned char *name_table, *tabptr;

  /* do named subpatterns - NJG */
  pcre_fullinfo (ud->pr, ud->extra, PCRE_INFO_NAMECOUNT, &namecount);
  if (namecount <= 0)
    return;
  pcre_fullinfo (ud->pr, ud->extra, PCRE_INFO_NAMETABLE, &name_table);
  pcre_fullinfo (ud->pr, ud->extra, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
  tabptr = name_table;
  for (i = 0; i < namecount; i++) {
    int n = (tabptr[0] << 8) | tabptr[1]; /* number of the capturing parenthesis */
    if (n > 0 && n <= ALG_NSUB(ud)) {   /* check range */
      lua_pushstring (L, (char *)tabptr + 2); /* name of the capture, zero terminated */
      ALG_PUSHSUB_OR_FALSE (L, ud, text, n);
      lua_rawset (L, -3);
    }
    tabptr += name_entry_size;
  }
}