fixed source information being copied when copying nodes

also:
- many minor documentation fixes
- added pull request template
This commit is contained in:
Mark Gillard 2020-07-30 23:31:08 +03:00
parent 52736559d2
commit 6b8fa1bef5
15 changed files with 455 additions and 278 deletions

44
.github/pull_request_template.md vendored Normal file
View File

@ -0,0 +1,44 @@
<!--
Please replace the HTML comments below with the requested information.
Or leave them there and put your answers above/below them; you do you!
Thanks for contributing!
-->
**What does this change do?**
<!--
Changes all Foos to Bars.
--->
**Is it related to an exisiting bug report or feature request?**
<!--
Fixes #69.
--->
**Pre-merge checklist**
<!--
Not all of these will necessarily apply, particularly if you're not making a code change (e.g. fixing documentation).
That's OK.
--->
- [ ] I've read [CONTRIBUTING.md]
- [ ] I've added new test cases to verify my change
- [ ] I've regenerated toml.hpp ([how-to])
- [ ] I've updated any affected documentation
- [ ] I've rebuilt and run the tests with at least one of:
- [ ] Clang 6 or higher
- [ ] GCC 7 or higher
- [ ] Visual Studio 2019
- [ ] I've forever enshrined myself in glory by adding myself to the list of contributors in [README.md](https://github.com/marzer/tomlplusplus/blob/master/README.md)
**Anything else?**
<!--
According to all known laws of aviation, there is no way a bee should be able to fly.
Its wings are too small to get its fat little body off the ground.
The bee, of course, flies anyway, because bees don't care what humans think is impossible.
--->
[CONTRIBUTING.md]: https://github.com/marzer/tomlplusplus/blob/master/CONTRIBUTING.md
[how-to]: https://github.com/marzer/tomlplusplus/blob/master/CONTRIBUTING.md#regenerating-tomlhpp
[README.md]: https://github.com/marzer/tomlplusplus/blob/master/README.md

View File

@ -35,14 +35,23 @@ If test discovery fails you can usually fix it by enabling
`Auto Detect runsettings Files` (settings gear icon > `Configure Run Settings`).
### Testing on Linux (and WSL)
Install [meson] and [ninja] if necessary, then test with both gcc and clang:
Install [meson] and [ninja] if necessary, then:
```bash
CXX=g++ meson build-gcc
CXX=clang++ meson build-clang
cd build-gcc && ninja && ninja test
cd ../build-clang && ninja && ninja test
# create the build configs (first time only)
CXX=g++ meson build-gcc-debug -DGENERATE_CMAKE_CONFIG=disabled -DALL_WARNINGS=true
CXX=clang++ meson build-clang-debug -DGENERATE_CMAKE_CONFIG=disabled -DALL_WARNINGS=true
CXX=g++ meson build-gcc-release --buildtype=release -DGENERATE_CMAKE_CONFIG=disabled -DALL_WARNINGS=true
CXX=clang++ meson build-clang-release --buildtype=release -DGENERATE_CMAKE_CONFIG=disabled -DALL_WARNINGS=true
# run the tests
cd build-gcc-debug && ninja && ninja test \
&& cd ../build-clang-debug && ninja && ninja test \
&& cd ../build-gcc-release && ninja && ninja test \
&& cd ../build-clang-release && ninja && ninja test \
&& cd ..
```
[Visual Studio 2019]: https://visualstudio.microsoft.com/vs/
[Test Adapter for Catch2]: https://marketplace.visualstudio.com/items?itemName=JohnnyHendriks.ext01
[reporting issues]: https://github.com/marzer/tomlplusplus/issues

View File

@ -25,7 +25,7 @@
- Works with or without exceptions
- Doesn't require RTTI
- First-class support for serializing to JSON
- Tested on Clang (7+), GCC (7+) and MSVC (VS2019)
- Tested on Clang (6+), GCC (7+) and MSVC (VS2019)
- Tested on x64, x86 and ARM
<br>

View File

@ -3,10 +3,10 @@
HTML_EXTRA_STYLESHEET = \
https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600 \
../css/m-dark+documentation.compiled.css \
tomlplusplus.css
muu.css
HTML_EXTRA_FILES = \
tomlplusplus.js \
muu.js \
logo.png \
banner_small.png \
github-icon.png \
@ -31,5 +31,5 @@ HTML_EXTRA_FILES = \
##! <br><br>Documentation generated using <a href="https://mcss.mosra.cz/">m.css</a>
##! M_HTML_HEADER = <meta name="google-site-verification" content="gbtcNgKlNiPSMKkYMw4zWFVWGPH_oU93m9n_-nb4qK8" />\
##! <meta name="description" content="Header-only TOML config file parser and serializer for modern C++.">\
##! <script src="tomlplusplus.js"></script>
##! <script src="muu.js"></script>
##! M_FAVICON = favicon.ico

View File

@ -14,7 +14,7 @@
/// - Header-only (optional!)
/// - Doesn't require RTTI
/// - Works with or without exceptions
/// - Tested on Clang (7+), GCC (7+) and MSVC (VS2019)
/// - Tested on Clang (6+), GCC (7+) and MSVC (VS2019)
/// - Tested on x64, x86 and ARM
///
//////////////////////////////////////////////////////////////////////

View File

@ -42,31 +42,41 @@ article, article > header, article div > section
article div > section > section
{
margin-bottom: 1.25rem;
margin-bottom: 2.25rem;
}
pre, code, .tpp-enable-if > a
article section.m-doc-details > div
{
background-color: rgba(0,0,0,0.07)
}
article section.m-doc-details > div > h3:first-child
{
background-color: #22272e;
}
pre, code, .muu-enable-if > a
{
font-family: 'Consolas', 'Source Code Pro', monospace;
}
a.tpp-external
a.muu-external
{
font-weight: normal;
}
pre a.tpp-external,
pre a.tpp-injected
pre a.muu-external,
pre a.muu-injected
{
font-weight: inherit !important;
color: inherit !important;
}
.tpp-enable-if
.muu-enable-if
{
margin-bottom: 2px;
}
.tpp-enable-if > *
.muu-enable-if > *
{
display: inline-block;
border-radius: 0.2rem;
@ -75,7 +85,7 @@ pre a.tpp-injected
text-decoration: none;
}
.tpp-enable-if > a
.muu-enable-if > a
{
white-space: nowrap;
font-size: 0.7rem;
@ -84,13 +94,13 @@ pre a.tpp-injected
color: #050505;
}
.tpp-enable-if > a:hover
.muu-enable-if > a:hover
{
background-color: #747474;
color: initial;
}
.tpp-enable-if > span
.muu-enable-if > span
{
display: none;
padding-left: 2em;
@ -206,14 +216,14 @@ pre.m-code .cp
}
/* user types and typedefs */
.m-code .ut,
.m-code .nc
pre.m-code .ut,
pre.m-code .nc
{
color: rgb(78,201,176);
}
/* namespace::scopes:: */
.m-code .ns
pre.m-code .ns
{
color: rgb(140,140,140);
}

View File

@ -76,10 +76,10 @@ TOML_NAMESPACE_START
protected:
node() noexcept = default;
node(const node&) noexcept = default;
node(node&& other) noexcept;
node& operator= (const node&) noexcept = default;
node& operator= (node&& rhs) noexcept;
node(const node&) noexcept;
node(node&&) noexcept;
node& operator= (const node&) noexcept;
node& operator= (node&&) noexcept;
template <typename T>
[[nodiscard]]

View File

@ -18,6 +18,13 @@ TOML_DISABLE_SUGGEST_WARNINGS
TOML_NAMESPACE_START
{
TOML_EXTERNAL_LINKAGE
node::node(const node& /*other*/) noexcept
{
// does not copy source information
// this is not an error
}
TOML_EXTERNAL_LINKAGE
node::node(node && other) noexcept
: source_{ std::move(other.source_) }
@ -27,7 +34,17 @@ TOML_NAMESPACE_START
}
TOML_EXTERNAL_LINKAGE
node & node::operator= (node && rhs) noexcept
node& node::operator= (const node& /*rhs*/) noexcept
{
// does not copy source information
// this is not an error
source_ = {};
return *this;
}
TOML_EXTERNAL_LINKAGE
node& node::operator= (node && rhs) noexcept
{
source_ = std::move(rhs.source_);
rhs.source_.begin = {};

View File

@ -452,8 +452,6 @@ TOML_NAMESPACE_START
///
/// \returns <strong><em>With exceptions:</em></strong> A toml::table. <br>
/// <strong><em>Without exceptions:</em></strong> A toml::parse_result detailing the parsing outcome.
///
/// \attention This overload is not available if your compiler does not support char8_t-based strings.
[[nodiscard]]
TOML_API
parse_result parse(std::u8string_view doc, std::string_view source_path = {}) TOML_MAY_THROW;
@ -477,8 +475,6 @@ TOML_NAMESPACE_START
///
/// \returns <strong><em>With exceptions:</em></strong> A toml::table. <br>
/// <strong><em>Without exceptions:</em></strong> A toml::parse_result detailing the parsing outcome.
///
/// \attention This overload is not available if your compiler does not support char8_t-based strings.
[[nodiscard]]
TOML_API
parse_result parse(std::u8string_view doc, std::string&& source_path) TOML_MAY_THROW;
@ -505,8 +501,7 @@ TOML_NAMESPACE_START
/// \returns <strong><em>With exceptions:</em></strong> A toml::table. <br>
/// <strong><em>Without exceptions:</em></strong> A toml::parse_result detailing the parsing outcome.
///
/// \attention This overload is only available when #TOML_WINDOWS_COMPAT is enabled and your compiler
/// supports char8_t-based strings.
/// \attention This overload is only available when #TOML_WINDOWS_COMPAT is enabled.
[[nodiscard]]
TOML_API
parse_result parse(std::u8string_view doc, std::wstring_view source_path) TOML_MAY_THROW;
@ -761,7 +756,7 @@ TOML_NAMESPACE_START
#ifdef __cpp_lib_char8_t
/// \brief Parses TOML data from a utf8 string literal.
/// \brief Parses TOML data from a UTF-8 string literal.
///
/// \detail \cpp
/// using namespace toml::literals;
@ -780,8 +775,6 @@ TOML_NAMESPACE_START
///
/// \returns <strong><em>With exceptions:</em></strong> A toml::table. <br>
/// <strong><em>Without exceptions:</em></strong> A toml::parse_result detailing the parsing outcome.
///
/// \attention This overload is not available if your compiler does not support char8_t-based strings.
[[nodiscard]]
TOML_API
parse_result operator"" _toml(const char8_t* str, size_t len) TOML_MAY_THROW;

View File

@ -18,6 +18,11 @@ import bs4 as soup
import json
#=== CONFIG ============================================================================================================
repository = 'marzer/tomlplusplus'
inline_namespaces = [
"toml::literals",
]
@ -92,6 +97,173 @@ string_literals = [
'sv',
'_toml'
]
external_links = [
(r'static_cast','https://en.cppreference.com/w/cpp/language/static_cast'),
(r'const_cast','https://en.cppreference.com/w/cpp/language/const_cast'),
(r'dynamic_cast','https://en.cppreference.com/w/cpp/language/dynamic_cast'),
(r'reinterpret_cast','https://en.cppreference.com/w/cpp/language/reinterpret_cast'),
(r'(?:std::)?size_t', 'https://en.cppreference.com/w/cpp/types/size_t'),
(r'(?:std::)?u?int(_fast|_least)?(?:8|16|32|64)_ts?', 'https://en.cppreference.com/w/cpp/types/integer'),
(r'std::pairs?', 'https://en.cppreference.com/w/cpp/utility/pair'),
(r'std::bytes?', 'https://en.cppreference.com/w/cpp/types/byte'),
(r'std::optionals?', 'https://en.cppreference.com/w/cpp/utility/optional'),
(r'std::tuples?', 'https://en.cppreference.com/w/cpp/utility/tuple'),
(r'std::integral_constants?', 'https://en.cppreference.com/w/cpp/types/integral_constant'),
(r'std::char_traits', 'https://en.cppreference.com/w/cpp/string/char_traits'),
(r'std::allocators?', 'https://en.cppreference.com/w/cpp/memory/allocator'),
(r'std::enable_if(?:_t)?', 'https://en.cppreference.com/w/cpp/types/enable_if'),
(r'std::conditional(?:_t)?', 'https://en.cppreference.com/w/cpp/types/conditional'),
(r'std::unordered_maps?', 'https://en.cppreference.com/w/cpp/container/unordered_map'),
(r'std::unordered_sets?', 'https://en.cppreference.com/w/cpp/container/unordered_set'),
(r'std::maps?', 'https://en.cppreference.com/w/cpp/container/map'),
(r'std::sets?', 'https://en.cppreference.com/w/cpp/container/set'),
(r'std::vectors?', 'https://en.cppreference.com/w/cpp/container/vector'),
(r'std::arrays?', 'https://en.cppreference.com/w/cpp/container/array'),
(r'std::chrono::durations?', 'https://en.cppreference.com/w/cpp/chrono/duration'),
(
r'std::atomic(?:_(?:'
+ r'bool|[su]?char(?:8_t|16_t|32_t)?|u?short'
+ r'|u?int(?:8_t|16_t|32_t|64_t)?|u?l?long'
+ r'))?',
'https://en.cppreference.com/w/cpp/atomic/atomic'
),
(r'std::unique_ptrs?', 'https://en.cppreference.com/w/cpp/memory/unique_ptr'),
(r'std::shared_ptrs?', 'https://en.cppreference.com/w/cpp/memory/shared_ptr'),
(r'(?:std::)?nullptr_t', 'https://en.cppreference.com/w/cpp/types/nullptr_t'),
(r'std::reverse_iterator', 'https://en.cppreference.com/w/cpp/iterator/reverse_iterator'),
(r'std::(?:basic_|w)?istreams?', 'https://en.cppreference.com/w/cpp/io/basic_istream'),
(r'std::(?:basic_|w)?ostreams?', 'https://en.cppreference.com/w/cpp/io/basic_ostream'),
(r'std::(?:basic_|w)?iostreams?', 'https://en.cppreference.com/w/cpp/io/basic_iostream'),
(r'std::(?:basic_|w)?ifstreams?', 'https://en.cppreference.com/w/cpp/io/basic_ifstream'),
(r'std::(?:basic_|w)?ofstreams?', 'https://en.cppreference.com/w/cpp/io/basic_ofstream'),
(r'std::(?:basic_|w)?fstreams?', 'https://en.cppreference.com/w/cpp/io/basic_fstream'),
(r'std::(?:basic_|w)?istringstreams?', 'https://en.cppreference.com/w/cpp/io/basic_istringstream'),
(r'std::(?:basic_|w)?ostringstreams?', 'https://en.cppreference.com/w/cpp/io/basic_ostringstream'),
(r'std::(?:basic_|w)?stringstreams?', 'https://en.cppreference.com/w/cpp/io/basic_stringstream'),
(r'std::(?:basic_|w|u(?:8|16|32))?string_views?', 'https://en.cppreference.com/w/cpp/string/basic_string_view'),
(r'std::(?:basic_|w|u(?:8|16|32))?strings?', 'https://en.cppreference.com/w/cpp/string/basic_string'),
(r'\s(?:<|&lt;)fstream(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/fstream'),
(r'\s(?:<|&lt;)sstream(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/sstream'),
(r'\s(?:<|&lt;)iostream(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/iostream'),
(r'\s(?:<|&lt;)iosfwd(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/iosfwd'),
(r'\s(?:<|&lt;)string(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/string'),
(r'\s(?:<|&lt;)string_view(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/string_view'),
(r'(?:wchar|char(?:8|16|32))_ts?', 'https://en.cppreference.com/w/cpp/language/types#Character_types'),
(r'std::is_(?:nothrow_)?convertible(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_convertible'),
(r'std::is_same(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_same'),
(r'std::is_base_of(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_base_of'),
(r'std::is_enum(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_enum'),
(r'std::is_floating_point(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_floating_point'),
(r'std::is_integral(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_integral'),
(r'std::is_pointer(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_pointer'),
(r'std::is_reference(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_reference'),
(r'std::is_signed(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_signed'),
(r'std::is_unsigned(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_unsigned'),
(r'std::is_void(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_void'),
(r'std::is_(?:nothrow_)?invocable(?:_r)?', 'https://en.cppreference.com/w/cpp/types/is_invocable'),
(r'std::add_[lr]value_reference(?:_t)?', 'https://en.cppreference.com/w/cpp/types/add_reference'),
(r'std::remove_reference(?:_t)?', 'https://en.cppreference.com/w/cpp/types/remove_reference'),
(r'std::remove_cv(?:_t)?', 'https://en.cppreference.com/w/cpp/types/remove_cv'),
(r'std::underlying_type(?:_t)?', 'https://en.cppreference.com/w/cpp/types/underlying_type'),
(r'std::exceptions?', 'https://en.cppreference.com/w/cpp/error/exception'),
(r'std::runtime_errors?', 'https://en.cppreference.com/w/cpp/error/runtime_error'),
(r'std::is_constant_evaluated', 'https://en.cppreference.com/w/cpp/types/is_constant_evaluated'),
(r'std::launder', 'https://en.cppreference.com/w/cpp/utility/launder'),
(r'std::bit_width', 'https://en.cppreference.com/w/cpp/numeric/bit_width'),
(r'std::bit_ceil', 'https://en.cppreference.com/w/cpp/numeric/bit_ceil'),
(r'std::bit_floor', 'https://en.cppreference.com/w/cpp/numeric/bit_floor'),
(r'std::bit_cast', 'https://en.cppreference.com/w/cpp/numeric/bit_cast'),
(r'std::countl_zero', 'https://en.cppreference.com/w/cpp/numeric/countl_zero'),
(r'std::countr_zero', 'https://en.cppreference.com/w/cpp/numeric/countr_zero'),
(r'std::countl_one', 'https://en.cppreference.com/w/cpp/numeric/countl_one'),
(r'std::countr_one', 'https://en.cppreference.com/w/cpp/numeric/countr_one'),
(r'std::popcount', 'https://en.cppreference.com/w/cpp/numeric/popcount'),
(r'std::has_single_bit', 'https://en.cppreference.com/w/cpp/numeric/has_single_bit'),
(r'std::min', 'https://en.cppreference.com/w/cpp/algorithm/min'),
(r'std::max', 'https://en.cppreference.com/w/cpp/algorithm/max'),
(r'std::clamp', 'https://en.cppreference.com/w/cpp/algorithm/clamp'),
(r'std::numeric_limits', 'https://en.cppreference.com/w/cpp/types/numeric_limits'),
(r'std::initializer_lists?', 'https://en.cppreference.com/w/cpp/utility/initializer_list'),
(
r'(?:L?P)?(?:'
+ r'D?WORD(?:32|64|_PTR)?|HANDLE|HMODULE|BOOL(?:EAN)?'
+ r'|U?SHORT|U?LONG|U?INT(?:8|16|32|64)?'
+ r'|BYTE|VOID|C[WT]?STR'
+ r')',
'https://docs.microsoft.com/en-us/windows/desktop/winprog/windows-data-types'
),
(
r'(?:__INTELLISENSE__|_MSC_FULL_VER|_MSC_VER|_MSVC_LANG|_WIN32|_WIN64)',
'https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019'
),
(r'IUnknowns?', 'https://docs.microsoft.com/en-us/windows/win32/api/unknwn/nn-unknwn-iunknown'),
(r'(?:IUnknown::)?QueryInterface?', 'https://docs.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-queryinterface(q)'),
(r'(?:Legacy)?InputIterators?', 'https://en.cppreference.com/w/cpp/named_req/InputIterator'),
(r'(?:Legacy)?OutputIterators?', 'https://en.cppreference.com/w/cpp/named_req/OutputIterator'),
(r'(?:Legacy)?ForwardIterators?', 'https://en.cppreference.com/w/cpp/named_req/ForwardIterator'),
(r'(?:Legacy)?BidirectionalIterators?', 'https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator'),
(r'(?:Legacy)?RandomAccessIterators?', 'https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator'),
(r'(?:Legacy)?ContiguousIterators?', 'https://en.cppreference.com/w/cpp/named_req/ContiguousIterator'),
(
r'(?:'
+ r'__cplusplus|__STDC_HOSTED__'
+ r'|__FILE__|__LINE__'
+ r'|__DATE__|__TIME__'
+ r'|__STDCPP_DEFAULT_NEW_ALIGNMENT__'
+ r')',
'https://en.cppreference.com/w/cpp/preprocessor/replace'
),
# toml-specific
(r'toml::values?', 'classtoml_1_1value.html'),
(r'(toml::)?date_times?', 'structtoml_1_1date__time.html'),
(r'(toml::)?time', 'structtoml_1_1time.html'),
(r'(toml::)?dates?', 'structtoml_1_1date.html')
]
header_overrides = [
]
badges = [
(
'Releases',
'https://img.shields.io/github/v/release/marzer/tomlplusplus?style=flat-square',
'https://github.com/marzer/tomlplusplus/releases'
),
(
'C++17',
'badge-C++17.svg',
'https://en.cppreference.com/w/cpp/compiler_support'
),
(
'C++20',
'badge-C++20.svg',
'https://en.cppreference.com/w/cpp/compiler_support'
),
(
'TOML v1.0.0-rc.1',
'badge-TOML.svg',
'https://toml.io/en/v1.0.0-rc.1'
),
(None, None, None), # <br>
(
'MIT License',
'badge-license-MIT.svg',
'https://github.com/marzer/tomlplusplus/blob/master/LICENSE'
),
(
'CircleCI',
'https://img.shields.io/circleci/build/github/marzer/tomlplusplus'
+ '?label=circle%20ci&logo=circleci&logoColor=white&style=flat-square',
'https://circleci.com/gh/marzer/tomlplusplus'
),
(
'Mentioned in Awesome C++',
'badge-awesome.svg',
'https://github.com/fffaraz/awesome-cpp'
)
]
#=== HTML DOCUMENT =====================================================================================================
@ -113,7 +285,7 @@ class HTMLDocument(object):
def flush(self):
with open(self.__path, 'w', encoding='utf-8', newline='\n') as f:
f.write(str(self.__doc))
def new_tag(self, name, parent=None, string=None, class_=None, index=None, before=None, after=None, **kwargs):
tag = self.__doc.new_tag(name, **kwargs)
if (string is not None):
@ -132,7 +304,7 @@ class HTMLDocument(object):
parent.append(tag)
else:
parent.insert(index, tag)
return tag
def find_all_from_sections(self, name=None, select=None, section=None, include_toc=False, **kwargs):
@ -164,7 +336,7 @@ def html_find_parent(tag, names, cutoff=None):
return None
if parent.name in names:
return parent;
parent = parent.parent
parent = parent.parent
return parent
@ -181,7 +353,7 @@ def html_replace_tag(tag,str):
prev = newTag
else:
newTags = []
if (isinstance(tag, soup.NavigableString)):
tag.extract()
else:
@ -193,14 +365,14 @@ def html_replace_tag(tag,str):
def html_shallow_search(starting_tag, names, filter = None):
if isinstance(starting_tag, soup.NavigableString):
return []
if not utils.is_collection(names):
names = [ names ]
if starting_tag.name in names:
if filter is None or filter(starting_tag):
return [ starting_tag ]
results = []
for tag in starting_tag.children:
if isinstance(tag, soup.NavigableString):
@ -218,7 +390,7 @@ def html_string_descendants(starting_tag, filter = None):
if isinstance(starting_tag, soup.NavigableString):
if filter is None or filter(starting_tag):
return [ starting_tag ]
results = []
for tag in starting_tag.children:
if isinstance(tag, soup.NavigableString):
@ -258,16 +430,16 @@ class RegexReplacer(object):
self.__value = expression.sub(lambda m: self.__substitute(m), value)
if (not self.__result):
self.__groups = []
def __str__(self):
return self.__value
def __bool__(self):
return self.__result
def __getitem__(self, key):
return self.__groups[key]
def __len__(self):
return len(self.__groups)
@ -278,7 +450,7 @@ class RegexReplacer(object):
# allows the injection of custom tags using square-bracketed proxies.
class CustomTagsFix(object):
class CustomTagsFix(object):
__double_tags = re.compile(r"\[\s*(span|div|code|pre|h1|h2|h3|h4|h5|h6)(.*?)\s*\](.*?)\[\s*/\s*\1\s*\]", re.I)
__single_tags = re.compile(r"\[\s*(/?(?:span|div|code|pre|emoji|br|li|ul|ol))(\s.*?)?\s*\]", re.I)
__allowed_parents = ['dd', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li']
@ -318,13 +490,13 @@ class CustomTagsFix(object):
if emoji not in cls.__emojis:
return ''
return '&#x{}'.format(cls.__emojis[emoji][0])
else:
return '<{}{}>'.format(
m.group(1),
(' ' + str(m.group(2)).strip()) if m.group(2) else ''
)
def __call__(self, file, doc):
changed = False
for name in self.__allowed_parents:
@ -354,19 +526,19 @@ class CustomTagsFix(object):
# adds custom links to the navbar.
class NavBarFix(object):
__links = [
('Report an issue', 'https://github.com/marzer/tomlplusplus/issues'),
('Github', 'https://github.com/marzer/tomlplusplus/')
]
class NavBarFix(object):
def __call__(self, file, doc):
global repository
__links = [
('Report an issue', f'https://github.com/{repository}/issues'),
('Github', f'https://github.com/{repository}/')
]
list = doc.body.header.nav.div.div.select_one('#m-navbar-collapse').div.ol
if (list.select_one('.tpp-injected') is None):
if (list.select_one('.muu-injected') is None):
for label, url in self.__links:
doc.new_tag('a',
parent=doc.new_tag('li', parent=list, class_='tpp-injected tpp-external-navbar', index=0),
parent=doc.new_tag('li', parent=list, class_='muu-injected muu-external-navbar', index=0),
string=label,
href=url,
target='_blank'
@ -403,20 +575,20 @@ class ModifiersFixBase(object):
# fixes improperly-parsed modifiers on function signatures in the various 'detail view' sections.
class ModifiersFix1(ModifiersFixBase):
class ModifiersFix1(ModifiersFixBase):
__expression = re.compile(r'(\s+)({})(\s+)'.format(ModifiersFixBase._modifierRegex))
__sections = ['pub-static-methods', 'pub-methods', 'friends', 'func-members']
@classmethod
def __substitute(cls, m):
return '{}<span class="tpp-injected m-label m-flat {}">{}</span>{}'.format(
return '{}<span class="muu-injected m-label m-flat {}">{}</span>{}'.format(
m.group(1),
cls._modifierClasses[m.group(2)],
m.group(2),
m.group(3)
)
def __call__(self, file, doc):
changed = False
for sect in self.__sections:
@ -435,7 +607,7 @@ class ModifiersFix1(ModifiersFixBase):
# fixes improperly-parsed modifiers on function signatures in the 'Function documentation' section.
class ModifiersFix2(ModifiersFixBase):
class ModifiersFix2(ModifiersFixBase):
__expression = re.compile(r'\s+({})\s+'.format(ModifiersFixBase._modifierRegex))
@ -443,7 +615,7 @@ class ModifiersFix2(ModifiersFixBase):
def __substitute(cls, m, matches):
matches.append(m.group(1))
return ' '
def __call__(self, file, doc):
changed = False
sections = doc.find_all_from_sections(section=False) # all sections without an id
@ -469,7 +641,7 @@ class ModifiersFix2(ModifiersFixBase):
lastInserted = doc.new_tag('span',
parent=end,
string=match,
class_='tpp-injected m-label {}'.format(self._modifierClasses[match]),
class_='muu-injected m-label {}'.format(self._modifierClasses[match]),
before=lastInserted
)
lastInserted.insert_after(' ')
@ -482,56 +654,17 @@ class ModifiersFix2(ModifiersFixBase):
# applies some basic fixes to index.html
class IndexPageFix(object):
__badges = [
(
'Releases',
'https://img.shields.io/github/v/release/marzer/tomlplusplus?style=flat-square',
'https://github.com/marzer/tomlplusplus/releases'
),
(
'C++17',
'badge-C++17.svg',
'https://en.cppreference.com/w/cpp/compiler_support'
),
(
'C++20',
'badge-C++20.svg',
'https://en.cppreference.com/w/cpp/compiler_support'
),
(
'TOML v1.0.0-rc.1',
'badge-TOML.svg',
'https://toml.io/en/v1.0.0-rc.1'
),
(None, None, None), # <br>
(
'MIT License',
'badge-license-MIT.svg',
'https://github.com/marzer/tomlplusplus/blob/master/LICENSE'
),
(
'CircleCI',
'https://img.shields.io/circleci/build/github/marzer/tomlplusplus'
+ '?label=circle%20ci&logo=circleci&logoColor=white&style=flat-square',
'https://circleci.com/gh/marzer/tomlplusplus'
),
(
'Mentioned in Awesome C++',
'badge-awesome.svg',
'https://github.com/fffaraz/awesome-cpp'
)
]
class IndexPageFix(object):
def __call__(self, file, doc):
global badges
if file != 'index.html':
return False
parent = doc.body.main.article.div.div.div
banner = parent('img')[0].extract()
parent('h1')[0].replace_with(banner)
parent = doc.new_tag('div', class_='gh-badges', after=banner)
for (alt, src, href) in self.__badges:
for (alt, src, href) in badges:
if alt is None and src is None and href is None:
doc.new_tag('br', parent=parent)
else:
@ -570,13 +703,13 @@ class InlineNamespaceFix1(InlineNamespaceFixBase):
next = anchor.next_sibling
while (next is not None and isinstance(next, soup.NavigableString)):
next = next.next_sibling
if (next is not None and next.get('class') is not None and 'tpp-injected' in next.get('class')):
if (next is not None and next.get('class') is not None and 'muu-injected' in next.get('class')):
continue
doc.new_tag('span',
after=anchor,
string='inline',
title=inline_namespace_explainer,
class_='m-label m-info m-flat tpp-injected tpp-inline-namespace'
class_='m-label m-info m-flat muu-injected muu-inline-namespace'
)
anchor.insert_after(' ')
changed = True
@ -596,13 +729,13 @@ class InlineNamespaceFix2(InlineNamespaceFixBase):
changed = False
if (file in self._namespaceFiles):
h1 = doc.body.find('h1')
tag = h1.select_one('span.tpp-injected')
tag = h1.select_one('span.muu-injected')
if (tag is None):
tag = doc.new_tag('span',
parent=h1,
string='inline',
title=inline_namespace_explainer,
class_='m-label m-info tpp-injected tpp-inline-namespace'
class_='m-label m-info muu-injected muu-inline-namespace'
)
tag.insert_before(' ')
changed = True
@ -627,13 +760,13 @@ class InlineNamespaceFix3(InlineNamespaceFixBase):
next = anchor.next_sibling
while (next is not None and isinstance(next, soup.NavigableString)):
next = next.next_sibling
if (next is not None and next.get('class') is not None and 'tpp-injected' in next.get('class')):
if (next is not None and next.get('class') is not None and 'muu-injected' in next.get('class')):
continue
doc.new_tag('span',
after=anchor,
string='inline',
title=inline_namespace_explainer,
class_='m-label m-info m-flat tpp-injected tpp-inline-namespace'
class_='m-label m-info m-flat muu-injected muu-inline-namespace'
)
anchor.insert_after(' ')
changed = True
@ -668,7 +801,7 @@ class SyntaxHighlightingFix(object):
code_blocks = doc.body('pre', class_='m-code')
changed = False
for code_block in code_blocks:
# namespaces
names = code_block('span', class_='n')
names_ = []
@ -724,142 +857,22 @@ class SyntaxHighlightingFix(object):
# adds links to external sources where appropriate
class ExtDocLinksFix(object):
__types = [
(r'static_cast','https://en.cppreference.com/w/cpp/language/static_cast'),
(r'const_cast','https://en.cppreference.com/w/cpp/language/const_cast'),
(r'dynamic_cast','https://en.cppreference.com/w/cpp/language/dynamic_cast'),
(r'reinterpret_cast','https://en.cppreference.com/w/cpp/language/reinterpret_cast'),
(r'(?:std::)?size_t', 'https://en.cppreference.com/w/cpp/types/size_t'),
(r'(?:std::)?u?int(?:8|16|32|64)(fast|least)?_ts?', 'https://en.cppreference.com/w/cpp/types/integer'),
(r'std::pairs?', 'https://en.cppreference.com/w/cpp/utility/pair'),
(r'std::bytes?', 'https://en.cppreference.com/w/cpp/types/byte'),
(r'std::optionals?', 'https://en.cppreference.com/w/cpp/utility/optional'),
(r'std::tuples?', 'https://en.cppreference.com/w/cpp/utility/tuple'),
(r'std::integral_constants?', 'https://en.cppreference.com/w/cpp/types/integral_constant'),
(r'std::char_traits', 'https://en.cppreference.com/w/cpp/string/char_traits'),
(r'std::allocators?', 'https://en.cppreference.com/w/cpp/memory/allocator'),
(r'std::enable_if(?:_t)?', 'https://en.cppreference.com/w/cpp/types/enable_if'),
(r'std::conditional(?:_t)?', 'https://en.cppreference.com/w/cpp/types/conditional'),
(r'std::unordered_maps?', 'https://en.cppreference.com/w/cpp/container/unordered_map'),
(r'std::unordered_sets?', 'https://en.cppreference.com/w/cpp/container/unordered_set'),
(r'std::maps?', 'https://en.cppreference.com/w/cpp/container/map'),
(r'std::sets?', 'https://en.cppreference.com/w/cpp/container/set'),
(r'std::vectors?', 'https://en.cppreference.com/w/cpp/container/vector'),
(r'std::arrays?', 'https://en.cppreference.com/w/cpp/container/array'),
(r'std::chrono::durations?', 'https://en.cppreference.com/w/cpp/chrono/duration'),
(
r'std::atomic(?:_(?:'
+ r'bool|[su]?char(?:8_t|16_t|32_t)?|u?short'
+ r'|u?int(?:8_t|16_t|32_t|64_t)?|u?l?long'
+ r'))?',
'https://en.cppreference.com/w/cpp/atomic/atomic'
),
(r'std::unique_ptrs?', 'https://en.cppreference.com/w/cpp/memory/unique_ptr'),
(r'std::shared_ptrs?', 'https://en.cppreference.com/w/cpp/memory/shared_ptr'),
(r'(?:std::)?nullptr_t', 'https://en.cppreference.com/w/cpp/types/nullptr_t'),
(r'std::reverse_iterator', 'https://en.cppreference.com/w/cpp/iterator/reverse_iterator'),
(r'std::(?:basic_|w)?istreams?', 'https://en.cppreference.com/w/cpp/io/basic_istream'),
(r'std::(?:basic_|w)?ostreams?', 'https://en.cppreference.com/w/cpp/io/basic_ostream'),
(r'std::(?:basic_|w)?iostreams?', 'https://en.cppreference.com/w/cpp/io/basic_iostream'),
(r'std::(?:basic_|w)?ifstreams?', 'https://en.cppreference.com/w/cpp/io/basic_ifstream'),
(r'std::(?:basic_|w)?ofstreams?', 'https://en.cppreference.com/w/cpp/io/basic_ofstream'),
(r'std::(?:basic_|w)?fstreams?', 'https://en.cppreference.com/w/cpp/io/basic_fstream'),
(r'std::(?:basic_|w)?istringstreams?', 'https://en.cppreference.com/w/cpp/io/basic_istringstream'),
(r'std::(?:basic_|w)?ostringstreams?', 'https://en.cppreference.com/w/cpp/io/basic_ostringstream'),
(r'std::(?:basic_|w)?stringstreams?', 'https://en.cppreference.com/w/cpp/io/basic_stringstream'),
(r'std::(?:basic_|w|u8)?string_views?', 'https://en.cppreference.com/w/cpp/string/basic_string_view'),
(r'std::(?:basic_|w|u8)?strings?', 'https://en.cppreference.com/w/cpp/string/basic_string'),
(r'\s(?:<|&lt;)fstream(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/fstream'),
(r'\s(?:<|&lt;)sstream(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/sstream'),
(r'\s(?:<|&lt;)iostream(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/iostream'),
(r'\s(?:<|&lt;)iosfwd(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/iosfwd'),
(r'\s(?:<|&lt;)string(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/string'),
(r'\s(?:<|&lt;)string_view(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/string_view'),
(r'char(?:8|16|32)_ts?', 'https://en.cppreference.com/w/cpp/language/types'),
(r'std::is_(?:nothrow_)?convertible(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_convertible'),
(r'std::is_same(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_same'),
(r'std::is_base_of(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_base_of'),
(r'std::is_enum(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_enum'),
(r'std::is_floating_point(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_floating_point'),
(r'std::is_integral(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_integral'),
(r'std::is_pointer(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_pointer'),
(r'std::is_reference(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_reference'),
(r'std::is_signed(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_signed'),
(r'std::is_unsigned(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_unsigned'),
(r'std::is_void(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_void'),
(r'std::is_(?:nothrow_)?invocable(?:_r)?', 'https://en.cppreference.com/w/cpp/types/is_invocable'),
(r'std::add_[lr]value_reference(?:_t)?', 'https://en.cppreference.com/w/cpp/types/add_reference'),
(r'std::remove_reference(?:_t)?', 'https://en.cppreference.com/w/cpp/types/remove_reference'),
(r'std::remove_cv(?:_t)?', 'https://en.cppreference.com/w/cpp/types/remove_cv'),
(r'std::underlying_type(?:_t)?', 'https://en.cppreference.com/w/cpp/types/underlying_type'),
(r'std::exceptions?', 'https://en.cppreference.com/w/cpp/error/exception'),
(r'std::runtime_errors?', 'https://en.cppreference.com/w/cpp/error/runtime_error'),
(r'std::is_constant_evaluated', 'https://en.cppreference.com/w/cpp/types/is_constant_evaluated'),
(r'std::launder', 'https://en.cppreference.com/w/cpp/utility/launder'),
(r'std::bit_width', 'https://en.cppreference.com/w/cpp/numeric/bit_width'),
(r'std::bit_ceil', 'https://en.cppreference.com/w/cpp/numeric/bit_ceil'),
(r'std::bit_floor', 'https://en.cppreference.com/w/cpp/numeric/bit_floor'),
(r'std::bit_cast', 'https://en.cppreference.com/w/cpp/numeric/bit_cast'),
(r'std::countl_zero', 'https://en.cppreference.com/w/cpp/numeric/countl_zero'),
(r'std::countr_zero', 'https://en.cppreference.com/w/cpp/numeric/countr_zero'),
(r'std::countl_one', 'https://en.cppreference.com/w/cpp/numeric/countl_one'),
(r'std::countr_one', 'https://en.cppreference.com/w/cpp/numeric/countr_one'),
(r'std::popcount', 'https://en.cppreference.com/w/cpp/numeric/popcount'),
(r'std::has_single_bit', 'https://en.cppreference.com/w/cpp/numeric/has_single_bit'),
(r'std::min', 'https://en.cppreference.com/w/cpp/algorithm/min'),
(r'std::max', 'https://en.cppreference.com/w/cpp/algorithm/max'),
(r'std::clamp', 'https://en.cppreference.com/w/cpp/algorithm/clamp'),
(r'std::numeric_limits', 'https://en.cppreference.com/w/cpp/types/numeric_limits'),
(r'std::initializer_lists?', 'https://en.cppreference.com/w/cpp/utility/initializer_list'),
(
r'(?:L?P)?(?:'
+ r'D?WORD(?:32|64|_PTR)?|HANDLE|HMODULE|BOOL(?:EAN)?'
+ r'|U?SHORT|U?LONG|U?INT(?:8|16|32|64)?'
+ r'|BYTE|VOID|C[WT]?STR'
+ r')',
'https://docs.microsoft.com/en-us/windows/desktop/winprog/windows-data-types'
),
(
r'(?:__INTELLISENSE__|_MSC_FULL_VER|_MSC_VER|_MSVC_LANG|_WIN32|_WIN64)',
'https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019'
),
(r'IUnknowns?', 'https://docs.microsoft.com/en-us/windows/win32/api/unknwn/nn-unknwn-iunknown'),
(r'(?:IUnknown::)?QueryInterface?', 'https://docs.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-queryinterface(q)'),
(r'(?:Legacy)?InputIterators?', 'https://en.cppreference.com/w/cpp/named_req/InputIterator'),
(r'(?:Legacy)?OutputIterators?', 'https://en.cppreference.com/w/cpp/named_req/OutputIterator'),
(r'(?:Legacy)?ForwardIterators?', 'https://en.cppreference.com/w/cpp/named_req/ForwardIterator'),
(r'(?:Legacy)?BidirectionalIterators?', 'https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator'),
(r'(?:Legacy)?RandomAccessIterators?', 'https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator'),
(r'(?:Legacy)?ContiguousIterators?', 'https://en.cppreference.com/w/cpp/named_req/ContiguousIterator'),
(
r'(?:'
+ r'__cplusplus|__STDC_HOSTED__'
+ r'|__FILE__|__LINE__'
+ r'|__DATE__|__TIME__'
+ r'|__STDCPP_DEFAULT_NEW_ALIGNMENT__'
+ r')',
'https://en.cppreference.com/w/cpp/preprocessor/replace'
),
# toml-specific
(r'toml::values?', 'classtoml_1_1value.html'),
(r'(toml::)?date_times?', 'structtoml_1_1date__time.html'),
(r'(toml::)?time', 'structtoml_1_1time.html'),
(r'(toml::)?dates?', 'structtoml_1_1date.html')
]
class ExtDocLinksFix(object):
__allowedNames = ['dd', 'p', 'dt', 'h3', 'td', 'div']
def __init__(self):
global external_links
self.__expressions = []
for type, uri in self.__types:
for type, uri in external_links:
self.__expressions.append((re.compile('(?<![a-zA-Z_])'+type+'(?![a-zA-Z_])'), uri))
@classmethod
def __substitute(cls, m, uri):
external = uri.startswith('http')
return r'<a href="{}" class="m-doc tpp-injected{}"{}>{}</a>'.format(
return r'<a href="{}" class="m-doc muu-injected{}"{}>{}</a>'.format(
uri,
' tpp-external' if external else '',
' muu-external' if external else '',
' target="_blank"' if external else '',
m.group(0),
)
@ -867,10 +880,10 @@ class ExtDocLinksFix(object):
def __call__(self, file, doc):
changed = False
root = doc.body.main.article.div.div
tags = tags = html_shallow_search(root, self.__allowedNames, lambda t: html_find_parent(t, 'a', root) is None)
tags = html_shallow_search(root, self.__allowedNames, lambda t: html_find_parent(t, 'a', root) is None)
strings = []
for tag in tags:
strings = strings + html_string_descendants(tag, lambda t: html_find_parent(t, 'a', tag) is None)
strings = strings + html_string_descendants(tag, lambda t: html_find_parent(t, 'a', tag) is None)
for expr, uri in self.__expressions:
for string in strings:
if string.parent is None:
@ -905,21 +918,21 @@ class EnableIfFix(object):
)
__spacingFix1 = re.compile(r'(_v|>::value)(&&|\|\|)')
@classmethod
def __substitute(cls, m):
return r'{}<span class="tpp-injected tpp-enable-if"><a href="#" onclick="ToggleEnableIf(this);return false;">...</a><span>{}</span></span>{}'.format(
return r'{}<span class="muu-injected muu-enable-if"><a href="#" onclick="ToggleEnableIf(this);return false;">...</a><span>{}</span></span>{}'.format(
m.group(1),
m.group(2),
m.group(3)
)
def __call__(self, file, doc):
changed = False
for template in doc.body('div', class_='m-doc-template'):
replacer = RegexReplacer(self.__expression, lambda m: self.__substitute(m), str(template))
if replacer:
injected = html_replace_tag(template, str(replacer))[0].select_one(".tpp-enable-if")
injected = html_replace_tag(template, str(replacer))[0].select_one(".muu-enable-if")
anchor = injected.a
content = injected.span
tweaks = []
@ -954,7 +967,7 @@ class ExternalLinksFix(object):
if 'target' not in anchor.attrs or anchor['target'] != '_blank':
anchor['target'] = '_blank'
changed = True
changed = html_append_class(anchor, 'tpp-external') or changed
changed = html_append_class(anchor, 'muu-external') or changed
# do magic with godbolt.org links
if self.__godbolt.fullmatch(anchor['href']):
@ -975,6 +988,46 @@ class ExternalLinksFix(object):
# overrides <path/to/header.h> links
class HeaderOverridesFix(object):
def __init__(self):
global header_overrides
self.__expressions = []
for header, repl, html_file in header_overrides:
self.__expressions.append((
re.compile('(?:<|")'+header+'(?:>|")'),
'<' + repl + '>',
html_file
))
@classmethod
def __substitute(cls, m, repl):
return repl
def __call__(self, file, doc):
changed = False
root = doc.body.main.article.div.div
tags = root.find_all('a', string=True)
for tag in tags:
skip = False
for expr, repl, html_file in self.__expressions:
replacer = RegexReplacer(expr, lambda m: self.__substitute(m, repl), tag.string)
if replacer:
tag.string = str(replacer)
tag["href"] = html_file
changed = True
skip = True
if skip:
continue
return changed
#=======================================================================================================================
_threadError = False
@ -1018,7 +1071,7 @@ def preprocess_xml(xml_dir):
def main():
global _threadError
num_threads = os.cpu_count() * 2
root_dir = path.join(utils.get_script_folder(), '..')
docs_dir = path.join(root_dir, 'docs')
@ -1042,7 +1095,7 @@ def main():
# delete xml
utils.delete_directory(xml_dir)
# post-process html files
fixes = [
CustomTagsFix()
@ -1057,6 +1110,7 @@ def main():
, ExtDocLinksFix()
, EnableIfFix()
, ExternalLinksFix()
, HeaderOverridesFix()
]
files = [path.split(f) for f in utils.get_all_files(html_dir, any=('*.html', '*.htm'))]
if files:

View File

@ -81,9 +81,9 @@ def is_collection(val):
def is_pow2(v):
return v & (v-1) == 0
def next_power_of_2(n):
if n == 0:
return 1
@ -103,7 +103,7 @@ def get_all_files(dir, all=None, any=None):
all = [f for f in all if f is not None]
for fil in all:
files = fnmatch.filter(files, fil)
if (files and any is not None):
if (not is_collection(any)):
any = (any,)
@ -129,6 +129,43 @@ def make_divider(text = None, text_col = 40, pattern = '-', line_length = 120):
def __hash_combine_32(current_hash, next_hash):
current_hash = current_hash & 0xFFFFFFFF
next_hash = next_hash & 0xFFFFFFFF
current_hash = current_hash ^ (next_hash + 0x9E3779B9 + (current_hash << 6) + (current_hash >> 2))
return current_hash & 0xFFFFFFFF
def __hash_combine_64(current_hash, next_hash):
current_hash = current_hash & 0xFFFFFFFFFFFFFFFF
next_hash = next_hash & 0xFFFFFFFFFFFFFFFF
current_hash = current_hash ^ (next_hash + 0x9E3779B97F4A7C15 + (current_hash << 12) + (current_hash >> 4))
return current_hash & 0xFFFFFFFFFFFFFFFF
__hash_combine_func = None
if sys.hash_info.width == 64:
__hash_combine_func = __hash_combine_64
elif sys.hash_info.width == 32:
__hash_combine_func = __hash_combine_32
def hash_combine(current_hash, next_hash, *nexts):
global __hash_combine_func
current_hash = __hash_combine_func(current_hash, next_hash)
if nexts:
for n in nexts:
current_hash = __hash_combine_func(current_hash, n)
return current_hash
def multi_hash(obj, *objs):
h = hash(obj)
if objs:
for o in objs:
h = hash_combine(h, hash(o))
return h
def run(main_func):
try:
result = main_func()

View File

@ -97,10 +97,9 @@ TEST_CASE("arrays - copying")
// check the results of copy-assignment
arr2 = *arr1;
CHECK(arr2.source().begin == source_position{ 1, 8 });
CHECK(arr2.source().end == source_position{ 1, 17 });
CHECK(arr2.source().path);
CHECK(*arr2.source().path == filename);
CHECK(arr2.source().begin == source_position{});
CHECK(arr2.source().end == source_position{});
CHECK(!arr2.source().path);
CHECK(arr2.size() == 1_sz);
REQUIRE(arr2.get_as<std::string>(0_sz));
CHECK(*arr2.get_as<std::string>(0_sz) == "foo"sv);
@ -108,10 +107,9 @@ TEST_CASE("arrays - copying")
// check the results of copy-construction
array arr3{ arr2 };
CHECK(arr3.source().begin == source_position{ 1, 8 });
CHECK(arr3.source().end == source_position{ 1, 17 });
CHECK(arr3.source().path);
CHECK(*arr3.source().path == filename);
CHECK(arr3.source().begin == source_position{});
CHECK(arr3.source().end == source_position{});
CHECK(!arr3.source().path);
CHECK(arr3.size() == 1_sz);
REQUIRE(arr3.get_as<std::string>(0_sz));
CHECK(*arr3.get_as<std::string>(0_sz) == "foo"sv);

View File

@ -93,10 +93,9 @@ TEST_CASE("tables - copying")
// check the results of copy-assignment
tbl2 = tbl;
CHECK(tbl2.source().begin == source_position{ 1, 1 });
CHECK(tbl2.source().end == source_position{ 1, 24 });
CHECK(tbl2.source().path);
CHECK(*tbl2.source().path == filename);
CHECK(tbl2.source().begin == source_position{});
CHECK(tbl2.source().end == source_position{});
CHECK(!tbl2.source().path);
CHECK(tbl2.size() == 1_sz);
REQUIRE(tbl2["test"].as<table>());
CHECK(tbl2["test"].as<table>()->size() == 1_sz);
@ -105,10 +104,9 @@ TEST_CASE("tables - copying")
// check the results of copy-construction
table tbl3{ tbl2 };
CHECK(tbl3.source().begin == source_position{ 1, 1 });
CHECK(tbl3.source().end == source_position{ 1, 24 });
CHECK(tbl3.source().path);
CHECK(*tbl3.source().path == filename);
CHECK(tbl3.source().begin == source_position{});
CHECK(tbl3.source().end == source_position{});
CHECK(!tbl3.source().path);
CHECK(tbl3.size() == 1_sz);
REQUIRE(tbl3["test"].as<table>());
CHECK(tbl3["test"].as<table>()->size() == 1_sz);

View File

@ -2091,10 +2091,10 @@ TOML_NAMESPACE_START
protected:
node() noexcept = default;
node(const node&) noexcept = default;
node(node&& other) noexcept;
node& operator= (const node&) noexcept = default;
node& operator= (node&& rhs) noexcept;
node(const node&) noexcept;
node(node&&) noexcept;
node& operator= (const node&) noexcept;
node& operator= (node&&) noexcept;
template <typename T>
[[nodiscard]]
@ -7304,6 +7304,13 @@ TOML_DISABLE_SUGGEST_WARNINGS
TOML_NAMESPACE_START
{
TOML_EXTERNAL_LINKAGE
node::node(const node& /*other*/) noexcept
{
// does not copy source information
// this is not an error
}
TOML_EXTERNAL_LINKAGE
node::node(node && other) noexcept
: source_{ std::move(other.source_) }
@ -7313,7 +7320,17 @@ TOML_NAMESPACE_START
}
TOML_EXTERNAL_LINKAGE
node & node::operator= (node && rhs) noexcept
node& node::operator= (const node& /*rhs*/) noexcept
{
// does not copy source information
// this is not an error
source_ = {};
return *this;
}
TOML_EXTERNAL_LINKAGE
node& node::operator= (node && rhs) noexcept
{
source_ = std::move(rhs.source_);
rhs.source_.begin = {};