Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Mar 8, 2022
2 parents 9cf6603 + 09f8167 commit 9f9f012
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 9 additions & 4 deletions doc/changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions doc/main.dox
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setlocale-wsetlocale?view=msvc-160#utf-8-support">the documentation</a> 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
Expand Down Expand Up @@ -255,7 +260,7 @@ The example above could be rewritten as:

\code
boost::nowide::basic_stackstring<wchar_t,char,64> 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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion include/boost/nowide/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
10 changes: 9 additions & 1 deletion test/file_test_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <boost/nowide/cstdio.hpp>
#include "test.hpp"
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <random>
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions test/test_iostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 9f9f012

Please sign in to comment.