Esempio n. 1
0
void do_test_find(regex_t *regex, char *text, size_t textlen)
{
	#define MATCHES 32
	regmatch_t m[MATCHES];
	int len;
	char *pm = text;
	char *buf = (char *)malloc(sizeof(char) * textlen);
	while(tre_regexec(regex, pm, MATCHES, m, 0) == 0
		&& m[0].rm_so > -1)
	{
		int o = pm - text;
		len = m[0].rm_eo - m[0].rm_so;
		buf_out->append("find(");
		buf_out->append(itoa(o + m[0].rm_so, buf, 10));
		buf_out->append(",");
		buf_out->append(itoa(o + m[0].rm_eo, buf, 10));
		buf_out->append("):");
		memcpy(buf, pm + m[0].rm_so, len);
		buf[len] = 0;
		buf_out->append(buf);
		buf_out->append("\n");
		for(int g = 1; g < MATCHES && m[g].rm_so > -1; g++) {
			len = m[g].rm_eo - m[g].rm_so;
			buf_out->append("  ");
			buf_out->append(itoa(g, buf, 10));
			buf_out->append(":");
			memcpy(buf, pm + m[g].rm_so, len);
			buf[len] = 0;
			buf_out->append(buf);
			buf_out->append("\n");
		}
		pm += m[0].rm_eo;
	}
	free(buf);
}
Esempio n. 2
0
int gt_grep(GT_UNUSED bool *match, GT_UNUSED const char *pattern,
            GT_UNUSED const char *line, GtError *err)
{
  regex_t matcher;
  int rval, had_err = 0;
  gt_error_check(err);
  gt_assert(pattern && line);
  if ((rval = tre_regcomp(&matcher, pattern, REG_EXTENDED | REG_NOSUB))) {
    grep_error(rval, &matcher, err);
    had_err = -1;
  }
  if (!had_err) {
    rval = tre_regexec(&matcher, line, 0, NULL, 0);
    if (rval && rval != REG_NOMATCH) {
      grep_error(rval, &matcher, err);
      had_err = -1;
    }
  }
  tre_regfree(&matcher);
  if (!had_err) {
    if (rval)
      *match = false;
    else
      *match = true;
  }
  return had_err;
}
Esempio n. 3
0
void do_test_match(regex_t *regex, char *text, size_t textlen)
{
	regmatch_t m;
	if(tre_regexec(regex, text, 1, &m, 0) == 0
		&& m.rm_so == 0 && (size_t)m.rm_eo == textlen
	) {
		buf_out->append("matches: yes\n");
	} else {
		buf_out->append("matches: no\n");
	}
}