mirror of
https://github.com/open-goal/jak-project
synced 2026-08-21 14:54:53 -04:00
lsp: handle line-endings appropriately (#3318)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user