Skip to content

Commit 0a9b672

Browse files
committed
Add empty_binary
1 parent 9dad166 commit 0a9b672

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

include/tao/json/internal/totally_ordered.hpp

+20
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,26 @@ namespace tao
314314
}
315315
};
316316

317+
template< typename T >
318+
struct totally_ordered< T, empty_binary_t, type::BINARY >
319+
: operators::totally_ordered< T, empty_binary_t >
320+
{
321+
friend bool operator==( const T& lhs, empty_binary_t rhs ) noexcept
322+
{
323+
return lhs == T( rhs );
324+
}
325+
326+
friend bool operator<( const T& lhs, empty_binary_t rhs ) noexcept
327+
{
328+
return lhs < T( rhs );
329+
}
330+
331+
friend bool operator>( const T& lhs, empty_binary_t rhs ) noexcept
332+
{
333+
return lhs > T( rhs );
334+
}
335+
};
336+
317337
template< typename T >
318338
struct totally_ordered< T, empty_array_t, type::ARRAY >
319339
: operators::totally_ordered< T, empty_array_t >

include/tao/json/traits.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,16 @@ namespace tao
267267
}
268268
};
269269

270+
template<>
271+
struct traits< empty_binary_t >
272+
{
273+
template< template< typename... > class Traits >
274+
static void assign( basic_value< Traits >& v, empty_binary_t )
275+
{
276+
v.unsafe_emplace_binary();
277+
}
278+
};
279+
270280
template<>
271281
struct traits< empty_array_t >
272282
{

include/tao/json/type.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ namespace tao
7979
}
8080
};
8181

82+
struct empty_binary_t
83+
{
84+
constexpr explicit empty_binary_t( int )
85+
{
86+
}
87+
};
88+
8289
struct empty_array_t
8390
{
8491
constexpr explicit empty_array_t( int )
@@ -94,6 +101,7 @@ namespace tao
94101
};
95102

96103
constexpr null_t null{ 0 };
104+
constexpr empty_binary_t empty_binary{ 0 };
97105
constexpr empty_array_t empty_array{ 0 };
98106
constexpr empty_object_t empty_object{ 0 };
99107

include/tao/json/value.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace tao
6868
internal::totally_ordered< basic_value< Traits >, std::string, type::STRING >,
6969
internal::totally_ordered< basic_value< Traits >, const char*, type::STRING >,
7070
internal::totally_ordered< basic_value< Traits >, std::vector< byte >, type::BINARY >,
71+
internal::totally_ordered< basic_value< Traits >, empty_binary_t, type::BINARY >,
7172
internal::totally_ordered< basic_value< Traits >, std::vector< basic_value< Traits > >, type::ARRAY >,
7273
internal::totally_ordered< basic_value< Traits >, empty_array_t, type::ARRAY >,
7374
internal::totally_ordered< basic_value< Traits >, std::map< std::string, basic_value< Traits > >, type::OBJECT >,

src/test/json/parse_jaxn.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ namespace tao
174174
TEST_THROWS( jaxn::from_string( "'f\0o'" ) );
175175
TEST_THROWS( jaxn::from_string( "\n\n'123456789\0'" ) );
176176

177-
TEST_ASSERT( jaxn::from_string( "$" ) == std::vector< json::byte >{} );
178-
TEST_ASSERT( jaxn::from_string( "$''" ) == std::vector< json::byte >{} );
179-
TEST_ASSERT( jaxn::from_string( "$+$''" ) == std::vector< json::byte >{} );
180-
TEST_ASSERT( jaxn::from_string( "$''+$" ) == std::vector< json::byte >{} );
177+
TEST_ASSERT( jaxn::from_string( "$" ) == empty_binary );
178+
TEST_ASSERT( jaxn::from_string( "$''" ) == empty_binary );
179+
TEST_ASSERT( jaxn::from_string( "$+$''" ) == empty_binary );
180+
TEST_ASSERT( jaxn::from_string( "$''+$" ) == empty_binary );
181181

182182
TEST_ASSERT( jaxn::from_string( "$'a'" ) == 0x61_binary );
183183
TEST_ASSERT( jaxn::from_string( "$+$'a'" ) == 0x61_binary );

0 commit comments

Comments
 (0)