Skip to content

Commit 00260d9

Browse files
author
subrata-ms
committed
formatting fix
1 parent 1dcf9ce commit 00260d9

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

mssql_python/pybind/unix_utils.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ std::wstring SQLWCHARToWString(const SQLWCHAR* sqlwStr, size_t length = SQL_NTS)
2727
// Lambda to calculate string length using pointer arithmetic
2828
auto calculateLength = [](const SQLWCHAR* str) -> size_t {
2929
const SQLWCHAR* p = str;
30-
while (*p) ++p;
30+
while (*p)
31+
++p;
3132
return p - str;
3233
};
3334

@@ -41,22 +42,20 @@ std::wstring SQLWCHARToWString(const SQLWCHAR* sqlwStr, size_t length = SQL_NTS)
4142

4243
// Lambda to check if character is in Basic Multilingual Plane
4344
auto isBMP = [](uint16_t ch) { return ch < 0xD800 || ch > 0xDFFF; };
44-
45+
4546
// Lambda to decode surrogate pair into code point
4647
auto decodeSurrogatePair = [](uint16_t high, uint16_t low) -> uint32_t {
47-
return 0x10000 +
48-
(static_cast<uint32_t>(high & 0x3FF) << 10) +
49-
(low & 0x3FF);
48+
return 0x10000 + (static_cast<uint32_t>(high & 0x3FF) << 10) + (low & 0x3FF);
5049
};
5150

5251
// Convert UTF-16 to UTF-32 directly without intermediate buffer
5352
std::wstring result;
5453
result.reserve(length); // Reserve assuming most chars are BMP
55-
54+
5655
size_t i = 0;
5756
while (i < length) {
5857
uint16_t utf16Char = static_cast<uint16_t>(sqlwStr[i]);
59-
58+
6059
// Fast path: BMP character (most common - ~99% of strings)
6160
if (isBMP(utf16Char)) {
6261
result.push_back(static_cast<wchar_t>(utf16Char));
@@ -76,8 +75,7 @@ std::wstring SQLWCHARToWString(const SQLWCHAR* sqlwStr, size_t length = SQL_NTS)
7675
// Invalid surrogate - push as-is
7776
result.push_back(static_cast<wchar_t>(utf16Char));
7877
++i;
79-
}
80-
else { // Low surrogate without high - invalid but push as-is
78+
} else { // Low surrogate without high - invalid but push as-is
8179
result.push_back(static_cast<wchar_t>(utf16Char));
8280
++i;
8381
}
@@ -102,21 +100,21 @@ std::vector<SQLWCHAR> WStringToSQLWCHAR(const std::wstring& str) {
102100
// Convert wstring (UTF-32) to UTF-16
103101
std::vector<SQLWCHAR> result;
104102
result.reserve(str.size() + 1); // Most chars are BMP, so reserve exact size
105-
103+
106104
for (wchar_t wc : str) {
107105
uint32_t codePoint = static_cast<uint32_t>(wc);
108-
106+
109107
// Fast path: BMP character (most common - ~99% of strings)
110108
if (codePoint <= 0xFFFF) {
111109
result.push_back(static_cast<SQLWCHAR>(codePoint));
112-
}
110+
}
113111
// Encode as surrogate pair for characters outside BMP
114112
else if (codePoint <= 0x10FFFF) {
115113
encodeSurrogatePair(result, codePoint);
116114
}
117115
// Invalid code points silently skipped
118116
}
119-
117+
120118
result.push_back(0); // Null terminator
121119
return result;
122120
}

0 commit comments

Comments
 (0)