Skip to content

Commit 4d14932

Browse files
committed
Moved commit "Fixed PG error positions" from ydb repo
1 parent 0b11343 commit 4d14932

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

include/ydb-cpp-sdk/library/yql_common/issue/yql_issue.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ struct TPosition {
5858

5959
class TTextWalker {
6060
public:
61-
TTextWalker(TPosition& position)
61+
TTextWalker(TPosition& position, bool utf8Aware)
6262
: Position(position)
63+
, Utf8Aware(utf8Aware)
6364
, HaveCr(false)
6465
, LfCount(0)
6566
{
6667
}
6768

69+
static inline bool IsUtf8Intermediate(char c) {
70+
return (c & 0xC0) == 0x80;
71+
}
72+
6873
template<typename T>
6974
TTextWalker& Advance(const T& buf) {
7075
for (char c : buf) {
@@ -77,6 +82,7 @@ class TTextWalker {
7782

7883
private:
7984
TPosition& Position;
85+
const bool Utf8Aware;
8086
bool HaveCr;
8187
uint32_t LfCount;
8288
};

src/library/yql_common/issue/yql_issue.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void SanitizeNonAscii(std::string& s) {
2424
const unsigned char* i = reinterpret_cast<const unsigned char*>(s.data());
2525
const unsigned char* end = i + s.size();
2626
while (i < end) {
27-
wchar32 rune;
27+
char32_t rune;
2828
size_t runeLen;
2929
const RECODE_RESULT result = SafeReadUTF8Char(rune, runeLen, i, end);
3030
if (result == RECODE_OK) {
@@ -52,13 +52,18 @@ TTextWalker& TTextWalker::Advance(char c) {
5252
return *this;
5353
}
5454

55+
uint32_t charDistance = 1;
56+
if (Utf8Aware && IsUtf8Intermediate(c)) {
57+
charDistance = 0;
58+
}
59+
5560
// either not '\r' or second '\r'
5661
if (LfCount) {
5762
Position.Row += LfCount;
58-
Position.Column = 1;
63+
Position.Column = charDistance;
5964
LfCount = 0;
6065
} else {
61-
Position.Column += 1 + (HaveCr && c != '\r');
66+
Position.Column += charDistance + (HaveCr && c != '\r');
6267
}
6368
HaveCr = (c == '\r');
6469
return *this;

0 commit comments

Comments
 (0)