예제 #1
0
파일: test.c 프로젝트: Lucky7Studio/czmq
int main(int argc, char* argv[])
{
	const TRexChar *begin,*end;
	TRexChar sTemp[200];
	const TRexChar *error = NULL;
	TRex *x = trex_compile(_TREXC("(x{1,5})xx"),&error);
	if(x) {
		trex_sprintf(sTemp,_TREXC("xxxxxxx"));
		if(trex_search(x,sTemp,&begin,&end))
		{
			int i,n = trex_getsubexpcount(x);
			TRexMatch match;
			for(i = 0; i < n; i++)
			{
				TRexChar t[200];
				trex_getsubexp(x,i,&match);
				trex_sprintf(t,_TREXC("[%%d]%%.%ds\n"),match.len);
				trex_printf(t,i,match.begin);
			}
			trex_printf(_TREXC("match! %d sub matches\n"),trex_getsubexpcount(x));
		}
		else {
			trex_printf(_TREXC("no match!\n"));
		}
		trex_free(x);
	}
	else {
		trex_printf(_TREXC("compilation error [%s]!\n"),error?error:_TREXC("undefined"));
	}
	return 0;
}
예제 #2
0
파일: ambiente.c 프로젝트: bzero/POSApp
ret_code amb_init(ambiente_t* ambiente, const char* content, int length)
{
	ret_code ret = ERROR; 
	if (NULL!=content && NULL!=ambiente) {
		const TRexChar *begin, *end, *error;
		TRex* x;		
		CHECK(NULL!=(x=trex_compile(_TREXC("QtdMax=(\\d+)&PdvId=(\\d+)" \
				"&Recibo=(\\d)&Dormir=(\\d)&Cortesias=(\\d)&Credito=(\\d)&"),&error)));
		if (trex_search(x,_TREXC(content),&begin,&end)) {
			int n = trex_getsubexpcount(x);	
			if (n==7) {
				char *qtdMax, *pdvId, *credito;					
				rx_getnext(x, 1, &qtdMax);
				rx_getnext(x, 2, &pdvId);
				rx_getnext(x, 6, &credito);
				CHECK(NULL!=qtdMax);
				CHECK(NULL!=pdvId);
				CHECK(NULL!=credito);
				ambiente->credito = atoi(credito);
				ambiente->qtdMax = atoi(qtdMax);
				ambiente->pdvId = pdvId;
				free(credito);
				free(qtdMax);					
				ret = SUCCESS;
			}
			else {
				ret = ERROR;
			}
		} /* trex_search */
		trex_free(x);
	} /* NULL!=content */
	return ret;
}
예제 #3
0
void test1()
{
	const char *error = NULL;
	const char *begin,*end;
	char *exp1 = "^([^ ]+) (/[^?# ]*)(\\?[^# ]*)?(#[^ ]*)? HTTP/([^ ]+)$";
	char *exp2 = "^([^ ]+): (.+)$";
	char *exp3 = "([^=]+)(=[^&])?(&([^=]+)(=[^&]))*";


	long long t = counter.Tick();
	TRex *x = trex_compile(exp3, &error);
	printf("compile %lld\n", counter.Tick() - t);

	t = counter.Tick();
	if(trex_search(x,"aaa=bbb&ccc=ddd&eee",&begin,&end))
	{
		printf("execute %lld\n", counter.Tick() - t);
		int i,n = trex_getsubexpcount(x);
		TRexMatch match;
		for(i = 1; i < n; i++)
		{
			t = counter.Tick();
			trex_getsubexp(x,i,&match);
			printf("trex_getsubexp %lld ", counter.Tick() - t);

			for(int j=0;j<match.len;j++)
				putchar(match.begin[j]);
			printf("\n");
		}
		printf("match! %d sub matches\n",trex_getsubexpcount(x));
	}
	else
	{
		printf("execute %lld\n", counter.Tick() - t);
		printf("no match!\n");
	}
}
예제 #4
0
파일: zrex.c 프로젝트: Prarrot/czmq
int
zrex_hits (zrex_t *self, const char *text)
{
    assert (self);
    assert (text);
    assert (self->trex);

    unsigned int index;
    for (index = 0; index < self->hits; index++) {
        free (self->hit [index]);
        self->hit [index] = NULL;
    }
    bool matched = !!trex_match (self->trex, text);
    if (matched) {
        //  Get number of hits, setting a sane limit
        self->hits = trex_getsubexpcount (self->trex);
        if (self->hits > MAX_HITS)
            self->hits = MAX_HITS;
    }
    else
        self->hits = 0;

    return self->hits;
}
예제 #5
0
int reSubEndTX (RegExpInfo *rx, int idx) {
  if (!rx->tx || idx < 0 || idx >= trex_getsubexpcount(rx->tx)) return -1;
  TRexMatch m;
  if (trex_getsubexp(rx->tx, idx, &m) != TRex_True) return -1;
  return (intptr_t)(m.begin-rx->bos)+m.len;
}
예제 #6
0
int reSubCountTX (RegExpInfo *rx) {
  if (!rx->tx) return 0;
  return trex_getsubexpcount(rx->tx);
}