Skip to content

Commit

Permalink
Merge pull request #216 from dosbox-staging/staging/locale-optional-1
Browse files Browse the repository at this point in the history
Make the use of locale optional via `LOGURU_USE_LOCALE`
  • Loading branch information
bylowerik authored Apr 22, 2022
2 parents 27f79be + 9790e71 commit 2d97b53
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 15 additions & 2 deletions loguru.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <algorithm>
#include <atomic>
#include <cctype>
#include <chrono>
#include <cstdarg>
#include <cstdio>
Expand Down Expand Up @@ -75,7 +76,6 @@

// TODO: use defined(_POSIX_VERSION) for some of these things?


#if defined(_WIN32) || defined(__CYGWIN__)
#define LOGURU_PTHREADS 0
#define LOGURU_WINTHREADS 1
Expand Down Expand Up @@ -472,7 +472,20 @@ namespace loguru
for (int arg_it = 1; arg_it < argc; ++arg_it) {
auto cmd = argv[arg_it];
auto arg_len = strlen(verbosity_flag);
if (strncmp(cmd, verbosity_flag, arg_len) == 0 && !std::isalpha(cmd[arg_len], std::locale(""))) {

bool last_is_alpha = false;
#if LOGURU_USE_LOCALE
try { // locale variant of isalpha will throw on error
last_is_alpha = std::isalpha(cmd[arg_len], std::locale(""));
}
catch (...) {
last_is_alpha = std::isalpha(static_cast<int>(cmd[arg_len]));
}
#else
last_is_alpha = std::isalpha(static_cast<int>(cmd[arg_len]));
#endif

if (strncmp(cmd, verbosity_flag, arg_len) == 0 && !last_is_alpha) {
out_argc -= 1;
auto value_str = cmd + arg_len;
if (value_str[0] == '\0') {
Expand Down
4 changes: 4 additions & 0 deletions loguru.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ Website: www.ilikebigbits.com
#define LOGURU_USE_FMTLIB 0
#endif

#ifndef LOGURU_USE_LOCALE
#define LOGURU_USE_LOCALE 0
#endif

#ifndef LOGURU_WITH_FILEABS
#define LOGURU_WITH_FILEABS 0
#endif
Expand Down

0 comments on commit 2d97b53

Please sign in to comment.