diff --git a/.gitignore b/.gitignore index 398a5cc..0ecf603 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,12 @@ *.core *.a *.so +examples/argparse +examples/concurrency examples/coroutine1 examples/coroutine2 examples/format +examples/glob examples/listdir examples/range examples/range_pipe diff --git a/examples/glob.cc b/examples/glob.cc new file mode 100644 index 0000000..95c7278 --- /dev/null +++ b/examples/glob.cc @@ -0,0 +1,130 @@ +/** @example glob.cc + * + * An example of using glob patterns, + */ + +#include + +#include +#include + +using namespace ostd; + +int main() { + writeln("-- all example sources (examples/*.cc) --\n"); + { + auto app = appender>(); + 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>(); + 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>(); + 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>(); + 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>(); + 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>(); + 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 diff --git a/ostd/filesystem.hh b/ostd/filesystem.hh index d4e4f13..b36f7c7 100644 --- a/ostd/filesystem.hh +++ b/ostd/filesystem.hh @@ -17,6 +17,7 @@ * Additionally, it implements glob matching following POSIX with its * own extensions (mainly recursive glob matching via `**`). * + * @include glob.cc * @include listdir.cc * * @copyright See COPYING.md in the project tree for further information.