40 lines
1.4 KiB
Markdown
40 lines
1.4 KiB
Markdown
[← Utils](../README.md)
| |||
| |||
# Utils/StrMatch
| |||
| |||
A module with a single pattern matching function for strings. Allows comparing a string against a pattern with special characters.
| |||
| |||
## Usage
| |||
| |||
```cpp
| |||
CSimpleStringMatch::SimpleMatchInString("hello.png", "*.png"); // true
| |||
```
| |||
| |||
## Supported Patterns
| |||
| |||
| Character | Meaning | Example |
| |||
|---|---|---|
| |||
| `*` | Any sequence of characters, searches up to the farthest occurrence after the `*` | `*.png` = any .png file |
| |||
| `?` | Exactly one character of any kind | `?.txt` = a.txt, b.txt |
| |||
| `^` | Exactly one digit (0-9) | `file^.csv` = file1.csv |
| |||
| `~` | Any sequence of characters, searches up to the nearest occurrence after the `~` | `~\\` = Only folder of 1 level |
| |||
| |||
Patterns can be combined freely.
| |||
| |||
## Examples
| |||
| |||
```cpp
| |||
SimpleMatchInString("hello_word.png", "*.png"); // true
| |||
SimpleMatchInString("hello_word.png", ".png*"); // false
| |||
SimpleMatchInString("aksdgello", "????gello"); // true
| |||
SimpleMatchInString("123a", "*^^^a"); // false
| |||
SimpleMatchInString("file123.txt", "file^^^.txt"); // true
| |||
SimpleMatchInString("anything", "*"); // true
| |||
SimpleMatchInString("", "*"); // true
| |||
SimpleMatchInString("abc", "??"); // false
| |||
```
| |||
| |||
## Notes
| |||
| |||
- `~~` is not supported as a valid pattern. The character after `~` acts as a sequence terminator.
| |||
- The pattern `~` or `*` only equals "anything" when it stands alone.
|