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/main.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 3d11fd5..0cb55e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -793,26 +793,24 @@ static Result gitInitProject(const FileString &projectPath) static bool gitIgnoreContainsSibs(const FileString &gitIgnoreFilePath) { - Result fileContentResult = getFileContent(gitIgnoreFilePath.c_str()); + Result fileContentResult = getFileContent(gitIgnoreFilePath.c_str()); if(!fileContentResult) return false; - StringView fileContent = fileContentResult.unwrap(); - const char *fileContentEnd = fileContent.data + fileContent.size; - auto it = std::search(fileContent.data, fileContentEnd, SIBS_GITIGNORE_HEADER.begin(), SIBS_GITIGNORE_HEADER.end()); + const std::string &fileContent = fileContentResult.unwrap(); + const char *fileContentEnd = fileContent.data() + fileContent.size(); + auto it = std::search(fileContent.data(), fileContentEnd, SIBS_GITIGNORE_HEADER.begin(), SIBS_GITIGNORE_HEADER.end()); bool containsSibs = it != fileContentEnd; - free((void*)fileContent.data); return containsSibs; } static void gitIgnoreAppendSibs(const FileString &gitIgnoreFilePath) { - Result fileContentResult = getFileContent(gitIgnoreFilePath.c_str()); + Result fileContentResult = getFileContent(gitIgnoreFilePath.c_str()); string fileContentNew; if(fileContentResult) { - StringView fileContent = fileContentResult.unwrap(); - fileContentNew.append(fileContent.data, fileContent.data + fileContent.size); + const std::string &fileContent = fileContentResult.unwrap(); + fileContentNew += fileContent; fileContentNew += "\n\n"; - free((void*)fileContent.data); } fileContentNew += SIBS_GITIGNORE_HEADER; fileContentNew += "\n"; -- cgit v1.2.3