From f1c219b6322427fd2d5d97df17fe684fbfe45afa Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 4 Jul 2020 20:21:45 +0200 Subject: Return a string for a getFileData --- src/Conf.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/Conf.cpp') diff --git a/src/Conf.cpp b/src/Conf.cpp index dc9c406..74c311c 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -463,19 +463,20 @@ namespace sibs Result Config::readFromFile(const _tinydir_char_t *filepath, SibsConfig &config) { - Result fileContentResult = getFileContent(filepath); + Result fileContentResult = getFileContent(filepath); if(fileContentResult.isErr()) return Result::Err(fileContentResult.getErrMsg()); - const char *code = fileContentResult.unwrap().data; - if(!utf8::is_valid(code, code + fileContentResult.unwrap().size)) + const std::string &code = fileContentResult.unwrap(); + if(!utf8::is_valid(code.data(), code.data() + code.size())) return Result::Err("File is not in valid utf8 format"); - if(fileContentResult.unwrap().size >= 3 && utf8::is_bom(code)) - code += 3; + const char *code_ptr = code.data(); + if(code.size() >= 3 && utf8::is_bom(code_ptr)) + code_ptr += 3; // Do not free file content (fileContentResult) on purpose, since we are using the data and sibs is short lived - Result parseResult = Parser::parse(code, config); + Result parseResult = Parser::parse(code_ptr, config); if(!parseResult) { string errMsg = "Failed while parsing project.conf for project "; -- cgit v1.2.3