Mercurial > minori
comparison dep/fmt/test/util.cc @ 343:1faa72660932
*: transfer back to cmake from autotools
autotools just made lots of things more complicated than
they should have and many things broke (i.e. translations)
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Thu, 20 Jun 2024 05:56:06 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 342:adb79bdde329 | 343:1faa72660932 |
|---|---|
| 1 // Formatting library for C++ - test utilities | |
| 2 // | |
| 3 // Copyright (c) 2012 - present, Victor Zverovich | |
| 4 // All rights reserved. | |
| 5 // | |
| 6 // For the license information refer to format.h. | |
| 7 | |
| 8 #include "util.h" | |
| 9 | |
| 10 #include <cstring> | |
| 11 | |
| 12 const char* const file_content = "Don't panic!"; | |
| 13 | |
| 14 fmt::buffered_file open_buffered_file(FILE** fp) { | |
| 15 #if FMT_USE_FCNTL | |
| 16 fmt::file read_end, write_end; | |
| 17 fmt::file::pipe(read_end, write_end); | |
| 18 write_end.write(file_content, std::strlen(file_content)); | |
| 19 write_end.close(); | |
| 20 fmt::buffered_file f = read_end.fdopen("r"); | |
| 21 if (fp) *fp = f.get(); | |
| 22 #else | |
| 23 fmt::buffered_file f("test-file", "w"); | |
| 24 fputs(file_content, f.get()); | |
| 25 if (fp) *fp = f.get(); | |
| 26 #endif | |
| 27 return f; | |
| 28 } | |
| 29 | |
| 30 std::locale do_get_locale(const char* name) { | |
| 31 try { | |
| 32 return std::locale(name); | |
| 33 } catch (const std::runtime_error&) { | |
| 34 } | |
| 35 return std::locale::classic(); | |
| 36 } | |
| 37 | |
| 38 std::locale get_locale(const char* name, const char* alt_name) { | |
| 39 auto loc = do_get_locale(name); | |
| 40 if (loc == std::locale::classic() && alt_name) | |
| 41 loc = do_get_locale(alt_name); | |
| 42 #ifdef __OpenBSD__ | |
| 43 // Locales are not working in OpenBSD: | |
| 44 // https://github.com/fmtlib/fmt/issues/3670. | |
| 45 loc = std::locale::classic(); | |
| 46 #endif | |
| 47 if (loc == std::locale::classic()) | |
| 48 fmt::print(stderr, "{} locale is missing.\n", name); | |
| 49 return loc; | |
| 50 } |
