33 Commits

Author SHA1 Message Date
Simon Gene Gottlieb bd070a7b76 fix: prettier floating point numbers
Add dragonbox to compute the required precision to print floating point
numbers. This avoids uglification of floating point numbers that
happen by default via std::stringstream.

Numbers like 34.34 used to be converted to '34.340000000000003' as strings.
With this version they will be converted to the string '34.34'.

This fixes issue https://github.com/jbeder/yaml-cpp/issues/1289
2024-11-07 15:14:36 -06:00
Reini Urban 3d2888cc8a missing keys should throw InvalidNode, not BadConversion
Fixes GH #1274
2024-11-01 10:25:39 -05:00
Simon Gene Gottlieb b95aa146ec fix: use C locale by default 2024-07-17 13:39:30 -05:00
Kefu Chai 35b4498026 node/convert: support conversion for std::string_view (#1148) 2023-07-24 14:51:05 -05:00
Matthijs van der Burgh bdc5582b35 Add tests for iterator and const_iterator on sequence (#1169) 2023-03-01 19:27:51 -06:00
sfalmo 4ae4cb7309 Support conversion for std::valarray (#956) 2022-09-20 00:31:51 -05:00
Chen bce601f2bf Support the conversion for std::unordered_map (#932) 2022-01-05 18:12:40 -06:00
Ian Taylor 9fb5153487 implement convert for standard library containers allowing for custom allocators (#855) 2020-04-29 18:29:33 -05:00
Ted Lyngmo 1d8542ad32 Add NodeTest EqualRepresentationAfterMoveAssignment (#816)
Add check that a move assigned Node gets the same representation as the
moved-from Node had before the move.
2020-04-07 20:08:56 -05:00
Anton Onishchenko de8253fcb0 Fix storing inf and NaN (#817) 2020-02-14 18:03:21 -06:00
JeffWegher 29dcf92f87 Fix Node::size() after removing node from sequence (#820) 2020-02-14 14:38:58 -06:00
Igor [hyperxor] 72f699f5ce Remove redundant checks and add more unit tests (#783) 2019-11-04 10:19:02 -06:00
Simon Gene Gottlieb abf941b20d Fix float precision (#649)
The issue is that numbers like
2.01 or 3.01 can not be precisely represented with binary floating point
numbers.

This replaces all occurrences of 'std::numeric_limits<T>::digits10 + 1' with
'std::numeric_limits<T>::max_digits10'.

Background:
Using 'std::numeric_limits<T>::digits10 + 1' is not precise enough.
Converting a 'float' into a 'string' and back to a 'float' will not always
produce the original 'float' value. To guarantee that the 'string'
representation has sufficient precision the value
'std::numeric_limits<T>::max_digits10' has to be used.
2018-12-21 09:05:19 -05:00
Jiao 4fb1c4b92b Enable items to be removed from a sequence (#582) 2018-05-14 08:50:28 -05:00
butataatawa f82861001a Fix sequence sometimes not turning into a map (#450)
Previously, just referencing the next element in the sequence (and so constructing it, as an undefined element) would allow you to skip defining an element without turning the sequence into a map. E.g:

node[0] = "foo"; // sequence of size 1
node[1]; // sequence of size 1, with an undefined element at 1
node[2] = "bar"; // FIX: should be map of size 2 (since there's no element at index 1)
2017-01-02 15:44:22 -06:00
butataatawa 147d909fe6 Fix inconsistent Node::size when removing a key with unassigned node (#327) (#449) 2016-12-06 08:40:00 -06:00
Jesse Beder b5b03bb9ad Run clang-format. 2016-10-12 00:00:39 -05:00
c0nk f0b15cd6a0 Change node_map type from map<ptr,ptr> to vector<pair<ptr,ptr>> (#386)
* Change node_map type from map<ptr,ptr> to vector<pair<ptr,ptr>>

Map nodes are now iterated over in document order.

* Change insert_map_pair to always append

Always append in insert_map_pair even if the key is already present.
This breaks the behavior of force_insert which now always inserts KVs
even if the key is already present. The first insert for duplicated keys
now takes precedence for lookups.
2016-07-18 08:54:10 -05:00
Vincent Cogne 7c33b3cdab Add convert specialization for std::array. 2016-06-12 21:59:31 -05:00
Michael Welsh Duggan 320b02b14a Allow using a Node as the key in force_insert.
Node::force_insert() uses convert<> to convert its key to a node.
Add a specialization for convert<Node>.
2015-11-22 11:21:08 -06:00
Jonathan Hamilton b426fafff6 Fix some Node::operator[] regressions from 0.5.1
"const Node Node::operator[](const Key& key) const" changed from
returning new empty node if the key was missing in 0.5.1 to returning
a shared 'zombie' node in 0.5.2 to resolve a memory leak.

(Specifically 1025f76df1 was where this
was introduced)

This caused some regressions where this 'zombie' object threw exceptions
in some functions where the 'empty' object would not.

This change fixes the Node::as(fallback) method (to return the
'fallback' instead of throwing an exception) and the
Node::begin()/Node::end() methods to return default-constructed
iterators (so begin() == end() in such cases) instead of another
exception.
2015-06-08 11:47:10 -07:00
bdutro aa928b925b Update node_data::remove to use new equals() method
- Update the call to equals() in node_data::remove() to match the new implementation
- Add unit test for node::remove() to catch this type of bug in the future
2015-04-08 13:41:59 -05:00
Jesse Beder 25b2ed0787 Fix operator bool() exception on zombie node 2015-03-29 14:31:22 -05:00
Jesse Beder 39e7b651dc Fix test that depended on the order of map outputs 2015-02-21 12:14:53 -06:00
Jesse Beder c9729b26a4 Remove stray 'auto' that leaked in without C++11 2015-01-24 15:34:39 -06:00
Jesse Beder 9eae039c91 Merge 2015-01-24 13:24:08 -06:00
Jesse Beder 0c280724e9 Add flow/block style setting on Nodes 2015-01-24 13:11:43 -06:00
Jesse Beder 2c340f0546 Fixed memory corruption when using a node as a key 2014-08-16 10:52:51 -05:00
Jesse Beder 1aa25e7679 Wrap the #pragma warning for msvc in an ifdef 2014-03-25 22:08:34 -05:00
Jesse Beder 13130ec20d clang-format 2014-03-25 00:11:17 -05:00
Jesse Beder 7a68eaafd9 Disable warning:
warning C4800: forcing value to bool 'true' or 'false' (performance warning)

for the node test, since it really doesn't make any sense in this context. (It's exactly what we intended with the "unspecified bool type".)
2014-03-23 22:42:06 -05:00
Jesse Beder ad0a3311a7 Convert node tests to gtest 2014-03-23 19:21:13 -05:00
Jesse Beder da118bbb0d Add test for cloning a null node 2014-03-22 23:29:14 -05:00