mirror of
https://github.com/boostorg/json.git
synced 2025-05-12 06:01:41 +00:00
parse_into clears sequences before filling them
This commit is contained in:
parent
f144f382d8
commit
75981e701e
@ -65,6 +65,10 @@ struct options
|
|||||||
|
|
||||||
iterator
|
iterator
|
||||||
end();
|
end();
|
||||||
|
|
||||||
|
void
|
||||||
|
clear()
|
||||||
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct coordinate
|
struct coordinate
|
||||||
@ -112,6 +116,10 @@ struct accumulator
|
|||||||
|
|
||||||
iterator
|
iterator
|
||||||
end() { return nullptr; }
|
end() { return nullptr; }
|
||||||
|
|
||||||
|
void
|
||||||
|
clear()
|
||||||
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct coordinates2
|
struct coordinates2
|
||||||
|
@ -502,6 +502,32 @@ std::true_type check_inserter( It1, It2 )
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void
|
||||||
|
clear_container(
|
||||||
|
T&,
|
||||||
|
mp11::mp_int<2>)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void
|
||||||
|
clear_container(
|
||||||
|
T& target,
|
||||||
|
mp11::mp_int<1>)
|
||||||
|
{
|
||||||
|
target.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void
|
||||||
|
clear_container(
|
||||||
|
T& target,
|
||||||
|
mp11::mp_int<0>)
|
||||||
|
{
|
||||||
|
target.clear();
|
||||||
|
}
|
||||||
|
|
||||||
template< class V, class P >
|
template< class V, class P >
|
||||||
class converting_handler<sequence_conversion_tag, V, P>
|
class converting_handler<sequence_conversion_tag, V, P>
|
||||||
: public composite_handler<
|
: public composite_handler<
|
||||||
@ -553,14 +579,11 @@ public:
|
|||||||
bool on_array_begin( error_code& ec )
|
bool on_array_begin( error_code& ec )
|
||||||
{
|
{
|
||||||
if( this->inner_active_ )
|
if( this->inner_active_ )
|
||||||
{
|
|
||||||
return this->inner_.on_array_begin( ec );
|
return this->inner_.on_array_begin( ec );
|
||||||
}
|
|
||||||
else
|
this->inner_active_ = true;
|
||||||
{
|
clear_container( *value_, inserter_implementation<V>() );
|
||||||
this->inner_active_ = true;
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool on_array_end( error_code& ec )
|
bool on_array_end( error_code& ec )
|
||||||
@ -605,6 +628,7 @@ public:
|
|||||||
if( this->inner_active_ )
|
if( this->inner_active_ )
|
||||||
return this->inner_.on_object_begin(ec);
|
return this->inner_.on_object_begin(ec);
|
||||||
|
|
||||||
|
clear_container( *value_, inserter_implementation<V>() );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,6 +252,13 @@ public:
|
|||||||
error::size_mismatch, {1, 2, 3} );
|
error::size_mismatch, {1, 2, 3} );
|
||||||
|
|
||||||
testParseInto< std::vector<std::array<int, 4>> >( {arr,arr,arr} );
|
testParseInto< std::vector<std::array<int, 4>> >( {arr,arr,arr} );
|
||||||
|
|
||||||
|
std::vector<int> v;
|
||||||
|
parse_into(v, "[1,2,3,4]");
|
||||||
|
BOOST_TEST( v.size() == 4 );
|
||||||
|
|
||||||
|
parse_into(v, "[5,6,7]");
|
||||||
|
BOOST_TEST( v.size() == 3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void testMap()
|
void testMap()
|
||||||
@ -272,6 +279,13 @@ public:
|
|||||||
error::not_object, { "1", 1, "2", 2} );
|
error::not_object, { "1", 1, "2", 2} );
|
||||||
testParseIntoErrors< std::map<std::string, std::map<std::string, int>> >(
|
testParseIntoErrors< std::map<std::string, std::map<std::string, int>> >(
|
||||||
error::not_object, { {"1", {}}, {"2", {"3", 4}} } );
|
error::not_object, { {"1", {}}, {"2", {"3", 4}} } );
|
||||||
|
|
||||||
|
std::map<std::string, int> m;
|
||||||
|
parse_into(m, R"( {"1": 1, "2": 2, "3": 3} )");
|
||||||
|
BOOST_TEST( m.size() == 3 );
|
||||||
|
|
||||||
|
parse_into(m, R"( {"4": 4, "5": 5} )");
|
||||||
|
BOOST_TEST( m.size() == 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void testTuple()
|
void testTuple()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user