From 7b5a580c0c7b6f181ec06566b4fc3b9f14a9134e Mon Sep 17 00:00:00 2001 From: Ned Palacios Date: Fri, 30 Oct 2020 00:21:08 +0800 Subject: [PATCH] util: split bom checking to a separate fn (#6694) --- vlib/v/util/util.v | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 39d0e385ef..a8a86956db 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -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 {