Changeset 210


Ignore:
Timestamp:
04/03/14 21:46:38 (11 years ago)
Author:
Maciej Komosinski
Message:

Added wildcard matching functions

Location:
cpp/frams/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/sstringutils.cpp

    r197 r210  
    288288return true;
    289289}
     290
     291bool matchWildcard(const SString& word,const SString& pattern)
     292{
     293if (pattern.len()==0)
     294        return word.len()==0;
     295int aster=pattern.indexOf('*');
     296if (aster>=0)
     297        {
     298        SString before=pattern.substr(0,aster);
     299        SString after=pattern.substr(aster+1);
     300        int pos=0;
     301        if (!word.len()) return false;
     302        if (before.len()) if (!word.startsWith(before)) return false;
     303        if (after.len())
     304                if ((word.len()<after.len())
     305                    ||(strcmp((const char*)after,((const char*)word)+word.len()-after.len())))
     306                        return false;
     307        return true;
     308        }
     309else
     310        return word==pattern;
     311}
     312
     313bool matchWildcardList(const SString& word,const SString& patterns)
     314{
     315if (patterns.len()==0)
     316        return word.len()==0;
     317int pos=0;
     318SString pattern;
     319while(patterns.getNextToken(pos,pattern,','))
     320        if (matchWildcard(word,pattern))
     321                return true;
     322return false;
     323}
     324
  • cpp/frams/util/sstringutils.h

    r197 r210  
    2626void strSetField(SString& txt,const SString& name,const SString& value);
    2727
    28 SString trim(SString& s); //remove leading/trailing whitespace
    29 bool removeCR(SString& s); //remove '\r' return true if changed
     28SString trim(SString& s); ///< remove leading/trailing whitespace
     29bool removeCR(SString& s); ///< remove '\r' return true if changed
     30bool matchWildcard(const SString& word,const SString& pattern);///< '*' in pattern matches any substring
     31bool matchWildcardList(const SString& word,const SString& patterns);///< patterns is a list of patterns (separated by ',')
    3032
    3133#endif
Note: See TracChangeset for help on using the changeset viewer.