From 779980828708cafdd3db3ae57face10338b14f33 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Thu, 18 Sep 2025 03:30:54 +0300 Subject: [PATCH] init --- .vscode/settings.json | 5 +++++ LICENSE | 23 +++++++++++++++++++++++ README.md | 3 +++ dub.json | 10 ++++++++++ dub.selections.json | 5 +++++ dub.settings.json | 4 ++++ source/wildmatch.d | 34 ++++++++++++++++++++++++++++++++++ 7 files changed, 84 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 LICENSE create mode 100644 README.md create mode 100644 dub.json create mode 100644 dub.selections.json create mode 100644 dub.settings.json create mode 100644 source/wildmatch.d diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d1c022f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "editor.insertSpaces": false, + "editor.tabSize": 4, + "editor.detectIndentation": false +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..36b7cd9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..997f87e --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# wildmatch + +wildmatch — это библиотека для сопоставления шаблонов в стиле git/rsync. diff --git a/dub.json b/dub.json new file mode 100644 index 0000000..5610d41 --- /dev/null +++ b/dub.json @@ -0,0 +1,10 @@ +{ + "authors": [ + "Alexander Zhirov" + ], + "copyright": "Copyright © 2025, Alexander Zhirov", + "description": "wildmatch is a library for git/rsync-style pattern matching.", + "license": "BSL-1.0", + "name": "wildmatch", + "targetType": "library" +} diff --git a/dub.selections.json b/dub.selections.json new file mode 100644 index 0000000..322586b --- /dev/null +++ b/dub.selections.json @@ -0,0 +1,5 @@ +{ + "fileVersion": 1, + "versions": { + } +} diff --git a/dub.settings.json b/dub.settings.json new file mode 100644 index 0000000..9da886c --- /dev/null +++ b/dub.settings.json @@ -0,0 +1,4 @@ +{ + "defaultArchitecture": "x86_64", + "defaultCompiler": "ldc2" +} diff --git a/source/wildmatch.d b/source/wildmatch.d new file mode 100644 index 0000000..c41d605 --- /dev/null +++ b/source/wildmatch.d @@ -0,0 +1,34 @@ +module wildmatch; + +import std.string : fromStringz; +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(string pattern, string str, int flags = WM_PATHNAME) { + return wildmatch(pattern.ptr, str.ptr, flags) == WM_MATCH; +}