wildmatch/source/wildmatch.d

36 lines
1.5 KiB
D
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module wildmatch;
import std.string : fromStringz, toStringz;
import std.conv : to;
extern(C):
/** Коды результата */
enum WM_MATCH = 0; // Совпадение
enum WM_NOMATCH = 1; // Не совпало
/** Флаги */
enum WM_NOESCAPE = 0x01; // Отключить экранирование обратным слешем
enum WM_PATHNAME = 0x02; // '/' должен совпадать только с '/'
enum WM_PERIOD = 0x04; // '.' должен совпадать только с '.'
enum WM_LEADING_DIR = 0x08; // Игнорировать /<хвост> после совпадения
enum WM_CASEFOLD = 0x10; // Регистронезависимо
enum WM_PREFIX_DIRS = 0x20; // Не используется
enum WM_WILDSTAR = 0x40; // '**' совпадает и через '/'
alias WM_IGNORECASE = WM_CASEFOLD;
alias WM_FILE_NAME = WM_PATHNAME;
/**
* Сопоставляет строку с шаблоном (fnmatch-подобно).
* @param pattern NUL-терминированный шаблон
* @param str NUL-терминированная строка
* @param flags комбинация WM_* флагов
* @return WM_MATCH или WM_NOMATCH
*/
private int wildmatch(const(char)* pattern, const(char)* str, int flags);
bool dwildmatch(const string pattern, const string str, int flags = WM_PATHNAME) {
auto patternZ = pattern.toStringz();
auto strZ = str.toStringz();
return wildmatch(patternZ, strZ, flags) == WM_MATCH;
}