added examples

This commit is contained in:
Dummi26 2023-03-22 19:37:21 +01:00
parent 2c12556af9
commit 296163d5fe
2 changed files with 61 additions and 0 deletions

13
regex.txt Normal file
View File

@ -0,0 +1,13 @@
pot_dates = "2014-01-01 201-02-05 2022-09-05"
for v pot_dates.regex("\\d{4}-\\d{2}-\\d{2}").0.assume1() v.println()
reg = pot_dates.regex("\\t\\h\\is is not a regex")
match reg {
reg.0 {
"regex matches:".println()
for reg reg reg.println()
}
true "not a valid regex!".println()
}

48
search_dirs.txt Normal file
View File

@ -0,0 +1,48 @@
println("Which directory do you want to scan?")
dir = read_line()
println("How deep should I search?")
depth = while {
depth = read_line().parse_int()
switch! depth {
[] {
println("depth wasn't an integer!")
[]
}
int if depth.gtoe(0) {
// break from loop with value depth
[depth]
} else {
// depth < 0
println("depth was negative!")
[]
}
}
}
"Searching in {0} with a maximum depth of {1}...".format(dir depth).println()
fn find_all_files(dir string max_depth int) {
files = ["" ...]
&files.pop()
entries = dir.fs_list()
depth = 0
while {
new = ["" ...] // set type string
&new.pop()
for entry entries {
local_entries = entry.fs_list()
switch! local_entries {
[] &files.push(entry)
[string] for entry entry.fs_list() {
&new.push(entry)
}
}
}
entries = new
depth = depth.add(1)
if depth.gt(max_depth) [files] else []
}
}
all_files = find_all_files(dir depth)
for file all_files file.println()