forked from OctaForge/libostd
add glob example
This commit is contained in:
parent
cca5952f93
commit
bee56e6a52
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,9 +2,12 @@
|
||||||
*.core
|
*.core
|
||||||
*.a
|
*.a
|
||||||
*.so
|
*.so
|
||||||
|
examples/argparse
|
||||||
|
examples/concurrency
|
||||||
examples/coroutine1
|
examples/coroutine1
|
||||||
examples/coroutine2
|
examples/coroutine2
|
||||||
examples/format
|
examples/format
|
||||||
|
examples/glob
|
||||||
examples/listdir
|
examples/listdir
|
||||||
examples/range
|
examples/range
|
||||||
examples/range_pipe
|
examples/range_pipe
|
||||||
|
|
130
examples/glob.cc
Normal file
130
examples/glob.cc
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
/** @example glob.cc
|
||||||
|
*
|
||||||
|
* An example of using glob patterns,
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <ostd/io.hh>
|
||||||
|
#include <ostd/filesystem.hh>
|
||||||
|
|
||||||
|
using namespace ostd;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
writeln("-- all example sources (examples/*.cc) --\n");
|
||||||
|
{
|
||||||
|
auto app = appender<std::vector<filesystem::path>>();
|
||||||
|
glob_match(app, "examples/*.cc");
|
||||||
|
|
||||||
|
for (auto &ex: app.get()) {
|
||||||
|
writefln("found: %s", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeln("\n-- recursive source files (src/**/*.cc) --\n");
|
||||||
|
{
|
||||||
|
auto app = appender<std::vector<filesystem::path>>();
|
||||||
|
glob_match(app, "src/**/*.cc");
|
||||||
|
|
||||||
|
for (auto &ex: app.get()) {
|
||||||
|
writefln("found: %s", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeln("\n-- 5-character headers (ostd/?????.hh) --\n");
|
||||||
|
{
|
||||||
|
auto app = appender<std::vector<filesystem::path>>();
|
||||||
|
glob_match(app, "ostd/?????.hh");
|
||||||
|
|
||||||
|
for (auto &ex: app.get()) {
|
||||||
|
writefln("found: %s", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeln("\n-- examples starting with f-r (examples/[f-r]*.cc) --\n");
|
||||||
|
{
|
||||||
|
auto app = appender<std::vector<filesystem::path>>();
|
||||||
|
glob_match(app, "examples/[f-r]*.cc");
|
||||||
|
|
||||||
|
for (auto &ex: app.get()) {
|
||||||
|
writefln("found: %s", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeln("\n-- examples not starting with f-r (examples/[!f-r]*.cc) --\n");
|
||||||
|
{
|
||||||
|
auto app = appender<std::vector<filesystem::path>>();
|
||||||
|
glob_match(app, "examples/[!f-r]*.cc");
|
||||||
|
|
||||||
|
for (auto &ex: app.get()) {
|
||||||
|
writefln("found: %s", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeln("\n-- headers starting with c, f or s (ostd/[cfs]*.hh) --\n");
|
||||||
|
{
|
||||||
|
auto app = appender<std::vector<filesystem::path>>();
|
||||||
|
glob_match(app, "ostd/[cfs]*.hh");
|
||||||
|
|
||||||
|
for (auto &ex: app.get()) {
|
||||||
|
writefln("found: %s", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// output:
|
||||||
|
// -- all example sources (examples/*.cc) --
|
||||||
|
//
|
||||||
|
// found: examples/format.cc
|
||||||
|
// found: examples/stream2.cc
|
||||||
|
// found: examples/stream1.cc
|
||||||
|
// found: examples/glob.cc
|
||||||
|
// found: examples/coroutine1.cc
|
||||||
|
// found: examples/range.cc
|
||||||
|
// found: examples/signal.cc
|
||||||
|
// found: examples/argparse.cc
|
||||||
|
// found: examples/range_pipe.cc
|
||||||
|
// found: examples/listdir.cc
|
||||||
|
// found: examples/concurrency.cc
|
||||||
|
// found: examples/coroutine2.cc
|
||||||
|
//
|
||||||
|
// -- recursive source files (src/**/*.cc) --
|
||||||
|
//
|
||||||
|
// found: src/context_stack.cc
|
||||||
|
// found: src/io.cc
|
||||||
|
// found: src/process.cc
|
||||||
|
// found: src/concurrency.cc
|
||||||
|
// found: src/environ.cc
|
||||||
|
// found: src/posix/context_stack.cc
|
||||||
|
// found: src/posix/process.cc
|
||||||
|
// found: src/win32/context_stack.cc
|
||||||
|
// found: src/win32/process.cc
|
||||||
|
//
|
||||||
|
// -- 5-character headers (ostd/?????.hh) --
|
||||||
|
//
|
||||||
|
// found: ostd/range.hh
|
||||||
|
// found: ostd/event.hh
|
||||||
|
//
|
||||||
|
// -- examples starting with f-r (examples/[f-r]*.cc) --
|
||||||
|
//
|
||||||
|
// found: examples/format.cc
|
||||||
|
// found: examples/glob.cc
|
||||||
|
// found: examples/range.cc
|
||||||
|
// found: examples/range_pipe.cc
|
||||||
|
// found: examples/listdir.cc
|
||||||
|
//
|
||||||
|
// -- examples not starting with f-r (examples/[!f-r]*.cc) --
|
||||||
|
//
|
||||||
|
// found: examples/stream2.cc
|
||||||
|
// found: examples/stream1.cc
|
||||||
|
// found: examples/coroutine1.cc
|
||||||
|
// found: examples/signal.cc
|
||||||
|
// found: examples/argparse.cc
|
||||||
|
// found: examples/concurrency.cc
|
||||||
|
// found: examples/coroutine2.cc
|
||||||
|
//
|
||||||
|
// -- headers starting with c, f or s (ostd/[cfs]*.hh) --
|
||||||
|
//
|
||||||
|
// found: ostd/context_stack.hh
|
||||||
|
// found: ostd/channel.hh
|
||||||
|
// found: ostd/format.hh
|
||||||
|
// found: ostd/string.hh
|
||||||
|
// found: ostd/stream.hh
|
||||||
|
// found: ostd/concurrency.hh
|
||||||
|
// found: ostd/coroutine.hh
|
||||||
|
// found: ostd/filesystem.hh
|
|
@ -17,6 +17,7 @@
|
||||||
* Additionally, it implements glob matching following POSIX with its
|
* Additionally, it implements glob matching following POSIX with its
|
||||||
* own extensions (mainly recursive glob matching via `**`).
|
* own extensions (mainly recursive glob matching via `**`).
|
||||||
*
|
*
|
||||||
|
* @include glob.cc
|
||||||
* @include listdir.cc
|
* @include listdir.cc
|
||||||
*
|
*
|
||||||
* @copyright See COPYING.md in the project tree for further information.
|
* @copyright See COPYING.md in the project tree for further information.
|
||||||
|
|
Loading…
Reference in a new issue