diff options
Diffstat (limited to 'test/util.cc')
-rw-r--r-- | test/util.cc | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/test/util.cc b/test/util.cc index d08dcbdc..4ff34a91 100644 --- a/test/util.cc +++ b/test/util.cc @@ -9,42 +9,37 @@ #include <cstring> -void increment(char* s) { - for (int i = static_cast<int>(std::strlen(s)) - 1; i >= 0; --i) { - if (s[i] != '9') { - ++s[i]; - break; - } - s[i] = '0'; - } -} - -std::string get_system_error(int error_code) { -#if defined(__MINGW32__) || !defined(_WIN32) - return strerror(error_code); -#else - enum { BUFFER_SIZE = 200 }; - char buffer[BUFFER_SIZE]; - if (strerror_s(buffer, BUFFER_SIZE, error_code)) - throw std::exception("strerror_s failed"); - return buffer; -#endif -} - -const char* const FILE_CONTENT = "Don't panic!"; +const char* const file_content = "Don't panic!"; fmt::buffered_file open_buffered_file(FILE** fp) { #if FMT_USE_FCNTL fmt::file read_end, write_end; fmt::file::pipe(read_end, write_end); - write_end.write(FILE_CONTENT, std::strlen(FILE_CONTENT)); + write_end.write(file_content, std::strlen(file_content)); write_end.close(); fmt::buffered_file f = read_end.fdopen("r"); if (fp) *fp = f.get(); #else fmt::buffered_file f("test-file", "w"); - fputs(FILE_CONTENT, f.get()); + fputs(file_content, f.get()); if (fp) *fp = f.get(); #endif return f; } + +std::locale do_get_locale(const char* name) { + try { + return std::locale(name); + } catch (const std::runtime_error&) { + } + return std::locale::classic(); +} + +std::locale get_locale(const char* name, const char* alt_name) { + auto loc = do_get_locale(name); + if (loc == std::locale::classic() && alt_name) + loc = do_get_locale(alt_name); + if (loc == std::locale::classic()) + fmt::print(stderr, "{} locale is missing.\n", name); + return loc; +} |