示例#1
0
文件: RegExp.cpp 项目: bencz/OrangeC
int RegExpMatch::Matches(RegExpContext &context, const char *str)
{
    if (rl >= 0 && rh >= 0)
    {
        int n,m = 0;
        int count = 0;
        n = MatchOne(context, str);
        while (n > 0)
        {
            m += n;
            n = MatchOne(context, str + m);
            count ++;
        }
        if (count >= rl && count <= rh)
        {
            if (count != 0 || MatchOne(context,str-1) == -1)
                return m;
        }
        if (m)
            return -m;
        else
            return -1;
    }
    else
        return MatchOne(context, str);
;
}
示例#2
0
void CStdErrParser::Add(const char *txt, int len)
{
	fErrBuffer.append(txt, txt + len);

	while (MatchOne(false))
		;
} // CStdErrParser::Add
示例#3
0
static int MatchSet( DaoRegex *self, DaoRgxItem *patt, daoint pos )
{
	DCharState ch = { 1, 1, 0 };
	DCharState chi = ch, chi2 = ch, chi3 = ch;
	char *chars = self->wordbuf + patt->word;
	char *end = chars + patt->length;
	char *src = self->source;
	int blmatch = 1;
	int matched = 0;
	short i;

	patt->offset = 0;
	if( pos >= self->end ) return 0;

	ch = DString_DecodeChar( src + pos, src + self->end );
	if( patt->config & PAT_CONFIG_CASEINS ) ch.value = towlower( ch.value );
	patt->offset = ch.width;
	for(i=0; i<patt->length; ){
		chi3.type = 0;
		chi3.width = 0;
		chi3.value = 0;
		chi = DString_DecodeChar2( chars + i, end );
		chi2 = DString_DecodeChar2( chars + i + chi.width, end );
		if( (i + chi.width + chi2.width) < patt->length ){
			chi3 = DString_DecodeChar2( chars + i + chi.width + chi2.width, end );
		}
		if( i == 0 && chi.value == '^' ){
			blmatch = 0;
		}else if( chi.value == '%' ){
			i += chi2.width;
			switch( chi2.value ){
			case 's': case 'S': case 'k': case 'K': case 'p': case 'P':
			case 'c': case 'C': case 'a': case 'A': case 'w': case 'W':
			case 'e': case 'E': case 'd': case 'D': case 'x': case 'X':
				patt->type = chi2.value;
				matched = (MatchOne( self, patt, pos ) !=0);
				patt->type = PAT_SET;
				break;
			case 't' : matched = (ch.value == '\t'); break;
			case 'n' : matched = (ch.value == '\n'); break;
			default  : matched = (ch.value == chi2.value); break;
			}
		}else if( chi3.type && iswalnum(chi.value) && chi2.value == '-' && iswalnum(chi3.value) ){
			i += chi2.width + chi3.width;
			matched = ( ch.value >= chi.value && ch.value <= chi3.value );
		}else{
			matched = (chi.value == ch.value);
		}
		i += chi.width;
		if( matched ) break;
	}
	if( matched == blmatch ) return 1;
	patt->offset = 0;
	return 0;
}
示例#4
0
static int MatchExpand( DaoRegex *self, DaoRgxItem *patt, daoint pos )
{
	if( patt->max < 0 || patt->count < patt->max ){
		daoint offset = patt->offset;
		if( MatchOne( self, patt, pos ) ){
			patt->offset += offset;
			return 1;
		}
	}
	return 0;
}
示例#5
0
static int MatchMin( DaoRegex *self, DaoRgxItem *patt, daoint pos )
{
	patt->pos = pos;
	patt->count = 0;
	while( patt->count < patt->min ){
		if( MatchOne( self, patt, pos ) ==0 ) return 0;
		pos += patt->offset;
	}
	patt->offset = pos - patt->pos;
	return 1;
}
示例#6
0
void CStdErrParser::Flush()
{
	while (true)
	{
		while (fErrBuffer[0] == '\n')
			fErrBuffer.erase(0, 1);
		
		if (fErrBuffer.length() == 0)
			break;
		
		if (!MatchOne(true))
			break;
	}
} // CStdErrParser::Flush
示例#7
0
/*
//  Trouble! In files, import and export specifiers may or may not have a trailing comma
//  so we look ahead to Token.next and see if there is a comma next (after whitespace)
//  and if there is then we don't set this flag else we do
//  this also affects us using
//      IMPORT x, (PREFIX), y, (PREFIX), x
*/
static bool DoWeNeedToSkipASeparator( bool CheckDirectives )
{
    char *parse;

    if( (NULL == (parse = Token.next)) || ('\0' == *parse) )
        return( false );

    while( ('\0' != *parse) && IS_WHITESPACE( parse ) )
        parse++;

    if( '\0' == *parse )
        return( false );

    if( ',' == *parse )
        return( false );

    /*
    //  skip cr-lf
    */
    if( ('\n' == *parse) || ('\r' == *parse) )
        parse++;
    if( ('\n' == *parse) || ('\r' == *parse) )
        parse++;

    /*
    //  always skip to the next token if the next available token is not a comma
    //  this will allow individual tokens without commas which isn't a big deal
    */
    if( ('\0' != *parse) && (',' != *parse) ) {
        /*
        //  If the next token is __not__ a comma then we need to check that it is not a directive
        //  before allowing the skip!
        */
        if( CheckDirectives ) {
            size_t      len = 0;
            char        *t;

            for( t = parse; !IS_WHITESPACE(t); ++t ) {
                len++;
            }

            if( MatchOne( Directives, SEP_NO, parse, len ) ) {
                return( false );
            }
        }
        return( true );
    }
    return( false );
}
示例#8
0
文件: RegExp.cpp 项目: bencz/OrangeC
bool RegExpContext::Match(int start, int len, const char *Beginning)
{
    beginning = Beginning;
    const char *str = Beginning + start;
    const char *end = str + len;
    matchStackTop = 0;
    while (*str && str < end)
    {
        int n = MatchOne(str);
        if (n >= 0)
        {
            m_so = str - beginning;
            m_eo = str - beginning + n;
            return true;
        }
        else
        {
            str+=-n;
        }
    }
    return false;
}