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; }
103class error :
public std::exception {
105 explicit error(
const std::string &msg) CTOON_NOEXCEPT :
msg_(msg) {}
106 virtual const char *
what() const CTOON_NOEXCEPT {
return msg_.c_str(); }
120 static std::string build_msg(
const ctoon_read_err &e) {
121 std::string m(e.msg ? e.msg :
"parse error");
122 char buf[32]; std::sprintf(buf,
" (pos %zu)", e.pos);
145 :
ptr_(o.ptr_),
len_(o.len_) { o.ptr_ = NULL; o.len_ = 0; }
147 if (
this != &o) { std::free(
ptr_);
ptr_ = o.ptr_;
len_ = o.len_; o.ptr_ = NULL; o.len_ = 0; }
151 std::size_t
size() const CTOON_NOEXCEPT {
return len_; }
164 COMMA = CTOON_DELIMITER_COMMA,
165 TAB = CTOON_DELIMITER_TAB,
166 PIPE = CTOON_DELIMITER_PIPE,
177 NOFLAG =
static_cast<uint32_t
>(CTOON_WRITE_NOFLAG),
178 ESCAPE_UNICODE =
static_cast<uint32_t
>(CTOON_WRITE_ESCAPE_UNICODE),
179 ESCAPE_SLASHES =
static_cast<uint32_t
>(CTOON_WRITE_ESCAPE_SLASHES),
183 LENGTH_MARKER =
static_cast<uint32_t
>(CTOON_WRITE_LENGTH_MARKER),
184 NEWLINE_AT_END =
static_cast<uint32_t
>(CTOON_WRITE_NEWLINE_AT_END),
188 return static_cast<write_flag>(
static_cast<uint32_t
>(l) |
static_cast<uint32_t
>(r));
195 return static_cast<ctoon_write_flag
>(
static_cast<uint32_t
>(f));
203 NOFLAG =
static_cast<uint32_t
>(CTOON_READ_NOFLAG),
204 INSITU =
static_cast<uint32_t
>(CTOON_READ_INSITU),
205 STOP_WHEN_DONE =
static_cast<uint32_t
>(CTOON_READ_STOP_WHEN_DONE),
207 ALLOW_COMMENTS =
static_cast<uint32_t
>(CTOON_READ_ALLOW_COMMENTS),
209 NUMBER_AS_RAW =
static_cast<uint32_t
>(CTOON_READ_NUMBER_AS_RAW),
211 BIGNUM_AS_RAW =
static_cast<uint32_t
>(CTOON_READ_BIGNUM_AS_RAW),
212 ALLOW_BOM =
static_cast<uint32_t
>(CTOON_READ_ALLOW_BOM),
221 return static_cast<read_flag>(
static_cast<uint32_t
>(l) |
static_cast<uint32_t
>(r));
228 return static_cast<ctoon_read_flag
>(
static_cast<uint32_t
>(f));
246 int indent() const CTOON_NOEXCEPT {
return indent_; }
248 ctoon_write_options
to_c() const CTOON_NOEXCEPT {
249 ctoon_write_options o;
251 o.delimiter =
static_cast<ctoon_delimiter
>(delimiter_);
277 explicit value(ctoon_val *v) CTOON_NOEXCEPT :
v_(v) {}
279 ctoon_val *
raw() const CTOON_NOEXCEPT {
return v_; }
280 bool valid() const CTOON_NOEXCEPT {
return v_ != NULL; }
281 operator bool() const CTOON_NOEXCEPT {
return valid(); }
284 bool is_null() const CTOON_NOEXCEPT {
return v_ && ctoon_is_null(
v_); }
285 bool is_true() const CTOON_NOEXCEPT {
return v_ && ctoon_is_true(
v_); }
286 bool is_false() const CTOON_NOEXCEPT {
return v_ && ctoon_is_false(
v_); }
287 bool is_bool() const CTOON_NOEXCEPT {
return v_ && ctoon_is_bool(
v_); }
288 bool is_uint() const CTOON_NOEXCEPT {
return v_ && ctoon_is_uint(
v_); }
289 bool is_sint() const CTOON_NOEXCEPT {
return v_ && ctoon_is_sint(
v_); }
290 bool is_int() const CTOON_NOEXCEPT {
return v_ && ctoon_is_int(
v_); }
291 bool is_real() const CTOON_NOEXCEPT {
return v_ && ctoon_is_real(
v_); }
292 bool is_num() const CTOON_NOEXCEPT {
return v_ && ctoon_is_num(
v_); }
293 bool is_str() const CTOON_NOEXCEPT {
return v_ && ctoon_is_str(
v_); }
294 bool is_arr() const CTOON_NOEXCEPT {
return v_ && ctoon_is_arr(
v_); }
295 bool is_obj() const CTOON_NOEXCEPT {
return v_ && ctoon_is_obj(
v_); }
298 bool get_bool() const CTOON_NOEXCEPT {
return v_ && ctoon_get_bool(
v_); }
299 std::uint64_t
get_uint() const CTOON_NOEXCEPT {
return v_ ? ctoon_get_uint(
v_) : 0; }
300 std::int64_t
get_sint() const CTOON_NOEXCEPT {
return v_ ? ctoon_get_sint(
v_) : 0; }
301 double get_real() const CTOON_NOEXCEPT {
return v_ ? ctoon_get_real(
v_) : 0.0; }
302 double get_num() const CTOON_NOEXCEPT {
return v_ ? ctoon_get_num(
v_) : 0.0; }
303 std::size_t
get_len() const CTOON_NOEXCEPT {
return v_ ? ctoon_get_len(
v_) : 0; }
305 if (!
v_)
return string_view();
306 const char *s = ctoon_get_str(
v_);
307 return s ? string_view(s, ctoon_get_len(
v_)) : string_view();
311 std::size_t
arr_size() const CTOON_NOEXCEPT {
return v_ ? ctoon_arr_size(
v_) : 0; }
318 std::size_t
obj_size() const CTOON_NOEXCEPT {
return v_ ? ctoon_obj_size(
v_) : 0; }
321 return value(
v_ ? ctoon_obj_getn(
v_, key.data(), key.size()) : NULL);
327 bool equals(
const value &rhs)
const CTOON_NOEXCEPT {
return v_ && rhs.v_ && ctoon_equals(
v_, rhs.v_); }
328 bool equals(
const char *s)
const CTOON_NOEXCEPT {
return v_ && ctoon_equals_str(
v_, s); }
329 bool equals(
const string_view &s)
const CTOON_NOEXCEPT {
return v_ && ctoon_equals_strn(
v_, s.data(), s.size()); }
333 return value(
v_ ? ctoon_ptr_getn(
v_, ptr.data(), ptr.size()) : NULL);
338 ctoon_write_options co = opts.to_c();
339 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
341 char *
raw = ctoon_val_write_opts(
v_, &co, NULL, &len, &err);
350 explicit arr_iterator(ctoon_val *arr,
bool end =
false) : cur_(NULL) {
351 if (!arr || end) { std::memset(&iter_, 0,
sizeof(iter_));
return; }
352 ctoon_arr_iter_init(arr, &iter_);
353 cur_ = ctoon_arr_iter_next(&iter_);
355 value operator*() const CTOON_NOEXCEPT {
return value(cur_); }
356 arr_iterator &operator++() CTOON_NOEXCEPT { cur_ = ctoon_arr_iter_next(&iter_);
return *
this; }
357 bool operator!=(
const arr_iterator &o)
const CTOON_NOEXCEPT {
return cur_ != o.cur_; }
359 ctoon_arr_iter iter_;
364 arr_iterator begin()
const {
return arr_iterator(arr); }
365 arr_iterator end()
const {
return arr_iterator(arr,
true); }
367 arr_range arr_items() const CTOON_NOEXCEPT { arr_range r; r.arr =
v_;
return r; }
370 ctoon_val *key_raw, *val_raw;
371 value key()
const {
return value(key_raw); }
372 value val()
const {
return value(val_raw); }
376 explicit obj_iterator(ctoon_val *obj,
bool end =
false) : key_(NULL) {
377 if (!obj || end) { std::memset(&iter_, 0,
sizeof(iter_));
return; }
378 ctoon_obj_iter_init(obj, &iter_);
379 key_ = ctoon_obj_iter_next(&iter_);
381 kv_pair operator*() const CTOON_NOEXCEPT {
382 kv_pair kv; kv.key_raw = key_; kv.val_raw = ctoon_obj_iter_get_val(key_);
return kv;
384 obj_iterator &operator++() CTOON_NOEXCEPT { key_ = ctoon_obj_iter_next(&iter_);
return *
this; }
385 bool operator!=(
const obj_iterator &o)
const CTOON_NOEXCEPT {
return key_ != o.key_; }
387 ctoon_obj_iter iter_;
392 obj_iterator begin()
const {
return obj_iterator(obj); }
393 obj_iterator end()
const {
return obj_iterator(obj,
true); }
395 obj_range obj_items() const CTOON_NOEXCEPT { obj_range r; r.obj =
v_;
return r; }
411 ctoon_mut_val *
raw() const CTOON_NOEXCEPT {
return v_; }
412 bool valid() const CTOON_NOEXCEPT {
return v_ != NULL; }
413 operator bool() const CTOON_NOEXCEPT {
return valid(); }
416 bool is_null() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_null(
v_); }
417 bool is_true() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_true(
v_); }
418 bool is_false() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_false(
v_); }
419 bool is_bool() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_bool(
v_); }
420 bool is_uint() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_uint(
v_); }
421 bool is_sint() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_sint(
v_); }
422 bool is_int() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_int(
v_); }
423 bool is_real() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_real(
v_); }
424 bool is_num() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_num(
v_); }
425 bool is_str() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_str(
v_); }
426 bool is_arr() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_arr(
v_); }
427 bool is_obj() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_is_obj(
v_); }
430 bool get_bool() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_get_bool(
v_); }
431 std::uint64_t
get_uint() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_get_uint(
v_) : 0; }
432 std::int64_t
get_sint() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_get_sint(
v_) : 0; }
433 double get_real() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_get_real(
v_) : 0.0; }
434 double get_num() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_get_num(
v_) : 0.0; }
435 std::size_t
get_len() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_get_len(
v_) : 0; }
437 if (!
v_)
return string_view();
438 const char *s = ctoon_mut_get_str(
v_);
439 return s ? string_view(s, ctoon_mut_get_len(
v_)) : string_view();
443 std::size_t
arr_size() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_arr_size(
v_) : 0; }
450 std::size_t
obj_size() const CTOON_NOEXCEPT {
return v_ ? ctoon_mut_obj_size(
v_) : 0; }
453 return mut_value(
v_ ? ctoon_mut_obj_getn(
v_, key.data(), key.size()) : NULL);
459 bool equals(
const mut_value &rhs)
const CTOON_NOEXCEPT {
return v_ && rhs.v_ && ctoon_mut_equals(
v_, rhs.v_); }
460 bool equals(
const char *s)
const CTOON_NOEXCEPT {
return v_ && ctoon_mut_equals_str(
v_, s); }
461 bool equals(
const string_view &s)
const CTOON_NOEXCEPT {
return v_ && ctoon_mut_equals_strn(
v_, s.data(), s.size()); }
465 return mut_value(
v_ ? ctoon_mut_ptr_getn(
v_, ptr.data(), ptr.size()) : NULL);
471 bool arr_clear() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_arr_clear(
v_); }
478 return v_ && key.v_ && val.v_ && ctoon_mut_obj_add(
v_, key.v_, val.v_);
481 return v_ && key.v_ && val.v_ && ctoon_mut_obj_put(
v_, key.v_, val.v_);
483 bool obj_clear() const CTOON_NOEXCEPT {
return v_ && ctoon_mut_obj_clear(
v_); }
485 return mut_value(
v_ ? ctoon_mut_obj_remove_keyn(
v_, key.data(), key.size()) : NULL);
492 explicit arr_iterator(ctoon_mut_val *arr,
bool end =
false) : cur_(NULL) {
493 if (!arr || end) { std::memset(&iter_, 0,
sizeof(iter_));
return; }
494 ctoon_mut_arr_iter_init(arr, &iter_);
495 cur_ = ctoon_mut_arr_iter_next(&iter_);
497 mut_value operator*() const CTOON_NOEXCEPT {
return mut_value(cur_); }
498 arr_iterator &operator++() CTOON_NOEXCEPT { cur_ = ctoon_mut_arr_iter_next(&iter_);
return *
this; }
499 bool operator!=(
const arr_iterator &o)
const CTOON_NOEXCEPT {
return cur_ != o.cur_; }
501 ctoon_mut_arr_iter iter_;
506 arr_iterator begin()
const {
return arr_iterator(arr); }
507 arr_iterator end()
const {
return arr_iterator(arr,
true); }
509 arr_range arr_items() const CTOON_NOEXCEPT { arr_range r; r.arr =
v_;
return r; }
512 ctoon_mut_val *key_raw, *val_raw;
513 mut_value key()
const {
return mut_value(key_raw); }
514 mut_value val()
const {
return mut_value(val_raw); }
518 explicit obj_iterator(ctoon_mut_val *obj,
bool end =
false) : key_(NULL) {
519 if (!obj || end) { std::memset(&iter_, 0,
sizeof(iter_));
return; }
520 ctoon_mut_obj_iter_init(obj, &iter_);
521 key_ = ctoon_mut_obj_iter_next(&iter_);
523 kv_pair operator*() const CTOON_NOEXCEPT {
524 kv_pair kv; kv.key_raw = key_; kv.val_raw = ctoon_mut_obj_iter_get_val(key_);
return kv;
526 obj_iterator &operator++() CTOON_NOEXCEPT { key_ = ctoon_mut_obj_iter_next(&iter_);
return *
this; }
527 bool operator!=(
const obj_iterator &o)
const CTOON_NOEXCEPT {
return key_ != o.key_; }
529 ctoon_mut_obj_iter iter_;
534 obj_iterator begin()
const {
return obj_iterator(obj); }
535 obj_iterator end()
const {
return obj_iterator(obj,
true); }
537 obj_range obj_items() const CTOON_NOEXCEPT { obj_range r; r.obj =
v_;
return r; }
556 if (
this != &o) { ctoon_doc_free(
doc_);
doc_ = o.doc_; o.doc_ = NULL; }
563 ctoon_read_err err; std::memset(&err, 0,
sizeof(err));
564 ctoon_doc *d = ctoon_read_opts(
const_cast<char *
>(toon), len,
to_c(flags), NULL, &err);
569 return parse(toon, std::strlen(toon), flags);
572 return parse(toon.data(), toon.size(), flags);
575 return parse(toon.data(), toon.size(), flags);
581 ctoon_read_err err; std::memset(&err, 0,
sizeof(err));
582 ctoon_doc *d = ctoon_read_opts_indent(
const_cast<char *
>(toon), len,
583 to_c(flags), indent_size, NULL, &err);
589 return parse_indent(toon.data(), toon.size(), indent_size, flags);
593 return parse_indent(toon.data(), toon.size(), indent_size, flags);
596 ctoon_read_err err; std::memset(&err, 0,
sizeof(err));
597 ctoon_doc *d = ctoon_read_file(path,
to_c(flags), NULL, &err);
602#if defined(CTOON_ENABLE_JSON) && CTOON_ENABLE_JSON
603 static document from_json(
const char *json, std::size_t len,
605 ctoon_read_err err; std::memset(&err, 0,
sizeof(err));
606 ctoon_doc *d = ctoon_read_json(
const_cast<char *
>(json), len,
to_c(flags), NULL, &err);
611 return from_json(json, std::strlen(json), flags);
614 return from_json(json.data(), json.size(), flags);
617 return from_json(json.data(), json.size(), flags);
620 ctoon_read_err err; std::memset(&err, 0,
sizeof(err));
621 ctoon_doc *d = ctoon_read_json_file(path,
to_c(flags), NULL, &err);
622 if (!d)
throw parse_error(err);
628 bool valid() const CTOON_NOEXCEPT {
return doc_ != NULL; }
629 operator bool() const CTOON_NOEXCEPT {
return valid(); }
632 ctoon_doc *
raw() const CTOON_NOEXCEPT {
return doc_; }
633 std::size_t
read_size() const CTOON_NOEXCEPT {
return ctoon_doc_get_read_size(
doc_); }
634 std::size_t
val_count() const CTOON_NOEXCEPT {
return ctoon_doc_get_val_count(
doc_); }
637 return value(ctoon_doc_ptr_getn(
doc_, ptr.data(), ptr.size()));
642 ctoon_write_options co = opts.to_c();
643 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
645 char *
raw = ctoon_write_opts(
doc_, &co, NULL, &len, &err);
651 ctoon_write_options co = opts.to_c();
652 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
653 if (!ctoon_write_file(path,
doc_, &co, NULL, &err))
throw write_error(err);
657#if defined(CTOON_ENABLE_JSON) && CTOON_ENABLE_JSON
660 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
662 char *
raw = ctoon_doc_to_json(
doc_, indent,
to_c(flags), NULL, &len, &err);
666 void to_json_file(
const char *path,
int indent = 2,
668 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
670 char *
raw = ctoon_doc_to_json(
doc_, indent,
to_c(flags), NULL, &len, &err);
671 if (!
raw)
throw write_error(err);
672 FILE *fp = std::fopen(path,
"wb");
673 if (!fp) { std::free(
raw);
throw write_error(err); }
674 std::fwrite(
raw, 1, len, fp);
700 if (
this != &o) { ctoon_mut_doc_free(
doc_);
doc_ = o.doc_; o.doc_ = NULL; }
705 ctoon_mut_doc *d = ctoon_mut_doc_new(NULL);
706 if (!d)
throw std::bad_alloc();
711 bool valid() const CTOON_NOEXCEPT {
return doc_ != NULL; }
712 operator bool() const CTOON_NOEXCEPT {
return valid(); }
716 ctoon_mut_doc *
raw() const CTOON_NOEXCEPT {
return doc_; }
719 return mut_value(ctoon_mut_doc_ptr_getn(
doc_, ptr.data(), ptr.size()));
734 return mut_value(ctoon_mut_strncpy(
doc_, s.data(), s.size()));
737 return mut_value(ctoon_mut_strncpy(
doc_, s.data(), s.size()));
742 ctoon_write_options co = opts.to_c();
743 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
745 char *
raw = ctoon_mut_write_opts(
doc_, &co, NULL, &len, &err);
751 ctoon_write_options co = opts.to_c();
752 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
753 if (!ctoon_mut_write_file(path,
doc_, &co, NULL, &err))
throw write_error(err);
757#if defined(CTOON_ENABLE_JSON) && CTOON_ENABLE_JSON
760 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
762 char *
raw = ctoon_mut_doc_to_json(
doc_, indent,
to_c(flags), NULL, &len, &err);
766 void to_json_file(
const char *path,
int indent = 2,
768 ctoon_write_err err; std::memset(&err, 0,
sizeof(err));
770 char *
raw = ctoon_mut_doc_to_json(
doc_, indent,
to_c(flags), NULL, &len, &err);
771 if (!
raw)
throw write_error(err);
772 FILE *fp = std::fopen(path,
"wb");
773 if (!fp) { std::free(
raw);
throw write_error(err); }
774 std::fwrite(
raw, 1, len, fp);
780 ctoon_mut_doc *
release() CTOON_NOEXCEPT { ctoon_mut_doc *d =
doc_;
doc_ = NULL;
return d; }
787 ctoon_mut_doc *d = ctoon_doc_mut_copy(
doc_, NULL);
788 if (!d)
throw std::bad_alloc();
809#if defined(CTOON_ENABLE_JSON) && CTOON_ENABLE_JSON
811 return document::from_json(json, len, flags);
814 return document::from_json(json, flags);
817 return document::from_json(json, flags);
820 return document::from_json_file(path, flags);
823 return d.to_json(indent, flags);
826 return d.to_json(indent, flags);
static document parse_indent(const char *toon, std::size_t len, int indent_size, 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)
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
std::size_t val_count() const CTOON_NOEXCEPT
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)
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
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
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
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
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
ctoon_write_flag to_c(write_flag f) CTOON_NOEXCEPT
Convert to the C type for passing to C API.
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())
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)