46#if __cplusplus >= 201103L
47# define CTOON_NOEXCEPT noexcept
49# define CTOON_NOEXCEPT throw()
52#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
53# include <string_view>
54 namespace ctoon {
using string_view = std::string_view; }
59 string_view() CTOON_NOEXCEPT : d_(""), n_(0) {}
60 string_view(
const char *p, std::size_t n) CTOON_NOEXCEPT
61 : d_(p ? p :
""), n_(p ? n : 0) {}
62 string_view(
const char *p) CTOON_NOEXCEPT
63 : d_(p ? p :
""), n_(p ? std::strlen(p) : 0) {}
64 string_view(
const std::string &s) CTOON_NOEXCEPT
65 : d_(s.data()), n_(s.size()) {}
66 const char *data() const CTOON_NOEXCEPT {
return d_; }
67 std::size_t size() const CTOON_NOEXCEPT {
return n_; }
68 bool empty() const CTOON_NOEXCEPT {
return n_ == 0; }
69 std::string str()
const {
return std::string(d_, n_); }
70 bool operator==(
const string_view &o)
const CTOON_NOEXCEPT {
71 return n_ == o.n_ && std::memcmp(d_, o.d_, n_) == 0;
73 bool operator!=(
const string_view &o)
const CTOON_NOEXCEPT {
return !(*
this == o); }
90 static unsigned int major() CTOON_NOEXCEPT {
return CTOON_VERSION_MAJOR; }
91 static unsigned int minor() CTOON_NOEXCEPT {
return CTOON_VERSION_MINOR; }
92 static unsigned int patch() CTOON_NOEXCEPT {
return CTOON_VERSION_PATCH; }
93 static unsigned int hex() CTOON_NOEXCEPT {
return CTOON_VERSION_HEX; }
94 static string_view
string() CTOON_NOEXCEPT {
return CTOON_VERSION_STRING; }
108 static unsigned int major() CTOON_NOEXCEPT {
return CTOON_SPEC_TAG_MAJOR; }
109 static unsigned int minor() CTOON_NOEXCEPT {
return CTOON_SPEC_TAG_MINOR; }
110 static unsigned int patch() CTOON_NOEXCEPT {
return CTOON_SPEC_TAG_PATCH; }
111 static unsigned int hex() CTOON_NOEXCEPT {
return CTOON_SPEC_TAG_HEX; }
112 static string_view
string() CTOON_NOEXCEPT {
return CTOON_SPEC_TAG_STRING; }
120 static string_view
string() CTOON_NOEXCEPT {
return CTOON_SPEC_VERSION_STRING; }
128 static string_view
string() CTOON_NOEXCEPT {
return CTOON_SPEC_DATE_STRING; }
140class error :
public std::exception {
142 explicit error(
const std::string &msg) CTOON_NOEXCEPT :
msg_(msg) {}
143 virtual const char *
what() const CTOON_NOEXCEPT {
return msg_.c_str(); }
157 static std::string build_msg(
const ctoon_read_err &e) {
158 std::string m(e.msg ? e.msg :
"parse error");
159 char buf[32]; std::sprintf(buf,
" (pos %zu)", e.pos);
182 :
ptr_(o.ptr_),
len_(o.len_) { o.ptr_ = NULL; o.len_ = 0; }
184 if (
this != &o) { std::free(
ptr_);
ptr_ = o.ptr_;
len_ = o.len_; o.ptr_ = NULL; o.len_ = 0; }
188 std::size_t
size() const CTOON_NOEXCEPT {
return len_; }
201 COMMA = CTOON_DELIMITER_COMMA,
202 TAB = CTOON_DELIMITER_TAB,
203 PIPE = CTOON_DELIMITER_PIPE,
214 NOFLAG =
static_cast<uint32_t
>(CTOON_WRITE_NOFLAG),
215 ESCAPE_UNICODE =
static_cast<uint32_t
>(CTOON_WRITE_ESCAPE_UNICODE),
216 ESCAPE_SLASHES =
static_cast<uint32_t
>(CTOON_WRITE_ESCAPE_SLASHES),
220 LENGTH_MARKER =
static_cast<uint32_t
>(CTOON_WRITE_LENGTH_MARKER),
221 NEWLINE_AT_END =
static_cast<uint32_t
>(CTOON_WRITE_NEWLINE_AT_END),
225 return static_cast<write_flag>(
static_cast<uint32_t
>(l) |
static_cast<uint32_t
>(r));
232 return static_cast<ctoon_write_flag
>(
static_cast<uint32_t
>(f));
240 NOFLAG =
static_cast<uint32_t
>(CTOON_READ_NOFLAG),
241 INSITU =
static_cast<uint32_t
>(CTOON_READ_INSITU),
242 STOP_WHEN_DONE =
static_cast<uint32_t
>(CTOON_READ_STOP_WHEN_DONE),
244 ALLOW_COMMENTS =
static_cast<uint32_t
>(CTOON_READ_ALLOW_COMMENTS),
246 NUMBER_AS_RAW =
static_cast<uint32_t
>(CTOON_READ_NUMBER_AS_RAW),
248 BIGNUM_AS_RAW =
static_cast<uint32_t
>(CTOON_READ_BIGNUM_AS_RAW),
249 ALLOW_BOM =
static_cast<uint32_t
>(CTOON_READ_ALLOW_BOM),
255 NON_STRICT =
static_cast<uint32_t
>(CTOON_READ_NON_STRICT),
259 return static_cast<read_flag>(
static_cast<uint32_t
>(l) |
static_cast<uint32_t
>(r));
266 return static_cast<ctoon_read_flag
>(
static_cast<uint32_t
>(f));
284 int indent() const CTOON_NOEXCEPT {
return indent_; }
286 ctoon_write_options
to_c() const CTOON_NOEXCEPT {
287 ctoon_write_options o;
289 o.delimiter =
static_cast<ctoon_delimiter
>(delimiter_);
315 explicit value(ctoon_val *v) CTOON_NOEXCEPT :
v_(v) {}
317 ctoon_val *
raw() const CTOON_NOEXCEPT {
return v_; }
318 bool valid() const CTOON_NOEXCEPT {
return v_ != NULL; }
319 operator bool() const CTOON_NOEXCEPT {
return valid(); }
322 bool is_null() const CTOON_NOEXCEPT {
return v_ && ctoon_is_null(
v_); }
323 bool is_true() const CTOON_NOEXCEPT {
return v_ && ctoon_is_true(
v_); }
324 bool is_false() const CTOON_NOEXCEPT {
return v_ && ctoon_is_false(
v_); }
325 bool is_bool() const CTOON_NOEXCEPT {
return v_ && ctoon_is_bool(
v_); }
326 bool is_uint() const CTOON_NOEXCEPT {
return v_ && ctoon_is_uint(
v_); }
327 bool is_sint() const CTOON_NOEXCEPT {
return v_ && ctoon_is_sint(
v_); }
328 bool is_int() const CTOON_NOEXCEPT {
return v_ && ctoon_is_int(
v_); }
329 bool is_real() const CTOON_NOEXCEPT {
return v_ && ctoon_is_real(
v_); }
330 bool is_num() const CTOON_NOEXCEPT {
return v_ && ctoon_is_num(
v_); }
331 bool is_str() const CTOON_NOEXCEPT {
return v_ && ctoon_is_str(
v_); }
332 bool is_arr() const CTOON_NOEXCEPT {
return v_ && ctoon_is_arr(
v_); }
333 bool is_obj() const CTOON_NOEXCEPT {
return v_ && ctoon_is_obj(
v_); }
336 bool get_bool() const CTOON_NOEXCEPT {
return v_ && ctoon_get_bool(
v_); }
337 std::uint64_t
get_uint() const CTOON_NOEXCEPT {
return v_ ? ctoon_get_uint(
v_) : 0; }
338 std::int64_t
get_sint() const CTOON_NOEXCEPT {
return v_ ? ctoon_get_sint(
v_) : 0; }
339 double get_real() const CTOON_NOEXCEPT {
return v_ ? ctoon_get_real(
v_) : 0.0; }
340 double get_num() const CTOON_NOEXCEPT {
return v_ ? ctoon_get_num(
v_) : 0.0; }
341 std::size_t
get_len() const CTOON_NOEXCEPT {
return v_ ? ctoon_get_len(
v_) : 0; }
343 if (!
v_)
return string_view();
344 const char *s = ctoon_get_str(
v_);
345 return s ? string_view(s, ctoon_get_len(
v_)) : string_view();
349 std::size_t
arr_size() const CTOON_NOEXCEPT {
return v_ ? ctoon_arr_size(
v_) : 0; }
356 std::size_t
obj_size() const CTOON_NOEXCEPT {
return v_ ? ctoon_obj_size(
v_) : 0; }
359 return value(
v_ ? ctoon_obj_getn(
v_, key.data(), key.size()) : NULL);
365 bool equals(
const value &rhs)
const CTOON_NOEXCEPT {
return v_ && rhs.v_ && ctoon_equals(
v_, rhs.v_); }
366 bool equals(
const char *s)
const CTOON_NOEXCEPT {
return v_ && ctoon_equals_str(
v_, s); }
367 bool equals(
const string_view &s)
const CTOON_NOEXCEPT {
return v_ && ctoon_equals_strn(
v_, s.data(), s.size()); }
371 return value(
v_ ? ctoon_ptr_getn(
v_, ptr.data(), ptr.size()) : NULL);
376 ctoon_write_options co = opts.to_c();
377 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
379 char *
raw = ctoon_val_write_opts(
v_, &co, NULL, &len, &err);
388 explicit arr_iterator(ctoon_val *arr,
bool end =
false) : cur_(NULL) {
389 if (!arr || end) { std::memset(&iter_, 0,
sizeof(iter_));
return; }
390 ctoon_arr_iter_init(arr, &iter_);
391 cur_ = ctoon_arr_iter_next(&iter_);
393 value operator*() const CTOON_NOEXCEPT {
return value(cur_); }
394 arr_iterator &operator++() CTOON_NOEXCEPT { cur_ = ctoon_arr_iter_next(&iter_);
return *
this; }
395 bool operator!=(
const arr_iterator &o)
const CTOON_NOEXCEPT {
return cur_ != o.cur_; }
397 ctoon_arr_iter iter_;
402 arr_iterator begin()
const {
return arr_iterator(arr); }
403 arr_iterator end()
const {
return arr_iterator(arr,
true); }
405 arr_range arr_items() const CTOON_NOEXCEPT { arr_range r; r.arr =
v_;
return r; }
408 ctoon_val *key_raw, *val_raw;
409 value key()
const {
return value(key_raw); }
410 value val()
const {
return value(val_raw); }
414 explicit obj_iterator(ctoon_val *obj,
bool end =
false) : key_(NULL) {
415 if (!obj || end) { std::memset(&iter_, 0,
sizeof(iter_));
return; }
416 ctoon_obj_iter_init(obj, &iter_);
417 key_ = ctoon_obj_iter_next(&iter_);
419 kv_pair operator*() const CTOON_NOEXCEPT {
420 kv_pair kv; kv.key_raw = key_; kv.val_raw = ctoon_obj_iter_get_val(key_);
return kv;
422 obj_iterator &operator++() CTOON_NOEXCEPT { key_ = ctoon_obj_iter_next(&iter_);
return *
this; }
423 bool operator!=(
const obj_iterator &o)
const CTOON_NOEXCEPT {
return key_ != o.key_; }
425 ctoon_obj_iter iter_;
430 obj_iterator begin()
const {
return obj_iterator(obj); }
431 obj_iterator end()
const {
return obj_iterator(obj,
true); }
433 obj_range obj_items() const CTOON_NOEXCEPT { obj_range r; r.obj =
v_;
return r; }
449 ctoon_mut_val *
raw() const CTOON_NOEXCEPT {
return v_; }
450 bool valid() const CTOON_NOEXCEPT {
return v_ != NULL; }
451 operator bool() const CTOON_NOEXCEPT {
return valid(); }
454 bool is_null() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_null(
v_); }
455 bool is_true() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_true(
v_); }
456 bool is_false() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_false(
v_); }
457 bool is_bool() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_bool(
v_); }
458 bool is_uint() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_uint(
v_); }
459 bool is_sint() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_sint(
v_); }
460 bool is_int() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_int(
v_); }
461 bool is_real() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_real(
v_); }
462 bool is_num() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_num(
v_); }
463 bool is_str() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_str(
v_); }
464 bool is_arr() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_arr(
v_); }
465 bool is_obj() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_obj(
v_); }
468 bool get_bool() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_get_bool(
v_); }
469 std::uint64_t
get_uint() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_get_uint(
v_) : 0; }
470 std::int64_t
get_sint() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_get_sint(
v_) : 0; }
471 double get_real() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_get_real(
v_) : 0.0; }
472 double get_num() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_get_num(
v_) : 0.0; }
473 std::size_t
get_len() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_get_len(
v_) : 0; }
475 if (!
v_)
return string_view();
476 const char *s = ctoon_mut_get_str(
v_);
477 return s ? string_view(s, ctoon_mut_get_len(
v_)) : string_view();
481 std::size_t
arr_size() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_arr_size(
v_) : 0; }
488 std::size_t
obj_size() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_obj_size(
v_) : 0; }
491 return mut_value(
v_ ? ctoon_mut_obj_getn(
v_, key.data(), key.size()) : NULL);
497 bool equals(
const mut_value &rhs)
const CTOON_NOEXCEPT {
return v_ && rhs.v_ && ctoon_mut_equals(
v_, rhs.v_); }
498 bool equals(
const char *s)
const CTOON_NOEXCEPT {
return v_ && ctoon_mut_equals_str(
v_, s); }
499 bool equals(
const string_view &s)
const CTOON_NOEXCEPT {
return v_ && ctoon_mut_equals_strn(
v_, s.data(), s.size()); }
503 return mut_value(
v_ ? ctoon_mut_ptr_getn(
v_, ptr.data(), ptr.size()) : NULL);
509 bool arr_clear() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_arr_clear(
v_); }
516 return v_ && key.v_ && val.v_ && ctoon_mut_obj_add(
v_, key.v_, val.v_);
519 return v_ && key.v_ && val.v_ && ctoon_mut_obj_put(
v_, key.v_, val.v_);
521 bool obj_clear() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_obj_clear(
v_); }
523 return mut_value(
v_ ? ctoon_mut_obj_remove_keyn(
v_, key.data(), key.size()) : NULL);
530 explicit arr_iterator(ctoon_mut_val *arr,
bool end =
false) : cur_(NULL) {
531 if (!arr || end) { std::memset(&iter_, 0,
sizeof(iter_));
return; }
532 ctoon_mut_arr_iter_init(arr, &iter_);
533 cur_ = ctoon_mut_arr_iter_next(&iter_);
535 mut_value operator*() const CTOON_NOEXCEPT {
return mut_value(cur_); }
536 arr_iterator &operator++() CTOON_NOEXCEPT { cur_ = ctoon_mut_arr_iter_next(&iter_);
return *
this; }
537 bool operator!=(
const arr_iterator &o)
const CTOON_NOEXCEPT {
return cur_ != o.cur_; }
539 ctoon_mut_arr_iter iter_;
544 arr_iterator begin()
const {
return arr_iterator(arr); }
545 arr_iterator end()
const {
return arr_iterator(arr,
true); }
547 arr_range arr_items() const CTOON_NOEXCEPT { arr_range r; r.arr =
v_;
return r; }
550 ctoon_mut_val *key_raw, *val_raw;
551 mut_value key()
const {
return mut_value(key_raw); }
552 mut_value val()
const {
return mut_value(val_raw); }
556 explicit obj_iterator(ctoon_mut_val *obj,
bool end =
false) : key_(NULL) {
557 if (!obj || end) { std::memset(&iter_, 0,
sizeof(iter_));
return; }
558 ctoon_mut_obj_iter_init(obj, &iter_);
559 key_ = ctoon_mut_obj_iter_next(&iter_);
561 kv_pair operator*() const CTOON_NOEXCEPT {
562 kv_pair kv; kv.key_raw = key_; kv.val_raw = ctoon_mut_obj_iter_get_val(key_);
return kv;
564 obj_iterator &operator++() CTOON_NOEXCEPT { key_ = ctoon_mut_obj_iter_next(&iter_);
return *
this; }
565 bool operator!=(
const obj_iterator &o)
const CTOON_NOEXCEPT {
return key_ != o.key_; }
567 ctoon_mut_obj_iter iter_;
572 obj_iterator begin()
const {
return obj_iterator(obj); }
573 obj_iterator end()
const {
return obj_iterator(obj,
true); }
575 obj_range obj_items() const CTOON_NOEXCEPT { obj_range r; r.obj =
v_;
return r; }
594 if (
this != &o) { ctoon_doc_free(
doc_);
doc_ = o.doc_; o.doc_ = NULL; }
601 ctoon_read_err err; std::memset(&err, 0,
sizeof(err));
602 ctoon_doc *d = ctoon_read_opts(
const_cast<char *
>(toon), len,
to_c(flags), NULL, &err);
607 return parse(toon, std::strlen(toon), flags);
610 return parse(toon.data(), toon.size(), flags);
613 return parse(toon.data(), toon.size(), flags);
619 ctoon_read_err err; std::memset(&err, 0,
sizeof(err));
620 ctoon_doc *d = ctoon_read_opts_indent(
const_cast<char *
>(toon), len,
621 to_c(flags), indent_size, NULL, &err);
627 return parse_indent(toon.data(), toon.size(), indent_size, flags);
631 return parse_indent(toon.data(), toon.size(), indent_size, flags);
634 ctoon_read_err err; std::memset(&err, 0,
sizeof(err));
635 ctoon_doc *d = ctoon_read_file(path,
to_c(flags), NULL, &err);
640#if defined(CTOON_ENABLE_JSON) && CTOON_ENABLE_JSON
643 ctoon_read_err err; std::memset(&err, 0,
sizeof(err));
644 ctoon_doc *d = ctoon_read_json(
const_cast<char *
>(json), len,
to_c(flags), NULL, &err);
649 return from_json(json, std::strlen(json), flags);
652 return from_json(json.data(), json.size(), flags);
655 return from_json(json.data(), json.size(), flags);
658 ctoon_read_err err; std::memset(&err, 0,
sizeof(err));
659 ctoon_doc *d = ctoon_read_json_file(path,
to_c(flags), NULL, &err);
666 bool valid() const CTOON_NOEXCEPT {
return doc_ != NULL; }
667 operator bool() const CTOON_NOEXCEPT {
return valid(); }
670 ctoon_doc *
raw() const CTOON_NOEXCEPT {
return doc_; }
671 std::size_t
read_size() const CTOON_NOEXCEPT {
return ctoon_doc_get_read_size(
doc_); }
672 std::size_t
val_count() const CTOON_NOEXCEPT {
return ctoon_doc_get_val_count(
doc_); }
675 return value(ctoon_doc_ptr_getn(
doc_, ptr.data(), ptr.size()));
680 ctoon_write_options co = opts.to_c();
681 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
683 char *
raw = ctoon_write_opts(
doc_, &co, NULL, &len, &err);
689 ctoon_write_options co = opts.to_c();
690 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
691 if (!ctoon_write_file(path,
doc_, &co, NULL, &err))
throw write_error(err);
695#if defined(CTOON_ENABLE_JSON) && CTOON_ENABLE_JSON
698 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
700 char *
raw = ctoon_doc_to_json(
doc_, indent,
to_c(flags), NULL, &len, &err);
706 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
708 char *
raw = ctoon_doc_to_json(
doc_, indent,
to_c(flags), NULL, &len, &err);
710 FILE *fp = std::fopen(path,
"wb");
712 std::fwrite(
raw, 1, len, fp);
738 if (
this != &o) { ctoon_mut_doc_free(
doc_);
doc_ = o.doc_; o.doc_ = NULL; }
743 ctoon_mut_doc *d = ctoon_mut_doc_new(NULL);
744 if (!d)
throw std::bad_alloc();
749 bool valid() const CTOON_NOEXCEPT {
return doc_ != NULL; }
750 operator bool() const CTOON_NOEXCEPT {
return valid(); }
754 ctoon_mut_doc *
raw() const CTOON_NOEXCEPT {
return doc_; }
757 return mut_value(ctoon_mut_doc_ptr_getn(
doc_, ptr.data(), ptr.size()));
772 return mut_value(ctoon_mut_strncpy(
doc_, s.data(), s.size()));
775 return mut_value(ctoon_mut_strncpy(
doc_, s.data(), s.size()));
780 ctoon_write_options co = opts.to_c();
781 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
783 char *
raw = ctoon_mut_write_opts(
doc_, &co, NULL, &len, &err);
789 ctoon_write_options co = opts.to_c();
790 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
791 if (!ctoon_mut_write_file(path,
doc_, &co, NULL, &err))
throw write_error(err);
795#if defined(CTOON_ENABLE_JSON) && CTOON_ENABLE_JSON
798 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
800 char *
raw = ctoon_mut_doc_to_json(
doc_, indent,
to_c(flags), NULL, &len, &err);
806 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
808 char *
raw = ctoon_mut_doc_to_json(
doc_, indent,
to_c(flags), NULL, &len, &err);
810 FILE *fp = std::fopen(path,
"wb");
812 std::fwrite(
raw, 1, len, fp);
818 ctoon_mut_doc *
release() CTOON_NOEXCEPT { ctoon_mut_doc *d =
doc_;
doc_ = NULL;
return d; }
825 ctoon_mut_doc *d = ctoon_doc_mut_copy(
doc_, NULL);
826 if (!d)
throw std::bad_alloc();
847#if defined(CTOON_ENABLE_JSON) && CTOON_ENABLE_JSON
861 return d.
to_json(indent, flags);
864 return d.
to_json(indent, flags);
878 ctoon_read_err rerr; std::memset(&rerr, 0,
sizeof(rerr));
879 ctoon_write_err werr; std::memset(&werr, 0,
sizeof(werr));
880 ctoon_write_options co = opts.to_c();
882 char *raw = ctoon_json_to_toon_opts(json, len,
to_c(flags), &co, NULL, &n, &rerr, &werr);
892 return json_to_toon(json, std::strlen(json), opts, flags);
897 return json_to_toon(json.data(), json.size(), opts, flags);
902 return json_to_toon(json.data(), json.size(), opts, flags);
909 ctoon_read_err rerr; std::memset(&rerr, 0,
sizeof(rerr));
910 ctoon_write_err werr; std::memset(&werr, 0,
sizeof(werr));
911 ctoon_write_options co = opts.to_c();
912 if (!ctoon_json_to_toon_file_opts(json_path, toon_path,
to_c(flags), &co, NULL, &rerr, &werr)) {
922 ctoon_read_err rerr; std::memset(&rerr, 0,
sizeof(rerr));
923 ctoon_write_err werr; std::memset(&werr, 0,
sizeof(werr));
925 char *raw = ctoon_toon_to_json_opts(toon, len,
to_c(rflags), indent,
to_c(wflags),
926 NULL, &n, &rerr, &werr);
936 return toon_to_json(toon, std::strlen(toon), indent, wflags, rflags);
941 return toon_to_json(toon.data(), toon.size(), indent, wflags, rflags);
946 return toon_to_json(toon.data(), toon.size(), indent, wflags, rflags);
953 ctoon_read_err rerr; std::memset(&rerr, 0,
sizeof(rerr));
954 ctoon_write_err werr; std::memset(&werr, 0,
sizeof(werr));
955 if (!ctoon_toon_to_json_file_opts(toon_path, json_path,
to_c(rflags), indent,
956 to_c(wflags), NULL, &rerr, &werr)) {
static document parse_indent(const char *toon, std::size_t len, int indent_size, read_flag flags=read_flag::NOFLAG)
static document from_json(const std::string &json, read_flag flags=read_flag::NOFLAG)
document & operator=(document &&o) CTOON_NOEXCEPT
static document parse_indent(const string_view &toon, int indent_size, read_flag flags=read_flag::NOFLAG)
write_result to_json(int indent=2, write_flag flags=write_flag::NOFLAG) const
document(document &&o) CTOON_NOEXCEPT
ctoon_doc * raw() const CTOON_NOEXCEPT
void write_file(const char *path, const write_options &opts=write_options()) const
document(ctoon_doc *doc) CTOON_NOEXCEPT
static document from_json(const char *json, std::size_t len, read_flag flags=read_flag::NOFLAG)
static document from_json(const string_view &json, read_flag flags=read_flag::NOFLAG)
std::size_t val_count() const CTOON_NOEXCEPT
static document from_json(const char *json, read_flag flags=read_flag::NOFLAG)
unsigned char valid() const CTOON_NOEXCEPT
static document parse(const string_view &toon, read_flag flags=read_flag::NOFLAG)
static document parse_indent(const std::string &toon, int indent_size, read_flag flags=read_flag::NOFLAG)
std::size_t read_size() const CTOON_NOEXCEPT
value operator*() const CTOON_NOEXCEPT
value get_pointer(const string_view &ptr) const CTOON_NOEXCEPT
static document parse(const std::string &toon, read_flag flags=read_flag::NOFLAG)
ctoon_doc * release() CTOON_NOEXCEPT
static document parse(const char *toon, std::size_t len, read_flag flags=read_flag::NOFLAG)
static document from_json_file(const char *path, read_flag flags=read_flag::NOFLAG)
document() CTOON_NOEXCEPT
write_result to_string(const write_options &opts=write_options()) const
mut_document mut_copy() const
static document parse_file(const char *path, read_flag flags=read_flag::NOFLAG)
static document parse(const char *toon, read_flag flags=read_flag::NOFLAG)
value root() const CTOON_NOEXCEPT
void to_json_file(const char *path, int indent=2, write_flag flags=write_flag::NOFLAG) const
virtual const char * what() const CTOON_NOEXCEPT
error(const std::string &msg) CTOON_NOEXCEPT
virtual ~error() CTOON_NOEXCEPT
mut_value make_uint(std::uint64_t v) CTOON_NOEXCEPT
mut_value make_false() CTOON_NOEXCEPT
mut_value make_arr() CTOON_NOEXCEPT
mut_value make_sint(std::int64_t v) CTOON_NOEXCEPT
void set_root(mut_value v) CTOON_NOEXCEPT
void write_file(const char *path, const write_options &opts=write_options()) const
mut_value make_bool(unsigned char v) CTOON_NOEXCEPT
mut_value make_str(const std::string &s) CTOON_NOEXCEPT
mut_document & operator=(mut_document &&o) CTOON_NOEXCEPT
mut_value get_pointer(const string_view &ptr) const CTOON_NOEXCEPT
write_result to_json(int indent=2, write_flag flags=write_flag::NOFLAG) const
mut_value make_obj() CTOON_NOEXCEPT
write_result to_string(const write_options &opts=write_options()) const
mut_document() CTOON_NOEXCEPT
mut_document(ctoon_mut_doc *doc) CTOON_NOEXCEPT
mut_value make_str(const string_view &s) CTOON_NOEXCEPT
unsigned char valid() const CTOON_NOEXCEPT
mut_value root() const CTOON_NOEXCEPT
ctoon_mut_doc * raw() const CTOON_NOEXCEPT
mut_value make_real(double v) CTOON_NOEXCEPT
mut_value make_null() CTOON_NOEXCEPT
void to_json_file(const char *path, int indent=2, write_flag flags=write_flag::NOFLAG) const
static mut_document create()
mut_document(mut_document &&o) CTOON_NOEXCEPT
mut_value make_str(const char *s) CTOON_NOEXCEPT
mut_value make_true() CTOON_NOEXCEPT
mut_value operator*() const CTOON_NOEXCEPT
ctoon_mut_doc * release() CTOON_NOEXCEPT
unsigned char equals(const mut_value &rhs) const CTOON_NOEXCEPT
mut_value obj_get(const string_view &key) const CTOON_NOEXCEPT
mut_value arr_get(std::size_t i) const CTOON_NOEXCEPT
unsigned char obj_clear() const CTOON_NOEXCEPT
mut_value() CTOON_NOEXCEPT
unsigned char arr_append(mut_value item) const CTOON_NOEXCEPT
unsigned char is_obj() const CTOON_NOEXCEPT
std::int64_t get_sint() const CTOON_NOEXCEPT
mut_value arr_first() const CTOON_NOEXCEPT
unsigned char arr_prepend(mut_value item) const CTOON_NOEXCEPT
unsigned char is_sint() const CTOON_NOEXCEPT
unsigned char is_bool() const CTOON_NOEXCEPT
std::size_t arr_size() const CTOON_NOEXCEPT
unsigned char get_bool() const CTOON_NOEXCEPT
unsigned char is_num() const CTOON_NOEXCEPT
mut_value(ctoon_mut_val *v) CTOON_NOEXCEPT
mut_value operator[](const string_view &key) const CTOON_NOEXCEPT
unsigned char is_real() const CTOON_NOEXCEPT
unsigned char is_null() const CTOON_NOEXCEPT
double get_num() const CTOON_NOEXCEPT
mut_value obj_get(const char *key) const CTOON_NOEXCEPT
unsigned char arr_clear() const CTOON_NOEXCEPT
mut_value operator[](const char *key) const CTOON_NOEXCEPT
std::size_t obj_size() const CTOON_NOEXCEPT
unsigned char valid() const CTOON_NOEXCEPT
unsigned char is_str() const CTOON_NOEXCEPT
unsigned char equals(const string_view &s) const CTOON_NOEXCEPT
mut_value operator[](std::size_t i) const CTOON_NOEXCEPT
unsigned char obj_put(mut_value key, mut_value val) const CTOON_NOEXCEPT
unsigned char is_int() const CTOON_NOEXCEPT
mut_value arr_last() const CTOON_NOEXCEPT
mut_value get_pointer(const string_view &ptr) const CTOON_NOEXCEPT
std::size_t get_len() const CTOON_NOEXCEPT
double get_real() const CTOON_NOEXCEPT
unsigned char is_arr() const CTOON_NOEXCEPT
unsigned char equals(const char *s) const CTOON_NOEXCEPT
unsigned char is_uint() const CTOON_NOEXCEPT
std::uint64_t get_uint() const CTOON_NOEXCEPT
unsigned char obj_add(mut_value key, mut_value val) const CTOON_NOEXCEPT
unsigned char is_false() const CTOON_NOEXCEPT
unsigned char is_true() const CTOON_NOEXCEPT
ctoon_mut_val * raw() const CTOON_NOEXCEPT
mut_value obj_remove(const string_view &key) const CTOON_NOEXCEPT
mut_value arr_remove(std::size_t i) const CTOON_NOEXCEPT
string_view get_str() const CTOON_NOEXCEPT
parse_error(const ctoon_read_err &e)
virtual ~parse_error() CTOON_NOEXCEPT
static string_view string() CTOON_NOEXCEPT
static unsigned int patch() CTOON_NOEXCEPT
static unsigned int major() CTOON_NOEXCEPT
static unsigned int minor() CTOON_NOEXCEPT
static string_view string() CTOON_NOEXCEPT
static unsigned int hex() CTOON_NOEXCEPT
static string_view string() CTOON_NOEXCEPT
value get_pointer(const string_view &ptr) const CTOON_NOEXCEPT
unsigned char equals(const string_view &s) const CTOON_NOEXCEPT
unsigned char is_int() const CTOON_NOEXCEPT
double get_num() const CTOON_NOEXCEPT
std::size_t obj_size() const CTOON_NOEXCEPT
std::int64_t get_sint() const CTOON_NOEXCEPT
unsigned char is_real() const CTOON_NOEXCEPT
unsigned char is_num() const CTOON_NOEXCEPT
unsigned char equals(const char *s) const CTOON_NOEXCEPT
value operator[](std::size_t i) const CTOON_NOEXCEPT
unsigned char equals(const value &rhs) const CTOON_NOEXCEPT
unsigned char is_sint() const CTOON_NOEXCEPT
unsigned char get_bool() const CTOON_NOEXCEPT
std::size_t arr_size() const CTOON_NOEXCEPT
value arr_first() const CTOON_NOEXCEPT
value operator[](const string_view &key) const CTOON_NOEXCEPT
string_view get_str() const CTOON_NOEXCEPT
value(ctoon_val *v) CTOON_NOEXCEPT
std::size_t get_len() const CTOON_NOEXCEPT
unsigned char is_true() const CTOON_NOEXCEPT
unsigned char is_str() const CTOON_NOEXCEPT
unsigned char is_bool() const CTOON_NOEXCEPT
write_result to_string(const write_options &opts=write_options()) const
value obj_get(const char *key) const CTOON_NOEXCEPT
unsigned char is_arr() const CTOON_NOEXCEPT
value arr_last() const CTOON_NOEXCEPT
value arr_get(std::size_t i) const CTOON_NOEXCEPT
std::uint64_t get_uint() const CTOON_NOEXCEPT
value operator[](const char *key) const CTOON_NOEXCEPT
unsigned char is_uint() const CTOON_NOEXCEPT
ctoon_val * raw() const CTOON_NOEXCEPT
value obj_get(const string_view &key) const CTOON_NOEXCEPT
double get_real() const CTOON_NOEXCEPT
unsigned char is_false() const CTOON_NOEXCEPT
unsigned char valid() const CTOON_NOEXCEPT
unsigned char is_obj() const CTOON_NOEXCEPT
unsigned char is_null() const CTOON_NOEXCEPT
static string_view string() CTOON_NOEXCEPT
static unsigned int patch() CTOON_NOEXCEPT
static unsigned int minor() CTOON_NOEXCEPT
static unsigned int hex() CTOON_NOEXCEPT
static unsigned int major() CTOON_NOEXCEPT
virtual ~write_error() CTOON_NOEXCEPT
write_error(const ctoon_write_err &e)
write_options & with_indent(int i) CTOON_NOEXCEPT
int indent() const CTOON_NOEXCEPT
ctoon_write_options to_c() const CTOON_NOEXCEPT
write_flag flag() const CTOON_NOEXCEPT
write_options & with_delimiter(delimiter d) CTOON_NOEXCEPT
write_options & with_flag(write_flag f) CTOON_NOEXCEPT
delimiter get_delimiter() const CTOON_NOEXCEPT
write_options() CTOON_NOEXCEPT
write_result(write_result &&o) CTOON_NOEXCEPT
write_result(char *p, std::size_t n) CTOON_NOEXCEPT
string_view view() const CTOON_NOEXCEPT
const char * c_str() const CTOON_NOEXCEPT
std::size_t size() const CTOON_NOEXCEPT
write_result & operator=(write_result &&o) CTOON_NOEXCEPT
write_result() CTOON_NOEXCEPT
unsigned char empty() const CTOON_NOEXCEPT
document from_json_file(const char *path, read_flag flags=read_flag::NOFLAG)
write_result to_json(const document &d, int indent=2, write_flag flags=write_flag::NOFLAG)
ctoon_write_flag to_c(write_flag f) CTOON_NOEXCEPT
Convert to the C type for passing to C API.
document from_json(const char *json, std::size_t len, read_flag flags=read_flag::NOFLAG)
write_result toon_to_json(const char *toon, std::size_t len, int indent=0, write_flag wflags=write_flag::NOFLAG, read_flag rflags=read_flag::NOFLAG)
TOON text -> JSON text (compact by default; pass indent > 0 to pretty-print).
write_result json_to_toon(const char *json, std::size_t len, const write_options &opts=write_options(), read_flag flags=read_flag::NOFLAG)
JSON text -> TOON text.
write_flag operator|(write_flag l, write_flag r) CTOON_NOEXCEPT
@ ALLOW_SINGLE_QUOTED_STR
mut_document make_document()
write_result to_string(const document &d, const write_options &o=write_options())
void json_to_toon_file(const char *json_path, const char *toon_path, const write_options &opts=write_options(), read_flag flags=read_flag::NOFLAG)
JSON file -> TOON file.
void toon_to_json_file(const char *toon_path, const char *json_path, int indent=0, write_flag wflags=write_flag::NOFLAG, read_flag rflags=read_flag::NOFLAG)
TOON file -> JSON file.
write_flag & operator|=(write_flag &l, write_flag r) CTOON_NOEXCEPT
document parse_file(const char *path, read_flag flags=read_flag::NOFLAG)
document parse(const char *toon, read_flag flags=read_flag::NOFLAG)