lsp: handle line-endings appropriately (#3318)

This commit is contained in:
Tyler Wilding
2024-01-18 20:32:30 -05:00
committed by GitHub
parent c3e4baf697
commit 272cb32a45
6 changed files with 60 additions and 17 deletions
+20
View File
@@ -706,4 +706,24 @@ std::string make_screenshot_filepath(const GameVersion game_version, const std::
return file_path;
}
std::string get_majority_file_line_endings(const std::string& file_contents) {
size_t lf_count = 0;
size_t crlf_count = 0;
for (size_t i = 0; i < file_contents.size(); ++i) {
if (file_contents[i] == '\n') {
if (i > 0 && file_contents[i - 1] == '\r') {
crlf_count++;
} else {
lf_count++;
}
}
}
if (crlf_count > lf_count) {
return "\r\n";
}
return "\n";
}
} // namespace file_util