Exemplo n.º 1
0
int matchhere(char* regex, char* text)
{
    if (regex[0] == '\0')
        return 1;
    if (regex[1] == '*')
    {
        return matchstar(regex[0], regex + 2, text);
    }
    if (regex[0] == '$' && regex[1] == '\0')
    {
        return *text == '\0';
    }
    if (*text != '\0' && regex[0] == '\\' && regex[1]!= '\0')
    {
        if (regex[2] != '*')
        {
            if (regex[1] == 'd' && isdigit(*text))
            {
                return matchhere(regex + 2, text + 1);
            }
            else if (regex[1] == 's' && isspace(*text))
            {
                return matchhere(regex + 2, text + 1);
            }
        }
    }
    if (*text != '\0' && (regex[0] == '.' || regex[0] == *text))
    {
        return matchhere(regex + 1, text + 1);
    }
    return 0;
}
Exemplo n.º 2
0
/* match: search for regexp anywhere in text */
static JsVar *match(char *regexp, JsVar *str, size_t startIndex, bool ignoreCase) {
  matchInfo info;
  info.sourceStr = str;
  info.startIndex = startIndex;
  info.ignoreCase = ignoreCase;
  info.rangeMatch = false;
  info.rangeFirstChar = NO_RANGE;
  info.groups = 0;

  JsVar *rmatch;
  JsvStringIterator txtIt, txtIt2;
  jsvStringIteratorNew(&txtIt, str, startIndex);
  /* must look even if string is empty */
  txtIt2 = jsvStringIteratorClone(&txtIt);
  rmatch = matchhere(regexp, &txtIt2, info);
  jsvStringIteratorFree(&txtIt2);
  jsvStringIteratorNext(&txtIt);
  while (!rmatch && jsvStringIteratorHasChar(&txtIt)) {
    info.startIndex++;
    txtIt2 = jsvStringIteratorClone(&txtIt);
    rmatch = matchhere(regexp, &txtIt2, info);
    jsvStringIteratorFree(&txtIt2);
    jsvStringIteratorNext(&txtIt);
  }
  jsvStringIteratorFree(&txtIt);
  return rmatch;
}
Exemplo n.º 3
0
/* match: search for regexp anywhere in text */ 
int match(char *regexp, char *text) {
    if (regexp[0] == '^')
        return matchhere(regexp+1, text);
    do {    /* must look even if string is empty */
        if (matchhere(regexp, text))
            return 1;
    } while (*text++ != '\0'); return 0;
}
Exemplo n.º 4
0
/* match: search for regexp anywhere in text */
static XMP_Bool match ( XMP_StringPtr regexp, XMP_StringPtr text ) {
	if ( regexp[0] == '^' )
		return matchhere ( regexp+1, text );
	do {    /* must look even if string is empty */
		if ( matchhere ( regexp, text ) )
			return true;
	} while ( *text++ != '\0' );
	return false;
}
Exemplo n.º 5
0
int match(char *re, char *text) {
  if (re[0] == '^')
    return matchhere(re+1, text);
  do {
    if (matchhere(re, text))
      return 1;
  } while (*text++ != '\0');
  return 0;
}
Exemplo n.º 6
0
int match(char *re, char *text)
{
    if(re[0] == '^')
        return matchhere(re+1, text);
    do {  // must look at empty string
        if (matchhere(re, text))
            return 1;
    } while (*text++ != '\0');
    return 0;
}
Exemplo n.º 7
0
// match: search regexp in text
int regexp::match(char *regexp, char *text)
{
   if (regexp[0] == '^')
      return matchhere(regexp+1, text);
   do {
      if (matchhere(regexp, text))
         return 1;
   } while (*text++ != '\0');
   return 0;
}
Exemplo n.º 8
0
Arquivo: 01.c Projeto: ytaoWang/test
int match(const char *regexp,const char *text)
{
  if(*regexp == '^') 
    return matchhere(regexp+1,text);

  do {
    if(matchhere(regexp,text))
      return 1;
  } while(*text++ != '\0');

  return 0;
}
Exemplo n.º 9
0
int match(char *regexp, char *text)
{
    if ('^' == regexp[0]) {
        return matchhere(regexp + 1, text);
    }

    do { // 即使子副词为空时也必须检查
        if (matchhere(regexp, text)) {
            return 1;
        }
    } while (*text++ != '\0');
}
Exemplo n.º 10
0
int match(char* regex, char* text)
{
    if (regex[0] == '^')
        return matchhere(regex + 1, text);
    do
    {
        if (matchhere(regex, text))
        {
            return 1;
        }
    }while(*text++ != '\0');
    return 0
}
Exemplo n.º 11
0
int regular_expression_match(const char *regexp, const char *text)
{
    if (regexp[0] == '^')
    {
        return matchhere(regexp + 1, text);
    }
    do
    { /* must look even if string is empty */
        if (matchhere(regexp, text))
            return 1;
    }
    while (*text++ != '\0');
    return 0;
}
Exemplo n.º 12
0
// match: search for regexp anywhere in text
int match (char *regexp, char *text) {
    
#if DEBUG
    printf ("match %s %s$\n", regexp, text);
#endif

    // match start of line
    if (regexp[0] == '^')
        return matchhere (regexp+1, text);

    do {    // check even if string is empty
        if (matchhere (regexp, text))
            return 1;
    } while (*text++ != '\0');
    return 0;
}
Exemplo n.º 13
0
Arquivo: 01.c Projeto: ytaoWang/test
int matchhere(const char *regexp,const char *text)
{
  if(*regexp == '\0')
    return 1;
  
  if(regexp[1] == '*')
    return matchstar(regexp[0],regexp+2,text);

  if(regexp[0] =='$' && regexp[1] == '\0')
    return *text == '\0';

#ifdef DEBUG
  fprintf(stderr,"[INFO]:%s,regexp:%s,text:%s\n",__func__,regexp,text);
#endif
  if(*text != '\0' && (regexp[0] == '.' || regexp[0] == *text))
    return matchhere(regexp + 1,text + 1);
  /*
  while(*regexp != '\0') {
    if(*regexp == '*') return matchstar(regexp[0],regexp+2,text);
    if(*text == '\0') return 0;
    if(*regexp++ != *text++) return 0;
  }
  */
#ifdef DEBUG
  fprintf(stderr,"[INFO]:%s,run successful at last.\n",__func__);
#endif

  return 0;
}
Exemplo n.º 14
0
static int matchstar(int c, char *re, char *text) {
  do {
    if (matchhere(re, text))
      return 1;
  } while (*text != '\0' && (*text++ == c || c== '.'));
  return 0;
}
Exemplo n.º 15
0
/*search for regexp anywhere in text*/
int match(char *regexp, char *text)
{
    if (regexp[0]=='^')//固定位置的匹配,字符必须对应匹配

        return matchhere(regexp+1, text);
    do
    {
        if(matchhere(regexp, text))
        {//不是^时,就从第一个开始匹配,直到结束
            return 1;
        }

    }while(*text++!='\0');

    return 0;
}
Exemplo n.º 16
0
// matchstar: search c*regexp in the beginning of text
int regexp::matchstar(int c, char *regexp, char *text)
{
   do {
      if (matchhere(regexp, text))
         return 1;
   } while (*text != '\0' && (*text++ == c || c == '.'));
   return 0;
}
Exemplo n.º 17
0
/* matchhere: search for regexp at beginning of text */
static XMP_Bool matchhere ( XMP_StringPtr regexp, XMP_StringPtr text ) {
	if ( regexp[0] == '\0' )
		return true;
	if ( regexp[0] == '\\' && regexp[1] == 'd' ) {
		if ( matchdigit(text) )
			return matchhere ( regexp+2, text+1 );
		else
			return false;
	}

	if ( regexp[0] == '$' && regexp[1] == '\0' )
		return *text == '\0';

	if ( *text != '\0' && regexp[0] == *text )
		return matchhere ( regexp+1, text+1 );
	return 0;
}
Exemplo n.º 18
0
// matchstar: search for c*re at beginning of text
int matchstar(int c, char *re, char *text)
{
  do{  // a * matches zero or more instances
    if(matchhere(re, text))
      return 1;
  }while(*text!='\0' && (*text++==c || c=='.'));
  return 0;
}
Exemplo n.º 19
0
/* matchstar: search for c*regexp at beginning of text */
static int matchstar(int c, const char *regexp, const char *text)
{
    do {    /* a * matches zero or more instances */
        if (matchhere(regexp, text))
            return 1;
    } while (*text != '\0' && (*text++ == c || c == '.'));
    return 0;

}
Exemplo n.º 20
0
Arquivo: main.cpp Projeto: CCJY/coliru
// matchstar searches for `regexp` at beginning of text 
int matchstar(int c, char* regexp, char* text)
{
    // a '*' matches zero or more instances 
    do {
        if (matchhere(regexp, text)) return 1;
    }
    while (*text != '\0' && (*text++ == c || c == '.'));
    return 0;
}
Exemplo n.º 21
0
int matchstar(int c, char *regexp, char *text)
{
    do { // 通配符*匹配零个或多个实例
        if (matchhere(regexp, text)) {
            return 1;
        }
    } while (*text != '\0' && (*text++ == c || c == '.'));

    return 0;
}
Exemplo n.º 22
0
/* matchstar: search for c*regexp at beginning of text */
int matchstar(int c, char *regexp, char *text)
{
    char *t;
    for (t = text; *t != '\0' && (*t == c || c == '.'); t++)
        do {    /* a * matches zero or more instances */
            if (matchhere(regexp, text))
                return 1;
        } while (*text != '\0' && (*text++ == c || c == '.'));
    return 0;
}
Exemplo n.º 23
0
static int matchhere(char *re, char *text) {
  if (re[0] == '\0')
     return 0;
  if (re[1] == '*')
    return matchstar(re[0], re+2, text);
  if (re[0] == '$' && re[1]=='\0')
    return *text == '\0';
  if (*text!='\0' && (re[0]=='.' || re[0]==*text))
    return matchhere(re+1, text+1);
  return 0;
}
Exemplo n.º 24
0
int matchstar(bool (fun*)(char),char* regex, char* text)
{
    do 
    {
        if (matchhere(regex, text))
        {
            return 1;
        }
    }while(*text != '\0' && fun(*text++)|| c == '.');
    return 0;
}
Exemplo n.º 25
0
/* matchhere: search for regexp at beginning of text */ 
int matchhere(char *regexp, char *text) {
    if (regexp[0] == '\0')
        return 1;
    if (regexp[1] == '*')
        return matchstar(regexp[0], regexp+2, text);
    if (regexp[0] == '$' && regexp[1] == '\0')
        return *text == '\0';
    if (*text!='\0' && (regexp[0]=='.' || regexp[0]==*text))
        return matchhere(regexp+1, text+1);
    return 0;
}
Exemplo n.º 26
0
int matchstar(int c,char* regex, char* text)
{
    do 
    {
        if (matchhere(regex, text))
        {
            return 1;
        }
    }while(*text != '\0' && *text++ == c || c == '.');
    return 0;
}
Exemplo n.º 27
0
/* matchstar: leftmost longest search for c*regexp */
int matchstar(int c, char *regexp, char *text)
{
	char *t;

	for (t = text; *t != '\0' && (*t == c || c == '.'); t++)
		;
	do {	/* * matches zero or more */
		if (matchhere(regexp, t))
			return 1;
	} while (t-- > text);
	return 0;
}
Exemplo n.º 28
0
Arquivo: 01.c Projeto: ytaoWang/test
/*
 * match string:c*regexp in text
 */
int matchstar(int c,const char *regexp,const char *text)
{
#ifdef DEBUG
  fprintf(stderr,"[INFO]:%s,regexp:%s,text:%s\n",__func__,regexp,text);
#endif
  if(*regexp == '$') return 1;
  do {
    if(matchhere(regexp,text))
      return 1;
  }while(*text != '\0' && (*text++ == c || c == '.'));

  return 0;
}
Exemplo n.º 29
0
/*matchhere:search for regexp at beginning of text*/
int matchhere(char *regexp, char *text)
{//正则表达式的字符与文本的第一个字符匹配
    if(regexp[0] == '\0')
        return 1;

    if(regexp[1] == '*')//如果字符后面有一个*号,那就从text中找出一个与*后字符匹配的都算成功
                        //例如x*y,与xadfdfgfhadsfsdy匹配
        return matchstar(regexp[0], regexp+2,text);

    if(regexp[0] == '$' && regexp[1]=='\0')
        return *text == '\0';

    if(*text!='\0' && (regexp[0]=='.' ||regexp[0]==*text) )
        return matchhere(regexp+1,text+1);

    return 0;
}
Exemplo n.º 30
0
// matchstar: leftmost longest search for c*regexp
int matchstar (char c, char *regexp, char *text) {

#if DEBUG
    printf ("matchstar %c %s %s$\n", c, regexp, text);
#endif
    
    char *t;
    
    // match repeated character
    for (t = text; *t != '\0' && (*t == c || c == '.'); t++);
    
    // resume matching regexp after repeated character
    do {
        if (matchhere (regexp, t))
            return 1;
    } while (t-- > text);
    
    return 0;
}