Skip to content

Commit

Permalink
indexer: change Pos computation from byte offset to UTF-8 encoded cod…
Browse files Browse the repository at this point in the history
…e point offset
  • Loading branch information
MaskRay committed Oct 24, 2019
1 parent bf05ec4 commit 136639c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/clang_tu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ static Pos Decomposed2LineAndCol(const SourceManager &SM,
std::pair<FileID, unsigned> I) {
int l = (int)SM.getLineNumber(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),
(int16_t)std::min<int>(c, INT16_MAX)};
}
Expand Down

0 comments on commit 136639c

Please sign in to comment.