Checks if a test string is of the form specified by a control string. The method is aimed primarily at filtering filenames and is not intended as a formal regular expression interpreter. The following sequences appearing in the control string are treated as wildcards as follows:- * One or more consequtive asterisks match to a series of zero or more characters of any form ? Matches to one character [0-9] Matches to any digit 0-9 [a-z] Matches to any lower case letter [A-Z] Matches to any upper case letter The control string is firstly broken into parts by an asterisk (or a series of consequtive asterisks), appearing anywhere within it. Each part either ends with an asterisk or a null terminator. If the control string starts with an asterisk, the first part (part 0) will just comprise the asterisk and be of zero length. Likewise if the control string ends with an asterisk, the last part will just comprise the asterisk and be of zero length. The test for a match is passed if the test string contains each part and in the order of appreance in the control string. The test string automatically matches a part of zero length.
| Return Type | Function name | Arguments |
|---|---|---|
| bool | FormCheckCstr | (const char*,const char*,) |
Declared in file: hzTextproc.h
Defined in file : hzRegex.cpp
Function Logic:
Function body:
bool FormCheckCstr (const char* cpTest)const char* cpCtrl,
{
// Category: Regular Expression
//
// Checks if a test string is of the form specified by a control string.
//
// The method is aimed primarily at filtering filenames and is not intended as a formal regular expression interpreter. The following sequences appearing in the control string
// are treated as wildcards as follows:-
//
// * One or more consequtive asterisks match to a series of zero or more characters of any form
// ? Matches to one character
// [0-9] Matches to any digit 0-9
// [a-z] Matches to any lower case letter
// [A-Z] Matches to any upper case letter
//
// The control string is firstly broken into parts by an asterisk (or a series of consequtive asterisks), appearing anywhere within it. Each part either ends with an asterisk
// or a null terminator. If the control string starts with an asterisk, the first part (part 0) will just comprise the asterisk and be of zero length. Likewise if the control
// string ends with an asterisk, the last part will just comprise the asterisk and be of zero length. The test for a match is passed if the test string contains each part and
// in the order of appreance in the control string. The test string automatically matches a part of zero length.
//
// Arguments: 1) cpTest The test string
// 2) cpCtrl The control string
//
// Returns: True If the test string is of the form specified by the control
// False Otherwise.
_hzfunc(__func__) ;
const char* c ; // For processing ctrl string into parts
const char* s ; // Progressive ptr for test string
uint32_t nParts ; // Total number of parts
uint32_t nChars ; // Total number of chars to be matched
uint32_t curPart ; // Current part
bool bMatch ; // Match by _checkformpart()
// If no control string there is no criteria so an automatic pass
if (!cpCtrl || !cpCtrl[0])
return true ;
// If no test string this is invalid so an automatic fail
if (!cpTest || !cpTest[0])
return false ;
// Break up the control string
for (c = cpCtrl ; *c ;)
{
if (*c == CHAR_ASTERISK)
{ nParts++ ; for (; *c == CHAR_ASTERISK ; c++) ; }
else if (*c == CHAR_SQOPEN)
{
if (memcmp(c, "[0-9]", 5)) { c += 5; nChars++ ; continue ; }
if (memcmp(c, "[a-z]", 5)) { c += 5; nChars++ ; continue ; }
if (memcmp(c, "[A-Z]", 5)) { c += 5; nChars++ ; continue ; }
}
else
{ c++ ; nChars++ ; }
}
// Process the CTRL string
for (curPart = 0,c = cpCtrl, s = cpTest ; *c && *s ;)
{
bMatch = _checkformpart(&s, &c) ;
if (!curPart && !bMatch)
return false ;
if (!bMatch)
s++ ;
else
{
if (*c == CHAR_ASTERISK)
{
// Advance the control until no longer on an asterisk. Then look for the first occurence of the control char in the test
curPart++ ;
for (; *c == CHAR_ASTERISK ; c++) ;
}
}
}
if (*c == 0&& *s == 0)
return true ;
return false ;
}