55 lines
1.7 KiB
Markdown
55 lines
1.7 KiB
Markdown
# std::io::glob
|
|||
|
|
|
||
|
|
`std::io::glob` reads globs, paths written with wildcards as
|
||
|
|
`src/**/*.sakura`, and matches paths against them or finds the files they name.
|
||
|
|
`*` matches any run of characters within a name, `?` any one, `[abc]` and
|
||
|
|
`[a-z]` one of a set, `[!abc]` one not in it, `**` as a whole name any number of
|
||
|
|
whole names, and `{a,b}` either. `\` takes away what the next character means.
|
||
|
|
`/` separates names on every system, Windows included, and a name starting with
|
||
|
|
`.` is matched only by one written so, unless the options say otherwise. Cases
|
||
|
|
are told apart on Linux and folded elsewhere, unless the options say otherwise.
|
||
|
|
|
||
|
|
`pattern::find` walks no further than a glob's names need, never follows a link
|
||
|
|
`**` would descend, and gives what it finds in the order of their bytes, as a
|
||
|
|
shell does. blossom expands a target's `srcs` with it.
|
||
|
|
|
||
|
|
It's a module within `std::io`, whose paths it matches, so the library `std.io`
|
||
|
|
holds it, and it sees `std::io`'s names without importing it.
|
||
|
|
|
||
|
|
## Using it
|
||
|
|
|
||
|
|
Require the standard library in your blossomfile, and name `std.io`, the library
|
||
|
|
holding it, among a target's `deps`:
|
||
|
|
|
||
|
|
```yaml
|
||
|
|
requires:
|
||
|
|
- https://git.malunal.studio/sakura/std@v1.0.0
|
||
|
|
|
||
|
|
targets:
|
||
|
|
- name: app
|
||
|
|
type: program
|
||
|
|
deps: [std.io]
|
||
|
|
```
|
||
|
|
|
||
|
|
```sakura
|
||
|
|
import std::io;
|
||
|
|
import std::io::glob;
|
||
|
|
|
||
|
|
def main(): void {
|
||
|
|
val sources := glob::pattern::parse("src/**/*.sakura") else (_) { return; };
|
||
|
|
val root := path::parse(".") else (_) { return; };
|
||
|
|
val found := sources.find(&root) else (_) { return; };
|
||
|
|
for &each in found {
|
||
|
|
io::println(each.span);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
## Testing
|
||
|
|
|
||
|
|
From the standard library's root, `blossom test --suite std.io` runs them with the
|
||
|
|
rest of `std::io`'s, or:
|
||
|
|
|
||
|
|
```sh
|
||
|
|
sakurac run --lib std=. tests/main.sakura tests/io/*.sakura tests/io/glob/*.sakura
|
||
|
|
```
|