| 114 | // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // |
| 115 | |
| 116 | void Foam::regExp::set(const char* pattern, const bool ignoreCase) const |
| 117 | { |
| 118 | clear(); |
| 119 | |
| 120 | // Avoid nullptr and zero-length patterns |
| 121 | if (pattern && *pattern) |
| 122 | { |
| 123 | int cflags = REG_EXTENDED; |
| 124 | if (ignoreCase) |
| 125 | { |
| 126 | cflags |= REG_ICASE; |
| 127 | } |
| 128 | |
| 129 | const char* pat = pattern; |
| 130 | |
| 131 | // Check for embedded prefix for ignore-case |
| 132 | // this is the only embedded prefix we support |
| 133 | // - a simple check is sufficient |
| 134 | if (!strncmp(pattern, "(?i)", 4)) |
| 135 | { |
| 136 | cflags |= REG_ICASE; |
| 137 | pat += 4; |
| 138 | |
| 139 | // avoid zero-length patterns |
| 140 | if (!*pat) |
| 141 | { |
| 142 | return; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | preg_ = new regex_t; |
| 147 | int err = regcomp(preg_, pat, cflags); |
| 148 | |
| 149 | if (err != 0) |
| 150 | { |
| 151 | char errbuf[200]; |
| 152 | regerror(err, preg_, errbuf, sizeof(errbuf)); |
| 153 | |
| 154 | FatalErrorInFunction |
| 155 | << "Failed to compile regular expression '" << pattern << "'" |
| 156 | << nl << errbuf |
| 157 | << exit(FatalError); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | |
| 163 | void Foam::regExp::set(const std::string& pattern, const bool ignoreCase) const |
no test coverage detected