⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 warfnmatch.h

📁 ftpserver very good sample
💻 H
字号:
/** Match STRING against the filename pattern PATTERN,     returning true if it matches, false if not.      Derived from the source code for GNU fnmatch()    Copyright Free Software Foundation.*/ #ifndef WAR_FNMATCH_H#define WAR_FNMATCH_H/* SYSTEM INCLUDES */#ifdef HAVE_LOCALE#   include <locale>#endif/* PROJECT INCLUDES */#ifndef WAR_EXCEPTION_H#   include "WarException.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********/#if defined(HAVE_FNMATCH_H) && !defined(WAR_INCLUDED_FNMATCH_H)#   define WAR_INCLUDED_FNMATCH_H#   include <fnmatch.h>#else    /* We #undef these before defining them because some losing systems   (HP-UX A.08.07 for example) define these in <unistd.h>.  */#   undef	FNM_PATHNAME#   undef	FNM_NOESCAPE#   undef	FNM_PERIOD/* Bits set in the FLAGS argument to `fnmatch'.  */#   define	FNM_PATHNAME	(1 << 0) /* No wildcard can ever match `/'.  */#   define	FNM_NOESCAPE	(1 << 1) /* Backslashes don't quote special chars.  */#   define	FNM_PERIOD	(1 << 2) /* Leading `.' is matched only explicitly.  */#   if !defined (_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 2 || defined (_GNU_SOURCE)#       define	FNM_FILE_NAME	FNM_PATHNAME /* Preferred GNU name.  */#       define	FNM_LEADING_DIR	(1 << 3) /* Ignore `/...' after a match.  */#       define	FNM_CASEFOLD	(1 << 4) /* Compare without regard to case.  */#   endif/* Value returned by `fnmatch' if STRING does not match PATTERN.  */#   define	FNM_NOMATCH	1#endif#ifndef FNM_CASEFOLD#   ifdef FMN_IGNORECASE#       define FNM_CASEFOLD FNM_IGNORECASE#   else#       define FNM_CASEFOLD 0x00100000#   endif#endif#ifndef FNM_FILE_NAME#    define FNM_FILE_NAME   0x00200000#endif#ifndef FNM_LEADING_DIR#    define FNM_LEADING_DIR 0x00400000#endif#if defined(FNM_CASEFOLD) && defined(HAVE_LOCALE)#   define FOLD(c) ((flags & FNM_CASEFOLD) && std::isupper(c, loc) ? std::tolower(c, loc) : (c))#else#   define FOLD(c) (c)#endif/** Match STRING against the filename pattern PATTERN, returning zero if   it matches, nonzero if not.    C++ Templatized GNU fnmatch()*//****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplustemplate <class charT>bool WarFnmatch (const charT *pattern, const charT *string, int flags = 0){#ifdef HAVE_LOCALE    std::locale loc;#endif    register const charT *p = pattern, *n = string;    register charT c;#ifndef HAVE_LOCALE    if (flags & FNM_CASEFOLD)        WarThrow(WarError(WAR_ERR_NOT_IMPLEMENTED), "FNM_CASEFOLD");#endif        /* Note that this evaluates C many times.  */        while ((c = *p++) != '\0')    {        c = FOLD (c);                switch (c)        {        case '?':            if (*n == '\0')                return false;            else if ((flags & FNM_FILE_NAME) && *n == '/')                return false;            else if ((flags & FNM_PERIOD) && *n == '.' &&                (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))                return false;            break;                    case '\\':            if (!(flags & FNM_NOESCAPE))            {                c = *p++;                if (c == '\0')                    /* Trailing \ loses.  */                    return false;                c = FOLD (c);            }            if (FOLD (*n) != c)                return false;            break;                    case '*':            if ((flags & FNM_PERIOD) && *n == '.' &&                (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))                return false;                        for (c = *p++; c == '?' || c == '*'; c = *p++)            {                if ((flags & FNM_FILE_NAME) && *n == '/')                    /* A slash does not match a wildcard under FNM_FILE_NAME.  */                    return false;                else if (c == '?')                {                    /* A ? needs to match one character.  */                    if (*n == '\0')                        /* There isn't another character; no match.  */                        return false;                    else                    /* One character of the string is consumed in matching                    this ? wildcard, so *??? won't match if there are                    less than three characters.  */                    ++n;                }            }                        if (c == '\0')                return true;                        {                char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;                c1 = FOLD (c1);                for (--p; *n != '\0'; ++n)                    if ((c == '[' || FOLD (*n) == c1) &&                        WarFnmatch<charT> (p, n, flags & ~FNM_PERIOD) == 0)                        return true;                    return false;            }                    case '[':            {                /* Nonzero if the sense of the character class is inverted.  */                register int nope;                                if (*n == '\0')                    return false;                                if ((flags & FNM_PERIOD) && *n == '.' &&                    (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))                    return false;                                nope = (*p == '!' || *p == '^');                if (nope)                    ++p;                                c = *p++;                for (;;)                {                    register char cstart = c, cend = c;                                        if (!(flags & FNM_NOESCAPE) && c == '\\')                    {                        if (*p == '\0')                            return false;                        cstart = cend = *p++;                    }                                        cstart = cend = FOLD (cstart);                                        if (c == '\0')                        /* [ (unterminated) loses.  */                        return false;                                        c = *p++;                    c = FOLD (c);                                        if ((flags & FNM_FILE_NAME) && c == '/')                        /* [/] can never match.  */                        return false;                                        if (c == '-' && *p != ']')                    {                        cend = *p++;                        if (!(flags & FNM_NOESCAPE) && cend == '\\')                            cend = *p++;                        if (cend == '\0')                            return false;                        cend = FOLD (cend);                                                c = *p++;                    }                                        if (FOLD (*n) >= cstart && FOLD (*n) <= cend)                        goto matched;                                        if (c == ']')                        break;                }                if (!nope)                    return false;                break;                matched:;        /* Skip the rest of the [...] that already matched.  */        while (c != ']')        {            if (c == '\0')                /* [... (unterminated) loses.  */                return false;                        c = *p++;            if (!(flags & FNM_NOESCAPE) && c == '\\')            {                if (*p == '\0')                    return false;                /* XXX 1003.2d11 is unclear if this is right.  */                ++p;            }        }        if (nope)            return false;            }            break;                    default:            if (c != FOLD (*n))                return false;    }        ++n;    }        if (*n == '\0')        return true;        if ((flags & FNM_LEADING_DIR) && *n == '/')        /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz".  */        return true;        return false;    # undef FOLD}/* INLINE METHODS *//* EXTERNAL REFERENCES */#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif  /* WAR_FNMATCH_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -