1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os.read_file(): replace C code with V, return ?string, handle errors

everywhere
This commit is contained in:
Alexander Medvednikov
2019-06-26 10:57:13 +02:00
parent b00a47be66
commit 8417fec5dc
3 changed files with 30 additions and 17 deletions

View File

@ -32,9 +32,13 @@ fn new_scanner(file_path string) *Scanner {
if !os.file_exists(file_path) {
panic('"$file_path" doesn\'t exist')
}
text := os.read_file(file_path) or {
panic('scanner: failed to open "$file_path"')
return &Scanner{}
}
scanner := &Scanner {
file_path: file_path
text: os.read_file(file_path)
text: text
fmt_out: new_string_builder(1000)
}
// println('new scanner "$file_path" txt.len=$scanner.text.len')