@@ -28,7 +28,8 @@ std::wstring SQLWCHARToWString(const SQLWCHAR* sqlwStr, size_t length = SQL_NTS)
2828 // Lambda to calculate string length using pointer arithmetic
2929 auto calculateLength = [](const SQLWCHAR* str) -> size_t {
3030 const SQLWCHAR* p = str;
31- while (*p) ++p;
31+ while (*p)
32+ ++p;
3233 return p - str;
3334 };
3435
@@ -42,22 +43,20 @@ std::wstring SQLWCHARToWString(const SQLWCHAR* sqlwStr, size_t length = SQL_NTS)
4243
4344 // Lambda to check if character is in Basic Multilingual Plane
4445 auto isBMP = [](uint16_t ch) { return ch < 0xD800 || ch > 0xDFFF ; };
45-
46+
4647 // Lambda to decode surrogate pair into code point
4748 auto decodeSurrogatePair = [](uint16_t high, uint16_t low) -> uint32_t {
48- return 0x10000 +
49- (static_cast <uint32_t >(high & 0x3FF ) << 10 ) +
50- (low & 0x3FF );
49+ return 0x10000 + (static_cast <uint32_t >(high & 0x3FF ) << 10 ) + (low & 0x3FF );
5150 };
5251
5352 // Convert UTF-16 to UTF-32 directly without intermediate buffer
5453 std::wstring result;
5554 result.reserve (length); // Reserve assuming most chars are BMP
56-
55+
5756 size_t i = 0 ;
5857 while (i < length) {
5958 uint16_t utf16Char = static_cast <uint16_t >(sqlwStr[i]);
60-
59+
6160 // Fast path: BMP character (most common - ~99% of strings)
6261 if (isBMP (utf16Char)) {
6362 result.push_back (static_cast <wchar_t >(utf16Char));
@@ -77,8 +76,7 @@ std::wstring SQLWCHARToWString(const SQLWCHAR* sqlwStr, size_t length = SQL_NTS)
7776 // Invalid surrogate - push as-is
7877 result.push_back (static_cast <wchar_t >(utf16Char));
7978 ++i;
80- }
81- else { // Low surrogate without high - invalid but push as-is
79+ } else { // Low surrogate without high - invalid but push as-is
8280 result.push_back (static_cast <wchar_t >(utf16Char));
8381 ++i;
8482 }
@@ -103,21 +101,21 @@ std::vector<SQLWCHAR> WStringToSQLWCHAR(const std::wstring& str) {
103101 // Convert wstring (UTF-32) to UTF-16
104102 std::vector<SQLWCHAR> result;
105103 result.reserve (str.size () + 1 ); // Most chars are BMP, so reserve exact size
106-
104+
107105 for (wchar_t wc : str) {
108106 uint32_t codePoint = static_cast <uint32_t >(wc);
109-
107+
110108 // Fast path: BMP character (most common - ~99% of strings)
111109 if (codePoint <= 0xFFFF ) {
112110 result.push_back (static_cast <SQLWCHAR>(codePoint));
113- }
111+ }
114112 // Encode as surrogate pair for characters outside BMP
115113 else if (codePoint <= 0x10FFFF ) {
116114 encodeSurrogatePair (result, codePoint);
117115 }
118116 // Invalid code points silently skipped
119117 }
120-
118+
121119 result.push_back (0 ); // Null terminator
122120 return result;
123121}
0 commit comments