Skip to content

Commit ec27e91

Browse files
clang-format
Apply clang-format-22 across all modified C++ files. No behavioral changes — purely whitespace/wrapping normalisation against the project .clang-format style. Signed-off-by: Christian Parpart <christian@parpart.family>
1 parent 1aaf128 commit ec27e91

45 files changed

Lines changed: 1461 additions & 1491 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Lightweight/CodeGen/SplitFileWriter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ WriteResult EmitChunked(std::filesystem::path const& outputPath,
112112
return result;
113113
}
114114

115-
void EmitPluginCmake(std::filesystem::path const& outputDir,
116-
std::string_view pluginName,
117-
std::string_view sourceGlob)
115+
void EmitPluginCmake(std::filesystem::path const& outputDir, std::string_view pluginName, std::string_view sourceGlob)
118116
{
119117
std::error_code ec;
120118
std::filesystem::create_directories(outputDir, ec);

src/Lightweight/CodeGen/SplitFileWriter.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ struct WriteResult
5555
/// @return `WriteResult` listing the paths actually written.
5656
/// @throws `std::runtime_error` if any output file cannot be opened.
5757
[[nodiscard]] LIGHTWEIGHT_API WriteResult EmitChunked(std::filesystem::path const& outputPath,
58-
std::vector<CodeBlock> const& blocks,
59-
std::size_t maxLinesPerFile,
60-
std::string_view fileHeader = {},
61-
std::string_view fileFooter = {});
58+
std::vector<CodeBlock> const& blocks,
59+
std::size_t maxLinesPerFile,
60+
std::string_view fileHeader = {},
61+
std::string_view fileFooter = {});
6262

6363
/// @brief Writes a `CMakeLists.txt` and a `Plugin.cpp` next to the generated
6464
/// migration sources so the output directory becomes a drop-in plugin.

src/Lightweight/Odbc/DataSourceEnumerator.cpp

Lines changed: 116 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -6,146 +6,150 @@
66
#include <Windows.h> // NOLINT(llvm-include-order) — must precede sqlext.h on Windows.
77
#endif
88

9-
#include <sql.h>
10-
#include <sqlext.h>
11-
129
#include <array>
1310
#include <cstdlib>
1411
#include <cstring>
1512
#include <span>
1613
#include <string_view>
1714

15+
#include <sql.h>
16+
#include <sqlext.h>
17+
1818
namespace Lightweight::Odbc
1919
{
2020

2121
namespace
2222
{
2323

24-
/// RAII wrapper around a scratch `SQL_HANDLE_ENV` used only for enumeration.
25-
///
26-
/// A fresh env handle per call keeps us decoupled from `SqlConnection`'s
27-
/// per-connection env — this matters for the migrations GUI, which may want
28-
/// to refresh the DSN list while a connection is open against a different
29-
/// driver manager configuration.
30-
class ScratchEnv
31-
{
32-
public:
33-
ScratchEnv() noexcept
24+
/// RAII wrapper around a scratch `SQL_HANDLE_ENV` used only for enumeration.
25+
///
26+
/// A fresh env handle per call keeps us decoupled from `SqlConnection`'s
27+
/// per-connection env — this matters for the migrations GUI, which may want
28+
/// to refresh the DSN list while a connection is open against a different
29+
/// driver manager configuration.
30+
class ScratchEnv
3431
{
35-
if (SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &_hEnv) != SQL_SUCCESS)
32+
public:
33+
ScratchEnv() noexcept
3634
{
37-
_hEnv = SQL_NULL_HANDLE;
38-
return;
35+
if (SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &_hEnv) != SQL_SUCCESS)
36+
{
37+
_hEnv = SQL_NULL_HANDLE;
38+
return;
39+
}
40+
// ODBC 3.x is a prerequisite for the driver manager to honour the
41+
// `SQL_FETCH_*` modes used below. Cast matches Microsoft's header
42+
// expectations (integer-as-pointer for environment attributes).
43+
SQLSetEnvAttr(_hEnv,
44+
SQL_ATTR_ODBC_VERSION,
45+
reinterpret_cast<SQLPOINTER>(SQL_OV_ODBC3),
46+
0); // NOLINT(performance-no-int-to-ptr)
3947
}
40-
// ODBC 3.x is a prerequisite for the driver manager to honour the
41-
// `SQL_FETCH_*` modes used below. Cast matches Microsoft's header
42-
// expectations (integer-as-pointer for environment attributes).
43-
SQLSetEnvAttr(
44-
_hEnv, SQL_ATTR_ODBC_VERSION, reinterpret_cast<SQLPOINTER>(SQL_OV_ODBC3), 0); // NOLINT(performance-no-int-to-ptr)
45-
}
46-
47-
~ScratchEnv()
48-
{
49-
if (_hEnv != SQL_NULL_HANDLE)
50-
SQLFreeHandle(SQL_HANDLE_ENV, _hEnv);
51-
}
5248

53-
ScratchEnv(ScratchEnv const&) = delete;
54-
ScratchEnv(ScratchEnv&&) = delete;
55-
ScratchEnv& operator=(ScratchEnv const&) = delete;
56-
ScratchEnv& operator=(ScratchEnv&&) = delete;
57-
58-
[[nodiscard]] SQLHENV Handle() const noexcept
59-
{
60-
return _hEnv;
61-
}
62-
[[nodiscard]] bool Ok() const noexcept
63-
{
64-
return _hEnv != SQL_NULL_HANDLE;
65-
}
66-
67-
private:
68-
SQLHENV _hEnv = SQL_NULL_HANDLE;
69-
};
49+
~ScratchEnv()
50+
{
51+
if (_hEnv != SQL_NULL_HANDLE)
52+
SQLFreeHandle(SQL_HANDLE_ENV, _hEnv);
53+
}
7054

71-
/// Trims trailing NULs / whitespace that some driver managers include when
72-
/// reporting fixed-width DSN fields.
73-
[[nodiscard]] std::string NormalizeBuffer(std::span<SQLCHAR const> buffer) noexcept
74-
{
75-
std::string_view const view { reinterpret_cast<char const*>(buffer.data()), buffer.size() };
76-
auto const firstNul = view.find('\0');
77-
auto const bounded = firstNul == std::string_view::npos ? view : view.substr(0, firstNul);
55+
ScratchEnv(ScratchEnv const&) = delete;
56+
ScratchEnv(ScratchEnv&&) = delete;
57+
ScratchEnv& operator=(ScratchEnv const&) = delete;
58+
ScratchEnv& operator=(ScratchEnv&&) = delete;
7859

79-
auto const last = bounded.find_last_not_of(" \t\r\n");
80-
if (last == std::string_view::npos)
81-
return {};
82-
return std::string { bounded.substr(0, last + 1) };
83-
}
84-
85-
/// Parses a driver attributes buffer — a double-NUL-terminated sequence of
86-
/// `KEY=VALUE\0KEY=VALUE\0\0` entries — into a vector of key/value pairs.
87-
[[nodiscard]] std::vector<std::pair<std::string, std::string>> ParseDriverAttributes(
88-
std::span<SQLCHAR const> buffer) noexcept
89-
{
90-
std::vector<std::pair<std::string, std::string>> attributes;
60+
[[nodiscard]] SQLHENV Handle() const noexcept
61+
{
62+
return _hEnv;
63+
}
64+
[[nodiscard]] bool Ok() const noexcept
65+
{
66+
return _hEnv != SQL_NULL_HANDLE;
67+
}
9168

92-
char const* cursor = reinterpret_cast<char const*>(buffer.data());
93-
char const* const end = cursor + buffer.size();
69+
private:
70+
SQLHENV _hEnv = SQL_NULL_HANDLE;
71+
};
9472

95-
while (cursor < end && *cursor != '\0')
73+
/// Trims trailing NULs / whitespace that some driver managers include when
74+
/// reporting fixed-width DSN fields.
75+
[[nodiscard]] std::string NormalizeBuffer(std::span<SQLCHAR const> buffer) noexcept
9676
{
97-
std::string_view const entry { cursor, std::strlen(cursor) };
98-
if (auto const eq = entry.find('='); eq != std::string_view::npos)
99-
attributes.emplace_back(std::string { entry.substr(0, eq) }, std::string { entry.substr(eq + 1) });
100-
else
101-
attributes.emplace_back(std::string { entry }, std::string {});
102-
cursor += entry.size() + 1;
77+
std::string_view const view { reinterpret_cast<char const*>(buffer.data()), buffer.size() };
78+
auto const firstNul = view.find('\0');
79+
auto const bounded = firstNul == std::string_view::npos ? view : view.substr(0, firstNul);
80+
81+
auto const last = bounded.find_last_not_of(" \t\r\n");
82+
if (last == std::string_view::npos)
83+
return {};
84+
return std::string { bounded.substr(0, last + 1) };
10385
}
10486

105-
return attributes;
106-
}
87+
/// Parses a driver attributes buffer — a double-NUL-terminated sequence of
88+
/// `KEY=VALUE\0KEY=VALUE\0\0` entries — into a vector of key/value pairs.
89+
[[nodiscard]] std::vector<std::pair<std::string, std::string>> ParseDriverAttributes(
90+
std::span<SQLCHAR const> buffer) noexcept
91+
{
92+
std::vector<std::pair<std::string, std::string>> attributes;
10793

108-
/// Runs a single `SQLDataSources` scan pass (user or system) and appends its
109-
/// results to `out`. Stops on the first non-success / non-info return code,
110-
/// which matches the driver manager's end-of-iteration contract.
111-
void EnumerateDataSourcesPass(SQLHENV hEnv, SQLUSMALLINT fetchType, DataSourceInfo::Scope scope,
112-
std::vector<DataSourceInfo>& out)
113-
{
114-
constexpr SQLSMALLINT NameBufferSize = SQL_MAX_DSN_LENGTH + 1;
115-
constexpr SQLSMALLINT DescriptionBufferSize = 256;
94+
char const* cursor = reinterpret_cast<char const*>(buffer.data());
95+
char const* const end = cursor + buffer.size();
11696

117-
std::array<SQLCHAR, NameBufferSize> nameBuf {};
118-
std::array<SQLCHAR, DescriptionBufferSize> descBuf {};
119-
SQLSMALLINT nameLen = 0;
120-
SQLSMALLINT descLen = 0;
97+
while (cursor < end && *cursor != '\0')
98+
{
99+
std::string_view const entry { cursor, std::strlen(cursor) };
100+
if (auto const eq = entry.find('='); eq != std::string_view::npos)
101+
attributes.emplace_back(std::string { entry.substr(0, eq) }, std::string { entry.substr(eq + 1) });
102+
else
103+
attributes.emplace_back(std::string { entry }, std::string {});
104+
cursor += entry.size() + 1;
105+
}
121106

122-
SQLRETURN rc = SQLDataSources(hEnv,
123-
fetchType,
124-
nameBuf.data(),
125-
static_cast<SQLSMALLINT>(nameBuf.size()),
126-
&nameLen,
127-
descBuf.data(),
128-
static_cast<SQLSMALLINT>(descBuf.size()),
129-
&descLen);
130-
while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO)
131-
{
132-
out.push_back(DataSourceInfo {
133-
.name = NormalizeBuffer(std::span<SQLCHAR const> { nameBuf.data(), static_cast<size_t>(nameLen) }),
134-
.description = NormalizeBuffer(std::span<SQLCHAR const> { descBuf.data(), static_cast<size_t>(descLen) }),
135-
.scope = scope,
136-
});
107+
return attributes;
108+
}
137109

138-
// Every pass after the first on the same fetchType wants FETCH_NEXT.
139-
rc = SQLDataSources(hEnv,
140-
SQL_FETCH_NEXT,
141-
nameBuf.data(),
142-
static_cast<SQLSMALLINT>(nameBuf.size()),
143-
&nameLen,
144-
descBuf.data(),
145-
static_cast<SQLSMALLINT>(descBuf.size()),
146-
&descLen);
110+
/// Runs a single `SQLDataSources` scan pass (user or system) and appends its
111+
/// results to `out`. Stops on the first non-success / non-info return code,
112+
/// which matches the driver manager's end-of-iteration contract.
113+
void EnumerateDataSourcesPass(SQLHENV hEnv,
114+
SQLUSMALLINT fetchType,
115+
DataSourceInfo::Scope scope,
116+
std::vector<DataSourceInfo>& out)
117+
{
118+
constexpr SQLSMALLINT NameBufferSize = SQL_MAX_DSN_LENGTH + 1;
119+
constexpr SQLSMALLINT DescriptionBufferSize = 256;
120+
121+
std::array<SQLCHAR, NameBufferSize> nameBuf {};
122+
std::array<SQLCHAR, DescriptionBufferSize> descBuf {};
123+
SQLSMALLINT nameLen = 0;
124+
SQLSMALLINT descLen = 0;
125+
126+
SQLRETURN rc = SQLDataSources(hEnv,
127+
fetchType,
128+
nameBuf.data(),
129+
static_cast<SQLSMALLINT>(nameBuf.size()),
130+
&nameLen,
131+
descBuf.data(),
132+
static_cast<SQLSMALLINT>(descBuf.size()),
133+
&descLen);
134+
while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO)
135+
{
136+
out.push_back(DataSourceInfo {
137+
.name = NormalizeBuffer(std::span<SQLCHAR const> { nameBuf.data(), static_cast<size_t>(nameLen) }),
138+
.description = NormalizeBuffer(std::span<SQLCHAR const> { descBuf.data(), static_cast<size_t>(descLen) }),
139+
.scope = scope,
140+
});
141+
142+
// Every pass after the first on the same fetchType wants FETCH_NEXT.
143+
rc = SQLDataSources(hEnv,
144+
SQL_FETCH_NEXT,
145+
nameBuf.data(),
146+
static_cast<SQLSMALLINT>(nameBuf.size()),
147+
&nameLen,
148+
descBuf.data(),
149+
static_cast<SQLSMALLINT>(descBuf.size()),
150+
&descLen);
151+
}
147152
}
148-
}
149153

150154
} // namespace
151155

src/Lightweight/QueryFormatter/SQLiteFormatter.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,7 @@ class SQLiteQueryFormatter: public SqlQueryFormatter
404404
}
405405

406406
private:
407-
[[nodiscard]] std::string FormatAlterTableCommand(std::string_view tableName,
408-
SqlAlterTableCommand const& command) const
407+
[[nodiscard]] std::string FormatAlterTableCommand(std::string_view tableName, SqlAlterTableCommand const& command) const
409408
{
410409
auto const formatTable = [tableName]() {
411410
return std::format(R"("{}")", tableName);

src/Lightweight/QueryFormatter/SqlServerFormatter.hpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,14 @@ EXEC sp_executesql @sql;)",
121121
/// encoder always makes forward progress.
122122
static constexpr std::size_t Utf8SequenceLength(unsigned char c) noexcept
123123
{
124-
if (c < 0x80) return 1;
125-
if (c < 0xC0) return 1; // stray continuation; treat as 1 to advance
126-
if (c < 0xE0) return 2;
127-
if (c < 0xF0) return 3;
124+
if (c < 0x80)
125+
return 1;
126+
if (c < 0xC0)
127+
return 1; // stray continuation; treat as 1 to advance
128+
if (c < 0xE0)
129+
return 2;
130+
if (c < 0xF0)
131+
return 3;
128132
return 4;
129133
}
130134

@@ -140,10 +144,18 @@ EXEC sp_executesql @sql;)",
140144
auto const lead = static_cast<unsigned char>(s[i]);
141145
switch (len)
142146
{
143-
case 2: cp = lead & 0x1F; break;
144-
case 3: cp = lead & 0x0F; break;
145-
case 4: cp = lead & 0x07; break;
146-
default: cp = lead; break; // unreachable given the early-return above
147+
case 2:
148+
cp = lead & 0x1F;
149+
break;
150+
case 3:
151+
cp = lead & 0x0F;
152+
break;
153+
case 4:
154+
cp = lead & 0x07;
155+
break;
156+
default:
157+
cp = lead;
158+
break; // unreachable given the early-return above
147159
}
148160
for (std::size_t k = 1; k < len; ++k)
149161
cp = (cp << 6) | (static_cast<unsigned char>(s[i + k]) & 0x3F);
@@ -219,7 +231,6 @@ EXEC sp_executesql @sql;)",
219231
}
220232

221233
public:
222-
223234
[[nodiscard]] std::string QualifiedTableName(std::string_view schema, std::string_view table) const override
224235
{
225236
if (schema.empty())

0 commit comments

Comments
 (0)