Skip to content

Commit e22f856

Browse files
committed
fix(core): improve Windows compatibility and fix formatting issues
- remove invalid noexcept in format size estimation - add cross-platform fallback for Unicode box drawing in print - replace unsafe getenv usage for Windows compatibility - fix encoding-related warnings on MSVC
1 parent faca0e2 commit e22f856

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

include/vix/format/Format.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ namespace vix
280280
* @return Estimated output size.
281281
*/
282282
[[nodiscard]] inline std::size_t estimate_output_size(std::string_view fmt,
283-
const rendered_arg_list &args) noexcept
283+
const rendered_arg_list &args)
284284
{
285285
std::size_t total = fmt.size();
286286
for (std::size_t i = 0; i < args.size(); ++i)

include/vix/print/Print.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,21 @@ namespace vix
219219
os << static_cast<std::underlying_type_t<E>>(e);
220220
}
221221

222+
#ifdef _WIN32
223+
inline constexpr const char *kBoxTopLeft = "+";
224+
inline constexpr const char *kBoxTopRight = "+";
225+
inline constexpr const char *kBoxBottomLeft = "+";
226+
inline constexpr const char *kBoxBottomRight = "+";
227+
inline constexpr const char *kBoxHorizontal = "-";
228+
inline constexpr const char *kBoxVertical = "|";
229+
#else
230+
inline constexpr const char *kBoxTopLeft = "\u250C";
231+
inline constexpr const char *kBoxTopRight = "\u2510";
232+
inline constexpr const char *kBoxBottomLeft = "\u2514";
233+
inline constexpr const char *kBoxBottomRight = "\u2518";
234+
inline constexpr const char *kBoxHorizontal = "\u2500";
235+
inline constexpr const char *kBoxVertical = "\u2502";
236+
#endif
222237
// write_duration
223238
template <typename Rep, typename Period>
224239
void write_duration(std::ostream &os,
@@ -233,7 +248,11 @@ namespace vix
233248
}
234249
else if constexpr (std::is_same_v<Period, std::micro>)
235250
{
251+
#ifdef _WIN32
252+
os << d.count() << "us";
253+
#else
236254
os << d.count() << "µs";
255+
#endif
237256
}
238257
else if constexpr (std::is_same_v<Period, std::milli>)
239258
{

src/config/Config.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
#include <vix/config/Config.hpp>
15+
#include <vix/utils/Env.hpp>
1516

1617
#include <cstdlib>
1718
#include <fstream>
@@ -124,17 +125,17 @@ namespace vix::config
124125

125126
std::string Config::getDbPasswordFromEnv()
126127
{
127-
if (const char *value = std::getenv("VIX_DB_PASSWORD"); value && *value != '\0')
128+
if (const char *value = vix::utils::vix_getenv("VIX_DB_PASSWORD"); value && *value != '\0')
128129
{
129130
return std::string(value);
130131
}
131132

132-
if (const char *value = std::getenv("DB_PASSWORD"); value && *value != '\0')
133+
if (const char *value = vix::utils::vix_getenv("DB_PASSWORD"); value && *value != '\0')
133134
{
134135
return std::string(value);
135136
}
136137

137-
if (const char *value = std::getenv("MYSQL_PASSWORD"); value && *value != '\0')
138+
if (const char *value = vix::utils::vix_getenv("MYSQL_PASSWORD"); value && *value != '\0')
138139
{
139140
return std::string(value);
140141
}

0 commit comments

Comments
 (0)