diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-07-04 20:21:45 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-06 07:39:58 +0200 |
commit | f1c219b6322427fd2d5d97df17fe684fbfe45afa (patch) | |
tree | 379da26a9a06144cbe054dd21a465a39f3f17e9c /src/Conf.cpp | |
parent | 444b5725b125e5154a571a1542cbb5a7ca58e29b (diff) |
Return a string for a getFileData
Diffstat (limited to 'src/Conf.cpp')
-rw-r--r-- | src/Conf.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
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<bool> Config::readFromFile(const _tinydir_char_t *filepath, SibsConfig &config) { - Result<StringView> fileContentResult = getFileContent(filepath); + Result<std::string> fileContentResult = getFileContent(filepath); if(fileContentResult.isErr()) return Result<bool>::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<bool>::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<bool> parseResult = Parser::parse(code, config); + Result<bool> parseResult = Parser::parse(code_ptr, config); if(!parseResult) { string errMsg = "Failed while parsing project.conf for project "; |