From 9922eaae71ac8121a5b8a6d6ef59d143087bd897 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Mon, 7 Mar 2022 16:37:26 +0100 Subject: [PATCH 1/3] Bump version to 11.1.4 and update docu --- CMakeLists.txt | 2 +- doc/changelog.dox | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1d9d1e2..7ff52fe5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ cmake_minimum_required(VERSION 3.9) # Version number starts at 10 to avoid conflicts with Boost version -set(_version 11.1.3) +set(_version 11.1.4) if(BOOST_SUPERPROJECT_SOURCE_DIR) set(_version ${BOOST_SUPERPROJECT_VERSION}) endif() diff --git a/doc/changelog.dox b/doc/changelog.dox index 1b5627ea..7aabaf51 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -10,14 +10,19 @@ \section changelog Changelog -\subsection changelog_next Next release +\subsection changelog_11_1_4 Nowide 11.1.4 +- Fix possible redefinition of `_LARGEFILE_SOURCE` +- Fix missing include when `BOOST_USE_WINDOWS_H` and `WIN32_LEAN_AND_MEAN` are defined. +- Fix compile failures on recent MinGW-w64 compilers +- Add sanity checking of the buffer size passed to the (possibly) 64 bit `stat` function +- Known issues: Read performance for text files is possibly worse than the `std` streams. Binary files and writing is unaffected. -- Fix possible double-free when setting a custom buffer (`setbuf`) after filebuf already allocated an internal buffer -- Handle some warnings (mostly on MSVC) -\subsection changelog_11_1_3 Nowide 11.1.3 +\subsection changelog_11_1_3 Nowide 11.1.3 (Boost 1.78) - Fix missing config file in release +- Fix possible double-free when setting a custom buffer (`setbuf`) after filebuf already allocated an internal buffer +- Handle some warnings (mostly on MSVC) - Known issues: Read performance for text files is degraded. Binary files and writing is unaffected. \subsection changelog_11_1_2 Nowide 11.1.2 (Boost 1.76) From 8d259f16b3ec11d23835538f0656176487c5fe7d Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 8 Mar 2022 18:09:53 +0100 Subject: [PATCH 2/3] Enhance CTRL+Z iostream test Output random seed and progress indicator to be able to reproduce failures --- test/file_test_helpers.cpp | 10 +++++++++- test/test_iostream.cpp | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/test/file_test_helpers.cpp b/test/file_test_helpers.cpp index 3835d4a3..36de84a3 100644 --- a/test/file_test_helpers.cpp +++ b/test/file_test_helpers.cpp @@ -10,6 +10,7 @@ #include #include "test.hpp" #include +#include #include #include #include @@ -76,9 +77,16 @@ namespace nowide { return result; } + static std::minstd_rand make_rand_engine() + { + const auto seed = std::random_device{}(); + std::cout << "RNG seed: " << seed << std::endl; + return std::minstd_rand(seed); + } + std::string create_random_data(size_t num_chars, data_type type) { - static std::minstd_rand rng(std::random_device{}()); + static std::minstd_rand rng = make_rand_engine(); std::string result(num_chars, '\0'); if(type == data_type::binary) { diff --git a/test/test_iostream.cpp b/test/test_iostream.cpp index 2b0e8233..ec84241e 100644 --- a/test/test_iostream.cpp +++ b/test/test_iostream.cpp @@ -349,13 +349,16 @@ void test_ctrl_z_is_eof() TEST_MOCKED(value == "Reached after clear()"); #ifndef BOOST_NOWIDE_TEST_INTERACTIVE // CTRL+Z anywhere else but at the start of a line does not matter + nw::cout << "CTRL+Z Test:"; for(int i = 1; i <= 1100; i++) { + nw::cout << '.' << std::flush; // Progress indicator const std::string expected = create_random_one_line_string(i) + "\x1a"; mock_buf.inputs.push(std::wstring(expected.begin(), expected.end()) + L"\r\n"); TEST(std::getline(nw::cin, value)); TEST_EQ(value, expected); } + nw::cout << std::endl; #endif } From 09f81674ecbdf256d4b64827b587d95d856c029a Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 8 Mar 2022 19:49:45 +0100 Subject: [PATCH 3/3] Docu update especially related to filesystem::path Mention `setlocale` to use an UTF-8 codepage on Windows. Refer to `u8path` and `u8string` functions for std::filesystem::path --- doc/main.dox | 14 ++++++++++++-- include/boost/nowide/filesystem.hpp | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/doc/main.dox b/doc/main.dox index 2d34c5f2..0b11cfca 100644 --- a/doc/main.dox +++ b/doc/main.dox @@ -143,6 +143,11 @@ Hence it is only usable if the targetted system is Windows 10 after May 2019. The second method relies on user interaction prior to starting the program. Obviously this is not reliable when expecting only UTF-8 in the code. +Also since Windows 10 1803 (i.e. since April 2018) it is possible to programmatically set the current code page to UTF-8 with e.g. `setlocale(LC_ALL, ".UTF8");`. +This makes many functions accept or produce UTF-8 encoded strings which is especially useful for `std::filesystem::path` and its `string()` function. +See the documentation for details. +While this works for most functions, it doesn't work for e.g. the program arguments (`argv` and `env` parameters of `main`). + Hence under some circumstances (and hopefully always somewhen in the future) this library will not be required and even Windows I/O can be used with UTF-8 encoded text. \subsection main_reading Further Reading @@ -255,7 +260,7 @@ The example above could be rewritten as: \code boost::nowide::basic_stackstring wexisting_file(existing_file), wnew_file(new_file); -CopyFileW(wexisting_file.c_str(),wnew_file.c_str(),TRUE); +CopyFileW(wexisting_file.c_str(), wnew_file.c_str(), TRUE); \endcode \note There are a few convenience typedefs: \c stackstring and \c wstackstring using @@ -276,12 +281,17 @@ Boost.Filesystem supports selection of narrow encoding. Unfortunatelly the default narrow encoding on Windows isn't UTF-8. But you can enable UTF-8 as default encoding on Boost.Filesystem by calling `boost::nowide::nowide_filesystem()` in the beginning of your program which -imbues a locale with a UTF-8 conversion facet to convert between \c char \c wchar_t. +imbues a locale with a UTF-8 conversion facet to convert between \c char and \c wchar_t. This interprets all narrow strings passed to and from \c boost::filesystem::path as UTF-8 when converting them to wide strings (as required for internal storage). On POSIX this has usually no effect, as no conversion is done due to narrow strings being used as the storage format. +For `std::filesystem::path` available since C++17 there is no way to imbue a locale. +However the `u8string()` member function can be used to obtain an UTF-8 encoded string from a `path`. +And to optain a `path` from an UTF-8 encoded string you may use `std::filesystem::u8path` +or since C++20 one of the `path` constructors taking a `char8_t`-type input. + \section technical Technical Details \subsection technical_imple Windows vs POSIX diff --git a/include/boost/nowide/filesystem.hpp b/include/boost/nowide/filesystem.hpp index 68e398d7..1df0c945 100644 --- a/include/boost/nowide/filesystem.hpp +++ b/include/boost/nowide/filesystem.hpp @@ -14,7 +14,9 @@ namespace boost { namespace nowide { /// - /// Install utf8_codecvt facet into boost::filesystem::path such all char strings are interpreted as utf-8 strings + /// Install utf8_codecvt facet into boost::filesystem::path + /// such that all char strings are interpreted as UTF-8 strings + /// \return The previous imbued path locale. /// inline std::locale nowide_filesystem() {