Compare commits

...

13 Commits

Author SHA1 Message Date
Toru Niina
b389bbc4eb Merge pull request #242 from 0X1A/master
Fix issues with CMake package configuration when used with vcpkg #110
2024-06-12 00:46:15 +09:00
ToruNiina
5e4eb52f84 fix: add cxx_std to check_cxx_source_compiles
in macos, default version is 98 and it fails to compile boost test.
ci fails in the test branch because of apt timeout, but osx jobs works.
2024-06-11 23:47:49 +09:00
Alberto Corona
cbd596144d Fix issue with CMake package configuration #110 2024-05-01 18:57:49 -05:00
ToruNiina
85faca9cbe ci: update action checkout 2024-03-20 23:43:01 +09:00
ToruNiina
3509be6629 ci: add env var to avoid installation failure 2024-03-20 23:33:47 +09:00
ToruNiina
fb7b02f254 ci: remove old version of osx that takes time 2024-03-20 23:33:27 +09:00
ToruNiina
2466959cf9 chore: avoid false-positive ref life warning 2024-03-20 22:42:00 +09:00
ToruNiina
a76c5b385f refactor: replace mut-ref by take-and-move pattern 2024-03-20 22:40:46 +09:00
ToruNiina
52621a4fd8 feat: remove cxx_standard related stuff
fix #241
2024-03-20 22:38:56 +09:00
ToruNiina
64cd90637b refactor: move cmake component to where it's used 2024-03-20 22:35:03 +09:00
ToruNiina
d4a6fc7953 refactor: remove scripts for old version of cmake
now minimum_require ensures that version is not used
2024-03-20 22:34:02 +09:00
ToruNiina
d4eb5f3c9d chore: update patch version 2024-01-07 18:06:50 +09:00
ToruNiina
cc2e453b5b feat: remove strerror from errmsg in FILE* version
parse(FILE*) is a minor overload, but dispatching strerror takes too
much cost. Standard library version is not thread-safe, so some compiler
reports a warning. There are thread-safe versions defined in XSI, GNU,
and Windows. XSI/GNU versions can be detected by macros, but in some
cases, detection-by-macro written in the doc does not work.
Since errno can be obtained from the exception, users can call strerror
that is available in their env if needed. We can just report errno.
2024-01-07 10:48:17 +09:00
9 changed files with 66 additions and 164 deletions

View File

@@ -12,7 +12,7 @@ jobs:
unreleased: ['ON', 'OFF']
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Install
@@ -46,7 +46,7 @@ jobs:
- {compiler: '11', standard: '20'}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Install
@@ -78,7 +78,7 @@ jobs:
- {compiler: 'g++-7', standard: '20'}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Install
@@ -117,7 +117,7 @@ jobs:
- {compiler: '9', standard: '20'}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Install
@@ -146,7 +146,7 @@ jobs:
# unreleased: ['ON', 'OFF']
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# uses: actions/checkout@v4
# with:
# submodules: true
# - name: Install
@@ -171,12 +171,14 @@ jobs:
unreleased: ['ON', 'OFF']
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Install
run: |
brew install boost
env:
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
- name: Configure
run: |
mkdir build && cd build
@@ -196,33 +198,7 @@ jobs:
unreleased: ['ON', 'OFF']
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Install
run: |
brew install boost
- name: Configure
run: |
mkdir build && cd build
cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DTOML11_USE_UNRELEASED_TOML_FEATURES=${{ matrix.unreleased }}
- name: Build
run: |
cd build && cmake --build .
- name: Test
run: |
cd build && ctest --output-on-failure
build-osx-11:
runs-on: macos-11
strategy:
matrix:
standard: ['11', '14', '17', '20']
unreleased: ['ON', 'OFF']
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Install
@@ -248,7 +224,7 @@ jobs:
unreleased: ['ON', 'OFF']
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Install

View File

@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5)
enable_testing()
project(toml11 VERSION 3.8.0)
project(toml11 VERSION 3.8.1)
option(toml11_BUILD_TEST "Build toml tests" OFF)
option(toml11_INSTALL "Install CMake targets during install step." ON)
@@ -11,40 +11,6 @@ option(toml11_TEST_WITH_UBSAN "use LLVM undefined behavior sanitizer" OFF)
option(TOML11_USE_UNRELEASED_TOML_FEATURES
"use features in toml-lang/toml master while testing" OFF)
include(CheckCXXCompilerFlag)
if("${CMAKE_VERSION}" VERSION_GREATER 3.1)
set(CMAKE_CXX_EXTENSIONS OFF CACHE BOOL "Boolean specifying whether compiler specific extensions are requested.")
if(NOT DEFINED CMAKE_CXX_STANDARD)
message(FATAL_ERROR "CMAKE_CXX_STANDARD is not defined. \
The C++ standard whose features are requested to *build* all targets. \
Remember that toml11 is a header only library that does NOT require compilation to use.")
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "Boolean describing whether the value of CXX_STANDARD is a requirement.")
else()
# Manually check for C++11 compiler flag.
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXXOX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
elseif(COMPILER_SUPPORTS_GNU11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
elseif(COMPILER_SUPPORTS_GNU0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
else()
if(MSVC)
if(MSVC_VERSION LESS 1900)
message(SEND_ERROR "MSVC < 14.0 is not supported. Please update your compiler or use mingw")
endif()
else()
message(SEND_ERROR "The ${CMAKE_CXX_COMPILER} compiler lacks C++11 support. Use another compiler.")
endif()
endif()
endif()
if(MSVC)
# add_definitions("/Zc:__cplusplus") # define __cplusplus value correctly
add_definitions("/utf-8") # enable to use u8"" literal

View File

@@ -1,2 +1,2 @@
@PACKAGE_INIT@
include("@PACKAGE_toml11_install_cmake_dir@/toml11Targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/toml11Targets.cmake")

View File

@@ -55,6 +55,8 @@ set(TEST_NAMES
test_extended_conversions
)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-Wall" COMPILER_SUPPORTS_WALL)
CHECK_CXX_COMPILER_FLAG("-Wextra" COMPILER_SUPPORTS_WEXTRA)
CHECK_CXX_COMPILER_FLAG("-Wpedantic" COMPILER_SUPPORTS_WPEDANTIC)
@@ -103,9 +105,13 @@ find_package(Boost COMPONENTS unit_test_framework REQUIRED)
set(PREVIOUSLY_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}")
set(PREVIOUSLY_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
set(PREVIOUSLY_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
list(APPEND CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
if(APPLE)
list(APPEND CMAKE_REQUIRED_FLAGS "-std=c++11")
endif()
check_cxx_source_compiles("
#define BOOST_TEST_MODULE \"dummy\"
@@ -133,9 +139,11 @@ BOOST_AUTO_TEST_CASE(proforma) { BOOST_TEST(true); }
set(CMAKE_REQUIRED_INCLUDES "${PREVIOUSLY_REQUIRED_INCLUDES}")
set(CMAKE_REQUIRED_LIBRARIES "${PREVIOUSLY_REQUIRED_LIBRARIES}")
set(CMAKE_REQUIRED_FLAGS "${PREVIOUSLY_REQUIRED_FLAGS}")
unset(PREVIOUSLY_REQUIRED_INCLUDES)
unset(PREVIOUSLY_REQUIRED_LIBRARIES)
unset(PREVIOUSLY_REQUIRED_FLAGS)
if(TOML11_WITH_BOOST_TEST_DYNAMIC)
add_definitions(-DUNITTEST_FRAMEWORK_LIBRARY_EXIST -DBOOST_TEST_DYN_LINK)

View File

@@ -14,8 +14,8 @@ BOOST_AUTO_TEST_CASE(test_comment_before)
std::istringstream iss(file);
const auto v = toml::parse<toml::preserve_comments>(iss);
const auto& a = toml::find(v, "a");
const auto& b = toml::find(v, "b");
const auto a = toml::find(v, "a");
const auto b = toml::find(v, "b");
BOOST_TEST(a.comments().size() == 1u);
BOOST_TEST(a.comments().front() == " comment for a.");
@@ -35,8 +35,8 @@ BOOST_AUTO_TEST_CASE(test_comment_before)
std::istringstream iss(file);
const auto v = toml::parse<toml::preserve_comments>(iss);
const auto& a = toml::find(v, "a");
const auto& b = toml::find(v, "b");
const auto a = toml::find(v, "a");
const auto b = toml::find(v, "b");
BOOST_TEST(a.comments().size() == 2u);
BOOST_TEST(a.comments().front() == " comment for a.");
@@ -58,8 +58,8 @@ BOOST_AUTO_TEST_CASE(test_comment_inline)
std::istringstream iss(file);
const auto v = toml::parse<toml::preserve_comments>(iss);
const auto& a = toml::find(v, "a");
const auto& b = toml::find(v, "b");
const auto a = toml::find(v, "a");
const auto b = toml::find(v, "b");
BOOST_TEST(a.comments().size() == 1u);
BOOST_TEST(a.comments().front() == " comment for a.");
@@ -79,9 +79,9 @@ BOOST_AUTO_TEST_CASE(test_comment_inline)
std::istringstream iss(file);
const auto v = toml::parse<toml::preserve_comments>(iss);
const auto& a = toml::find(v, "a");
const auto& b = toml::find(v, "b");
const auto& b0 = b.as_array().at(0);
const auto a = toml::find(v, "a");
const auto b = toml::find(v, "b");
const auto b0 = b.as_array().at(0);
BOOST_TEST(a.comments().size() == 1u);
BOOST_TEST(a.comments().front() == " comment for a.");
@@ -110,10 +110,10 @@ BOOST_AUTO_TEST_CASE(test_comment_both)
std::istringstream iss(file);
const auto v = toml::parse<toml::preserve_comments>(iss);
const auto& a = toml::find(v, "a");
const auto& b = toml::find(v, "b");
const auto& c = toml::find(v, "c");
const auto& c0 = c.as_array().at(0);
const auto a = toml::find(v, "a");
const auto b = toml::find(v, "b");
const auto c = toml::find(v, "c");
const auto c0 = c.as_array().at(0);
BOOST_TEST(a.comments().size() == 2u);
BOOST_TEST(a.comments().front() == " comment for a.");
@@ -186,10 +186,10 @@ BOOST_AUTO_TEST_CASE(test_discard_comment)
std::istringstream iss(file);
const auto v = toml::parse<toml::discard_comments>(iss);
const auto& a = toml::find(v, "a");
const auto& b = toml::find(v, "b");
const auto& c = toml::find(v, "c");
const auto& c0 = c.as_array().at(0);
const auto a = toml::find(v, "a");
const auto b = toml::find(v, "b");
const auto c = toml::find(v, "c");
const auto c0 = c.as_array().at(0);
BOOST_TEST(a.comments().empty());
BOOST_TEST(b.comments().empty());

View File

@@ -12,7 +12,7 @@ BOOST_AUTO_TEST_CASE(test_example)
const auto data = toml::parse(testinput("example.toml"));
BOOST_TEST(toml::find<std::string>(data, "title") == "TOML Example");
const auto& owner = toml::find(data, "owner");
const auto owner = toml::find(data, "owner");
{
BOOST_TEST(toml::find<std::string>(owner, "name") == "Tom Preston-Werner");
BOOST_TEST(toml::find<std::string>(owner, "organization") == "GitHub");
@@ -23,7 +23,7 @@ BOOST_AUTO_TEST_CASE(test_example)
toml::local_time(7, 32, 0), toml::time_offset(0, 0)));
}
const auto& database = toml::find(data, "database");
const auto database = toml::find(data, "database");
{
BOOST_TEST(toml::find<std::string>(database, "server") == "192.168.1.1");
const std::vector<int> expected_ports{8001, 8001, 8002};
@@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE(test_example)
BOOST_TEST(toml::find<bool>(database, "enabled") == true);
}
const auto& servers = toml::find(data, "servers");
const auto servers = toml::find(data, "servers");
{
toml::table alpha = toml::find<toml::table>(servers, "alpha");
BOOST_TEST(toml::get<std::string>(alpha.at("ip")) == "10.0.0.1");
@@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(test_example)
BOOST_TEST(toml::get<std::string>(beta.at("country")) == "\xE4\xB8\xAD\xE5\x9B\xBD");
}
const auto& clients = toml::find(data, "clients");
const auto clients = toml::find(data, "clients");
{
toml::array clients_data = toml::find<toml::array>(clients, "data");
@@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(test_example_stream)
const auto data = toml::parse(ifs);
BOOST_TEST(toml::find<std::string>(data, "title") == "TOML Example");
const auto& owner = toml::find(data, "owner");
const auto owner = toml::find(data, "owner");
{
BOOST_TEST(toml::find<std::string>(owner, "name") == "Tom Preston-Werner");
BOOST_TEST(toml::find<std::string>(owner, "organization") == "GitHub");
@@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(test_example_stream)
toml::local_time(7, 32, 0), toml::time_offset(0, 0)));
}
const auto& database = toml::find(data, "database");
const auto database = toml::find(data, "database");
{
BOOST_TEST(toml::find<std::string>(database, "server") == "192.168.1.1");
const std::vector<int> expected_ports{8001, 8001, 8002};
@@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(test_example_stream)
BOOST_TEST(toml::find<bool>(database, "enabled") == true);
}
const auto& servers = toml::find(data, "servers");
const auto servers = toml::find(data, "servers");
{
toml::table alpha = toml::find<toml::table>(servers, "alpha");
BOOST_TEST(toml::get<std::string>(alpha.at("ip")) == "10.0.0.1");
@@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(test_example_stream)
BOOST_TEST(toml::get<std::string>(beta.at("country")) == "\xE4\xB8\xAD\xE5\x9B\xBD");
}
const auto& clients = toml::find(data, "clients");
const auto clients = toml::find(data, "clients");
{
toml::array clients_data = toml::find<toml::array>(clients, "data");
std::vector<std::string> expected_name{"gamma", "delta"};
@@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(test_example_file_pointer)
fclose(file);
BOOST_TEST(toml::find<std::string>(data, "title") == "TOML Example");
const auto& owner = toml::find(data, "owner");
const auto owner = toml::find(data, "owner");
{
BOOST_TEST(toml::find<std::string>(owner, "name") == "Tom Preston-Werner");
BOOST_TEST(toml::find<std::string>(owner, "organization") == "GitHub");
@@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE(test_example_file_pointer)
toml::local_time(7, 32, 0), toml::time_offset(0, 0)));
}
const auto& database = toml::find(data, "database");
const auto database = toml::find(data, "database");
{
BOOST_TEST(toml::find<std::string>(database, "server") == "192.168.1.1");
const std::vector<int> expected_ports{8001, 8001, 8002};
@@ -165,7 +165,7 @@ BOOST_AUTO_TEST_CASE(test_example_file_pointer)
BOOST_TEST(toml::find<bool>(database, "enabled") == true);
}
const auto& servers = toml::find(data, "servers");
const auto servers = toml::find(data, "servers");
{
toml::table alpha = toml::find<toml::table>(servers, "alpha");
BOOST_TEST(toml::get<std::string>(alpha.at("ip")) == "10.0.0.1");
@@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(test_example_file_pointer)
BOOST_TEST(toml::get<std::string>(beta.at("country")) == "\xE4\xB8\xAD\xE5\x9B\xBD");
}
const auto& clients = toml::find(data, "clients");
const auto clients = toml::find(data, "clients");
{
toml::array clients_data = toml::find<toml::array>(clients, "data");
std::vector<std::string> expected_name{"gamma", "delta"};
@@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(test_example_preserve_comment)
const auto data = toml::parse<toml::preserve_comments>(testinput("example.toml"));
BOOST_TEST(toml::find<std::string>(data, "title") == "TOML Example");
const auto& owner = toml::find(data, "owner");
const auto owner = toml::find(data, "owner");
{
BOOST_TEST(toml::find<std::string>(owner, "name") == "Tom Preston-Werner");
BOOST_TEST(toml::find<std::string>(owner, "organization") == "GitHub");
@@ -299,7 +299,7 @@ BOOST_AUTO_TEST_CASE(test_example_preserve_comment)
" First class dates? Why not?");
}
const auto& database = toml::find(data, "database");
const auto database = toml::find(data, "database");
{
BOOST_TEST(toml::find<std::string>(database, "server") == "192.168.1.1");
const std::vector<int> expected_ports{8001, 8001, 8002};
@@ -308,15 +308,15 @@ BOOST_AUTO_TEST_CASE(test_example_preserve_comment)
BOOST_TEST(toml::find<bool>(database, "enabled") == true);
}
const auto& servers = toml::find(data, "servers");
const auto servers = toml::find(data, "servers");
{
const auto& alpha = toml::find(servers, "alpha");
const auto alpha = toml::find(servers, "alpha");
BOOST_TEST(alpha.comments().at(0) ==
" You can indent as you please. Tabs or spaces. TOML don't care.");
BOOST_TEST(toml::find<std::string>(alpha, "ip") == "10.0.0.1");
BOOST_TEST(toml::find<std::string>(alpha, "dc") == "eqdc10");
const auto& beta = toml::find(servers, "beta");
const auto beta = toml::find(servers, "beta");
BOOST_TEST(toml::find<std::string>(beta, "ip") == "10.0.0.2");
BOOST_TEST(toml::find<std::string>(beta, "dc") == "eqdc10");
BOOST_TEST(toml::find<std::string>(beta, "country") ==
@@ -325,7 +325,7 @@ BOOST_AUTO_TEST_CASE(test_example_preserve_comment)
" This should be parsed as UTF-8");
}
const auto& clients = toml::find(data, "clients");
const auto clients = toml::find(data, "clients");
{
BOOST_TEST(toml::find(clients, "data").comments().at(0) ==
" just an update to make sure parsers support it");
@@ -376,7 +376,7 @@ BOOST_AUTO_TEST_CASE(test_example_preserve_stdmap_stddeque)
>::value, "");
BOOST_TEST(toml::find<std::string>(data, "title") == "TOML Example");
const auto& owner = toml::find(data, "owner");
const auto owner = toml::find(data, "owner");
{
BOOST_TEST(toml::find<std::string>(owner, "name") == "Tom Preston-Werner");
BOOST_TEST(toml::find<std::string>(owner, "organization") == "GitHub");
@@ -389,7 +389,7 @@ BOOST_AUTO_TEST_CASE(test_example_preserve_stdmap_stddeque)
" First class dates? Why not?");
}
const auto& database = toml::find(data, "database");
const auto database = toml::find(data, "database");
{
BOOST_TEST(toml::find<std::string>(database, "server") == "192.168.1.1");
const std::vector<int> expected_ports{8001, 8001, 8002};
@@ -398,15 +398,15 @@ BOOST_AUTO_TEST_CASE(test_example_preserve_stdmap_stddeque)
BOOST_TEST(toml::find<bool>(database, "enabled") == true);
}
const auto& servers = toml::find(data, "servers");
const auto servers = toml::find(data, "servers");
{
const auto& alpha = toml::find(servers, "alpha");
const auto alpha = toml::find(servers, "alpha");
BOOST_TEST(alpha.comments().at(0) ==
" You can indent as you please. Tabs or spaces. TOML don't care.");
BOOST_TEST(toml::find<std::string>(alpha, "ip") == "10.0.0.1");
BOOST_TEST(toml::find<std::string>(alpha, "dc") == "eqdc10");
const auto& beta = toml::find(servers, "beta");
const auto beta = toml::find(servers, "beta");
BOOST_TEST(toml::find<std::string>(beta, "ip") == "10.0.0.2");
BOOST_TEST(toml::find<std::string>(beta, "dc") == "eqdc10");
BOOST_TEST(toml::find<std::string>(beta, "country") ==
@@ -415,7 +415,7 @@ BOOST_AUTO_TEST_CASE(test_example_preserve_stdmap_stddeque)
" This should be parsed as UTF-8");
}
const auto& clients = toml::find(data, "clients");
const auto clients = toml::find(data, "clients");
{
BOOST_TEST(toml::find(clients, "data").comments().at(0) ==
" just an update to make sure parsers support it");

View File

@@ -27,7 +27,7 @@
#define TOML11_VERSION_MAJOR 3
#define TOML11_VERSION_MINOR 8
#define TOML11_VERSION_PATCH 0
#define TOML11_VERSION_PATCH 1
#include "toml/parser.hpp"
#include "toml/literal.hpp"

View File

@@ -14,62 +14,14 @@
namespace toml
{
namespace detail
{
inline std::string str_error(int errnum)
{
// C++ standard strerror is not thread-safe.
// C11 provides thread-safe version of this function, `strerror_s`, but it
// is not available in C++.
// To avoid using std::strerror, we need to use platform-specific functions.
// If none of the conditions are met, it calls std::strerror as a fallback.
#ifdef _MSC_VER // MSVC
constexpr std::size_t bufsize = 256;
std::array<char, bufsize> buf;
buf.fill('\0');
const auto result = strerror_s(buf.data(), bufsize, errnum);
if(result != 0)
{
return std::string("strerror_s failed");
}
else
{
return std::string(buf.data());
}
#elif defined(_GNU_SOURCE) && !(defined(__DARWIN_C_LEVEL) && __DARWIN_C_LEVEL >= 200112L )
constexpr std::size_t bufsize = 256;
std::array<char, bufsize> buf;
buf.fill('\0');
const char* result = strerror_r(errnum, buf.data(), bufsize);
return std::string(result);
#elif (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600) || ( defined(__DARWIN_C_LEVEL) && __DARWIN_C_LEVEL >= 200112L ) // macOS
constexpr std::size_t bufsize = 256;
std::array<char, bufsize> buf;
buf.fill('\0');
const int result = strerror_r(errnum, buf.data(), bufsize);
if (result != 0)
{
return std::string("strerror_r failed");
}
else
{
return std::string(buf.data());
}
#else // fallback
return std::strerror(errnum);
#endif
}
} // detail
struct file_io_error : public std::runtime_error
{
public:
file_io_error(int errnum, const std::string& msg, const std::string& fname)
: std::runtime_error(msg + " \"" + fname + "\": " + detail::str_error(errnum)),
: std::runtime_error(msg + " \"" + fname + "\": errno = " + std::to_string(errnum)),
errno_(errnum)
{}
int get_errno() const noexcept {return errno_;}
private:

View File

@@ -2453,7 +2453,7 @@ template<typename Comment = TOML11_DEFAULT_COMMENT_STRATEGY,
template<typename ...> class Table = std::unordered_map,
template<typename ...> class Array = std::vector>
basic_value<Comment, Table, Array>
parse(std::vector<char>& letters, const std::string& fname)
parse(std::vector<char> letters, const std::string& fname)
{
using value_type = basic_value<Comment, Table, Array>;
@@ -2468,7 +2468,7 @@ parse(std::vector<char>& letters, const std::string& fname)
letters.push_back('\n');
}
detail::location loc(std::move(fname), std::move(letters));
detail::location loc(fname, std::move(letters));
// skip BOM if exists.
// XXX component of BOM (like 0xEF) exceeds the representable range of