mirror of
https://github.com/MaskRay/ccls.git
synced 2024-12-01 20:07:08 +00:00
indexer: change Pos computation from byte offset to UTF-8 encoded code point offset
This commit is contained in:
parent
7bc952e543
commit
4f9e7b219e
@ -33,6 +33,16 @@ static Pos Decomposed2LineAndCol(const SourceManager &SM,
|
|||||||
std::pair<FileID, unsigned> I) {
|
std::pair<FileID, unsigned> I) {
|
||||||
int l = (int)SM.getLineNumber(I.first, I.second) - 1,
|
int l = (int)SM.getLineNumber(I.first, I.second) - 1,
|
||||||
c = (int)SM.getColumnNumber(I.first, I.second) - 1;
|
c = (int)SM.getColumnNumber(I.first, I.second) - 1;
|
||||||
|
bool Invalid = false;
|
||||||
|
StringRef Buf = SM.getBufferData(I.first, &Invalid);
|
||||||
|
if (!Invalid) {
|
||||||
|
StringRef P = Buf.substr(I.second - c, c);
|
||||||
|
c = 0;
|
||||||
|
for (size_t i = 0; i < P.size(); )
|
||||||
|
if (c++, (uint8_t)P[i++] >= 128)
|
||||||
|
while (i < P.size() && (uint8_t)P[i] >= 128 && (uint8_t)P[i] < 192)
|
||||||
|
i++;
|
||||||
|
}
|
||||||
return {(int16_t)std::min<int>(l, INT16_MAX),
|
return {(int16_t)std::min<int>(l, INT16_MAX),
|
||||||
(int16_t)std::min<int>(c, INT16_MAX)};
|
(int16_t)std::min<int>(c, INT16_MAX)};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user