util: split bom checking to a separate fn (#6694)

pull/6715/head
Ned Palacios 2020-10-30 00:21:08 +08:00 committed by GitHub
parent be02ee97fb
commit 7b5a580c0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -223,9 +223,14 @@ pub fn path_of_executable(path string) string {
}
pub fn read_file(file_path string) ?string {
mut raw_text := os.read_file(file_path) or {
raw_text := os.read_file(file_path) or {
return error('failed to open $file_path')
}
return skip_bom(raw_text)
}
pub fn skip_bom(file_content string) string {
mut raw_text := file_content
// BOM check
if raw_text.len >= 3 {
unsafe {