|
4 | 4 | #include "jss_core.h" |
5 | 5 | #include "jss_object.h" |
6 | 6 | #include "jss_check.h" |
| 7 | +#include "jss_optional.h" |
7 | 8 | #include <functional> |
8 | 9 |
|
9 | 10 | namespace JSON { namespace Internal |
10 | 11 | { |
11 | 12 | template <typename T, template <typename, class = std::allocator <T> > class ContainerT, |
12 | 13 | typename FuncT = std::function <typename ContainerT<T>::const_iterator(ContainerT<T> const&)>, |
13 | 14 | class = typename std::enable_if<Internal::can_stringify<typename ContainerT<T>::value_type>::value>::type > |
14 | | - inline std::ostream& stringify_i(std::ostream& stream, std::string const& name, ContainerT <T> const& values, FuncT end_iter, StringificationOptions const& options = DEFAULT_OPTIONS) |
| 15 | + inline std::ostream& stringify_i(std::ostream& stream, std::string const& name, ContainerT <T> const& values, StringificationOptions const& options = DEFAULT_OPTIONS) |
15 | 16 | { |
16 | 17 | using namespace Internal; |
17 | 18 |
|
18 | 19 | WRITE_ARRAY_START(stream); |
19 | | - if (!values.empty()) |
| 20 | + auto noNameOption = options; |
| 21 | + noNameOption.ignore_name = true; |
| 22 | + |
| 23 | + bool first = true; |
| 24 | + for (auto const& i : values) |
20 | 25 | { |
21 | | - auto end = end_iter(values); |
22 | | - APPLY_IO_MANIPULATERS(stream); |
23 | | - auto noNameOption = options; |
24 | | - noNameOption.ignore_name = true; |
25 | | - auto i = values.begin(); |
26 | | - for (; i != end; ++i) |
| 26 | + if (Internal::is_optional_set(i)) |
27 | 27 | { |
28 | | - stringify(stream, {}, *i, noNameOption); |
29 | | - stream << options.delimiter; |
| 28 | + if (!first) |
| 29 | + stream << options.delimiter; |
| 30 | + stringify(stream, {}, i, noNameOption); |
| 31 | + first = false; |
30 | 32 | } |
31 | | - stringify(stream, {}, *i, noNameOption); |
32 | 33 | } |
33 | 34 | WRITE_ARRAY_END(stream); |
34 | 35 | return stream; |
|
0 commit comments