File: wildcmp.cpp

package info (click to toggle)
osm2pgsql 0.92.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,420 kB
  • ctags: 1,429
  • sloc: cpp: 11,650; python: 543; sh: 98; makefile: 14
file content (35 lines) | stat: -rw-r--r-- 790 bytes parent folder | download | duplicates (3)
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
/* Wildcard matching.

*/

/**
 * Case sensitive wild card match with a string.
 * * matches any string or no character.
 * ? matches any single character.
 * anything else etc must match the character exactly.
 *
 * Returns if a match was found.
 */
bool wildMatch(const char *first, const char *second)
{
    // Code borrowed from
    // http://www.geeksforgeeks.org/wildcard-character-matching/
    if (*first == '\0' && *second == '\0') {
        return true;
    }

    if (*first == '*' && *(first+1) != '\0' && *second == '\0') {
        return false;
    }

    if (*first == '?' || *first == *second) {
        return wildMatch(first+1, second+1);
    }

    if (*first == '*') {
        return wildMatch(first+1, second) || wildMatch(first, second+1);
    }

    return false;
}