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; }
static int name_callback(const UChar* name, const UChar* name_end, int ngroup_num, int* group_nums, regex_t* reg, void* arg) { int i, gn, ref; char* s; OnigRegion *region = (OnigRegion* )arg; for (i = 0; i < ngroup_num; i++) { gn = group_nums[i]; ref = onig_name_to_backref_number(reg, name, name_end, region); s = (ref == gn ? "*" : ""); fprintf(stderr, "%s (%d): ", name, gn); fprintf(stderr, "(%d-%d) %s\n", region->beg[gn], region->end[gn], s); } return 0; /* 0: continue */ }
int LookupOnigCaptureByName(char *name, int name_length, OnigRegex regex, OnigRegion *region) { int ret = ONIGERR_UNDEFINED_NAME_REFERENCE; #ifdef BENCHMARK_CHELP struct timeval tim1, tim2; long t; #endif OnigUChar *name_start = (OnigUChar *) name; OnigUChar *name_end = (OnigUChar *) (name_start + name_length); #ifdef BENCHMARK_CHELP gettimeofday(&tim1, NULL); #endif ret = onig_name_to_backref_number(regex, name_start, name_end, region); #ifdef BENCHMARK_CHELP gettimeofday(&tim2, NULL); t = (tim2.tv_sec - tim1.tv_sec) * 1000000 + tim2.tv_usec - tim1.tv_usec; printf("%ld microseconds elapsed\n", t); #endif return ret; }
static int name_callback(const UChar* name, const UChar* name_end, int ngroup_num, int* group_nums, regex_t* reg, void* arg) { int i, gn, ref; char* s; OnigRegion *region = (OnigRegion* )arg; for (i = 0; i ngroup_num; i++) { gn = group_nums[i]; ref = onig_name_to_backref_number(reg, name, name_end, region); s = (ref == gn ? "*" : ""); strcpy(data_rslt[gn].n, name); data_rslt[gn].b = region-beg[gn]; data_rslt[gn].e = region-end[gn]; } return 0; /* 0: continue */ }