/*FUNCTION*/ int match_match(char *pszPattern, unsigned long cbPattern, char *pszString, unsigned long cbString, char **ParameterArray, unsigned long *pcbParameterArray, char *pszBuffer, int cArraySize, int cbBufferSize, int fCase, pMatchSets pThisMatchSets, int *iResult ){ /*noverbatim CUT*/ char cA,cB; int ErrorCode; unsigned char *set; if( pThisMatchSets == NULL )pThisMatchSets = &DefaultMatchSets; *iResult = 0;/* note that iResult is set to 1 directly before success return */ while( 1 ){ if( ! cbString ){ *iResult = ! cbPattern; return MATCH_ERROR_SUCCESS; } if( set=MultiJokerSet(pThisMatchSets,*pszPattern) ){ if( ! cbString )return MATCH_ERROR_SUCCESS; /* nothing to match by the joker character */ if( cArraySize == 0 )return MATCH_ERROR_ARRAY_SHORT; if( cbBufferSize < 1 )return MATCH_ERROR_BUFFER_SHORT; /* we have at least one character */ /* check that the first character matches the joker */ cA = *pszString; if( !fCase && islower(cA) )cA = toupper(cA); if( ! JokerMatch(set,cA) )return MATCH_ERROR_SUCCESS; /* handle the first character that matched the joker */ *ParameterArray = pszBuffer; *pszBuffer++ = *pszString++; cbString--; cbBufferSize--; *pcbParameterArray = 1; /* the first character is put into the ParameterArray */ //if( ! cbBufferSize )return STRING_MATCH_BUFFER_SHORT; while( (ErrorCode=match_match(pszPattern+1, cbPattern-1, pszString, cbString, ParameterArray+1, pcbParameterArray+1, pszBuffer, /* while there is no error and does not match */ cArraySize-1, cbBufferSize, fCase, pThisMatchSets, iResult) ) == MATCH_ERROR_SUCCESS && !*iResult ){ if( ! cbString )return MATCH_ERROR_SUCCESS; cA = *pszString; if( !fCase && islower(cA) )cA = toupper(cA); if( ! JokerMatch(set,cA) )return MATCH_ERROR_SUCCESS; *pszBuffer++ = *pszString++; cbBufferSize --; cbString--; (*pcbParameterArray)++; if( ! cbBufferSize )return MATCH_ERROR_BUFFER_SHORT; } *iResult = 1; return MATCH_ERROR_SUCCESS; } /* ~x is just x no matter what x is */ if( *pszPattern == ESCAPE_CHARACTER ){ pszPattern ++; cbPattern--; if( ! cbPattern )return MATCH_ERROR_SYNTAX_ERROR; if( ! fCase ){ cA = *pszPattern; cB = *pszString; if( islower(cA) )cA = toupper(cA); if( islower(cB) )cB = toupper(cB); if( cA != cB )return MATCH_ERROR_SUCCESS; }else{ if( *pszPattern != *pszString )return MATCH_ERROR_SUCCESS; } }else{ if( set=SingleJokerSet(pThisMatchSets,*pszPattern) ){ cA = *pszString; if( !fCase && islower(cA) )cA = toupper(cA); if( ! JokerMatch(set,cA) )return MATCH_ERROR_SUCCESS; *ParameterArray++ = pszBuffer; *pszBuffer++ = *pszString; cbBufferSize--; *pcbParameterArray++ = 1; } else if( *pszPattern == ' ' ){ if( ! isspace(*pszString) )return MATCH_ERROR_SUCCESS; while( cbString && isspace( *pszString ) ){ pszString ++; cbString --; } pszString--; cbString++; }else{ /* Normal character. */ if( ! fCase ){ cA = *pszPattern; cB = *pszString; if( islower(cA) )cA = toupper(cA); if( islower(cB) )cB = toupper(cB); if( cA != cB )return MATCH_ERROR_SUCCESS; }else{ if( *pszPattern != *pszString )return MATCH_ERROR_SUCCESS; } } } pszPattern++; pszString++; cbPattern--; cbString--; }/* end of 'while(1)' */ }
bool Security::MatchString(const string& pattern,const string& s) { return JokerMatch(pattern,s); }