File: vmatch.cc

package info (click to toggle)
filtermail 1.06.00-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,688 kB
  • sloc: cpp: 2,487; fortran: 249; makefile: 106; ansic: 51; sh: 36
file content (36 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//#define XERR
#include "stringnocase.ih"

// overrides
bool StringNoCase::vMatch(string const &hdr) const
{
    size_t length = pattern().length();
    int lastIdx = hdr.length() - length;

    if (lastIdx < 0)
        return false;

    char const *cHdr = &hdr.front();
    char const *cPattern = &pattern().front();

    size_t hdrIdx = 0;
    while (true)
    {
        hdrIdx = hdr.find_first_of(d_first, hdrIdx);
        if (
            hdrIdx == string::npos      // first pattern char. not found
            or 
            static_cast<int>(hdrIdx) > lastIdx // pattern longer than the rest
        )
            return false;               // then no match

                                        // case insensitive match 
        if (strncasecmp(cPattern, cHdr + hdrIdx, length) == 0)
            return true;
        
        ++hdrIdx;                       // continue at the next char.
    }
}