Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexst07/glob-cpp
Extended globbing in modern C++
https://github.com/alexst07/glob-cpp
cpp-library filesystem glob glob-pattern shell
Last synced: about 1 month ago
JSON representation
Extended globbing in modern C++
- Host: GitHub
- URL: https://github.com/alexst07/glob-cpp
- Owner: alexst07
- License: apache-2.0
- Created: 2019-04-05T01:40:36.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T17:57:50.000Z (about 1 year ago)
- Last Synced: 2023-10-18T18:56:45.890Z (about 1 year ago)
- Topics: cpp-library, filesystem, glob, glob-pattern, shell
- Language: C++
- Size: 95.7 KB
- Stars: 7
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# glob-cpp
------------
Glob CPP is still in development, and more testing needs to be done.
------------Glob CPP is a header only library based on STL regular expression to perform glob operation on string, or on filesystem.
```
?(pattern-list) Matches zero or one occurrence of the given patterns
*(pattern-list) Matches zero or more occurrences of the given patterns
+(pattern-list) Matches one or more occurrences of the given patterns
@(pattern-list) Matches one of the given patterns
!(pattern-list) Matches anything except one of the given patterns
```
## Glob Examples
```
*.jpg : All JPEG files
[A-Z]*.jpg : JPEG files that start with a capital letter
*!(.jpg|.gif) : All files, except JPEGs or GIFs.
```## Examples
### Match with string
Verify is a given string match with glob expression.
```cpp
#include "glob.h"int main () {
glob::glob g("*.pdf");
bool r = glob::glob_match("test.pdf", g);
std::cout << "match: " << r?"yes":"no" << "\n";
return 0;
}
```### Get match substrings
Print the matches found on the target sequence of characters after a glob matching operation.
```cpp
#include "glob.h"int main () {
glob::glob g("*.pdf");
glob::cmatch m;
if (glob::glob_match("test.pdf", m, g)) {
for (auto& token : m) {
std::cout << "sub string: " << token << "\n";
}
}
return 0;
}
```### Get files from match operation in a directory and all match substrings
Given a directory, this example list all files that match with the glob expression. For example:
`*.pdf` get all pdf files in the directory, and `**/*.pdf` get all pdf files in all sub directories.```cpp
#include "file-glob.h"int main () {
glob::file_glob fglob{argv[1]};
std::vector results = fglob.Exec();for (auto& res : results) {
std::cout << "path: " << res.path() << "[";
auto& match_res = res.match_result();
for (auto& token : match_res) {
std::cout << " \"" << token << "\" ";
}
std::cout << "]" << std::endl;
}
return 0;
}
```