Browse Source

Load locales so that we get proper digit separators when LANG is set

default_compile_flags
vector-of-bool 3 years ago
parent
commit
a8913f3ca7
2 changed files with 17 additions and 2 deletions
  1. +17
    -1
      src/dds.main.cpp
  2. +0
    -1
      src/dds/cli/dispatch_main.cpp

+ 17
- 1
src/dds.main.cpp View File

@@ -12,10 +12,26 @@

#include <filesystem>
#include <iostream>
#include <locale>

static void load_locale() {
auto lang = std::getenv("LANG");
if (!lang) {
return;
}
try {
std::locale::global(std::locale(lang));
} catch (const std::runtime_error& e) {
// No locale with the given name
return;
}
}

int main_fn(std::string_view program_name, const std::vector<std::string>& argv) {
dds::log::init_logger();
auto log_subscr = neo::subscribe(&dds::log::ev_log::print);
load_locale();
std::setlocale(LC_CTYPE, ".utf8");

dds::install_signal_handlers();

@@ -104,6 +120,7 @@ int main_fn(std::string_view program_name, const std::vector<std::string>& argv)
// Non-null result from argument parsing, return that value immediately.
return *result;
}
dds::log::current_log_level = opts.log_level;
return dds::cli::dispatch_main(opts);
}

@@ -142,7 +159,6 @@ std::string wstr_to_u8str(std::wstring_view in) {

int wmain(int argc, wchar_t** argv) {
std::vector<std::string> u8_argv;
::setlocale(LC_ALL, ".utf8");
for (int i = 0; i < argc; ++i) {
u8_argv.emplace_back(wstr_to_u8str(argv[i]));
}

+ 0
- 1
src/dds/cli/dispatch_main.cpp View File

@@ -33,7 +33,6 @@ command sdist_create;
} // namespace cmd

int dispatch_main(const options& opts) noexcept {
dds::log::current_log_level = opts.log_level;
return dds::handle_cli_errors([&] {
DDS_E_SCOPE(opts.subcommand);
switch (opts.subcommand) {

Loading…
Cancel
Save