mirror of
https://github.com/MaskRay/ccls.git
synced 2025-06-08 01:04: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> ToLines(const std::string &content) {
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
std::istringstream lines(content);
|
size_t startPos = 0;
|
||||||
std::string line;
|
while (startPos < content.size()) {
|
||||||
while (getline(lines, line))
|
// \r or \n
|
||||||
result.push_back(line);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user