mirror of
https://github.com/MaskRay/ccls.git
synced 2025-06-07 16:54:54 +00:00
Treat \r\n, \r, \n all as markers of end of line.
This commit is contained in:
parent
00158e2150
commit
b9f14db942
@ -57,10 +57,23 @@ Position GetPositionForOffset(const std::string &content, int offset) {
|
||||
|
||||
std::vector<std::string> ToLines(const std::string &content) {
|
||||
std::vector<std::string> result;
|
||||
std::istringstream lines(content);
|
||||
std::string line;
|
||||
while (getline(lines, line))
|
||||
result.push_back(line);
|
||||
size_t startPos = 0;
|
||||
while (startPos < content.size()) {
|
||||
// \r or \n
|
||||
size_t endPos = content.find_first_of("\r\n", startPos);
|
||||
if (endPos == std::string::npos) {
|
||||
// EOF
|
||||
result.push_back(content.substr(startPos));
|
||||
break;
|
||||
}
|
||||
result.push_back(content.substr(startPos, endPos - startPos));
|
||||
if (content[endPos] == '\r' && endPos < content.size() - 1 &&
|
||||
content[endPos + 1] == '\n') {
|
||||
// \r\n
|
||||
endPos++;
|
||||
}
|
||||
startPos = endPos + 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user