549 ) { |
549 ) { |
550 return cxJsonFilln(json, str, strlen(str)); |
550 return cxJsonFilln(json, str, strlen(str)); |
551 } |
551 } |
552 #endif |
552 #endif |
553 |
553 |
|
554 /** |
|
555 * Creates a new (empty) JSON object. |
|
556 * |
|
557 * @param allocator the allocator to use |
|
558 * @return the new JSON object or \c NULL if allocation fails |
|
559 */ |
554 cx_attr_nodiscard |
560 cx_attr_nodiscard |
555 CxJsonValue* cxJsonCreateObj(const CxAllocator* allocator); |
561 CxJsonValue* cxJsonCreateObj(const CxAllocator* allocator); |
556 |
562 |
|
563 /** |
|
564 * Creates a new (empty) JSON array. |
|
565 * |
|
566 * @param allocator the allocator to use |
|
567 * @return the new JSON array or \c NULL if allocation fails |
|
568 */ |
557 cx_attr_nodiscard |
569 cx_attr_nodiscard |
558 CxJsonValue* cxJsonCreateArr(const CxAllocator* allocator); |
570 CxJsonValue* cxJsonCreateArr(const CxAllocator* allocator); |
559 |
571 |
|
572 /** |
|
573 * Creates a new JSON number value. |
|
574 * |
|
575 * @param allocator the allocator to use |
|
576 * @param num the numeric value |
|
577 * @return the new JSON value or \c NULL if allocation fails |
|
578 * @see cxJsonObjPutNumber() |
|
579 * @see cxJsonArrAddNumbers() |
|
580 */ |
560 cx_attr_nodiscard |
581 cx_attr_nodiscard |
561 CxJsonValue* cxJsonCreateNumber(const CxAllocator* allocator, double num); |
582 CxJsonValue* cxJsonCreateNumber(const CxAllocator* allocator, double num); |
562 |
583 |
|
584 /** |
|
585 * Creates a new JSON number value based on an integer. |
|
586 * |
|
587 * @param allocator the allocator to use |
|
588 * @param num the numeric value |
|
589 * @return the new JSON value or \c NULL if allocation fails |
|
590 * @see cxJsonObjPutInteger() |
|
591 * @see cxJsonArrAddIntegers() |
|
592 */ |
563 cx_attr_nodiscard |
593 cx_attr_nodiscard |
564 CxJsonValue* cxJsonCreateInteger(const CxAllocator* allocator, int64_t num); |
594 CxJsonValue* cxJsonCreateInteger(const CxAllocator* allocator, int64_t num); |
565 |
595 |
|
596 /** |
|
597 * Creates a new JSON string. |
|
598 * |
|
599 * @param allocator the allocator to use |
|
600 * @param str the string data |
|
601 * @return the new JSON value or \c NULL if allocation fails |
|
602 * @see cxJsonCreateCxString() |
|
603 * @see cxJsonObjPutString() |
|
604 * @see cxJsonArrAddStrings() |
|
605 */ |
566 cx_attr_nodiscard |
606 cx_attr_nodiscard |
567 cx_attr_nonnull_arg(2) |
607 cx_attr_nonnull_arg(2) |
568 cx_attr_cstr_arg(2) |
608 cx_attr_cstr_arg(2) |
569 CxJsonValue* cxJsonCreateString(const CxAllocator* allocator, const char *str); |
609 CxJsonValue* cxJsonCreateString(const CxAllocator* allocator, const char *str); |
570 |
610 |
|
611 /** |
|
612 * Creates a new JSON string. |
|
613 * |
|
614 * @param allocator the allocator to use |
|
615 * @param str the string data |
|
616 * @return the new JSON value or \c NULL if allocation fails |
|
617 * @see cxJsonCreateString() |
|
618 * @see cxJsonObjPutCxString() |
|
619 * @see cxJsonArrAddCxStrings() |
|
620 */ |
571 cx_attr_nodiscard |
621 cx_attr_nodiscard |
572 CxJsonValue* cxJsonCreateCxString(const CxAllocator* allocator, cxstring str); |
622 CxJsonValue* cxJsonCreateCxString(const CxAllocator* allocator, cxstring str); |
573 |
623 |
|
624 /** |
|
625 * Creates a new JSON literal. |
|
626 * |
|
627 * @param allocator the allocator to use |
|
628 * @param lit the type of literal |
|
629 * @return the new JSON value or \c NULL if allocation fails |
|
630 * @see cxJsonObjPutLiteral() |
|
631 * @see cxJsonArrAddLiterals() |
|
632 */ |
574 cx_attr_nodiscard |
633 cx_attr_nodiscard |
575 CxJsonValue* cxJsonCreateLiteral(const CxAllocator* allocator, CxJsonLiteral lit); |
634 CxJsonValue* cxJsonCreateLiteral(const CxAllocator* allocator, CxJsonLiteral lit); |
576 |
635 |
|
636 /** |
|
637 * Adds number values to a JSON array. |
|
638 * |
|
639 * @param arr the JSON array |
|
640 * @param num the array of values |
|
641 * @param count the number of elements |
|
642 * @return zero on success, non-zero on allocation failure |
|
643 */ |
577 cx_attr_nonnull |
644 cx_attr_nonnull |
578 cx_attr_access_r(2, 3) |
645 cx_attr_access_r(2, 3) |
579 int cxJsonArrAddNumbers(CxJsonValue* arr, const double* num, size_t count); |
646 int cxJsonArrAddNumbers(CxJsonValue* arr, const double* num, size_t count); |
580 |
647 |
|
648 /** |
|
649 * Adds number values, of which all are integers, to a JSON array. |
|
650 * |
|
651 * @param arr the JSON array |
|
652 * @param num the array of values |
|
653 * @param count the number of elements |
|
654 * @return zero on success, non-zero on allocation failure |
|
655 */ |
581 cx_attr_nonnull |
656 cx_attr_nonnull |
582 cx_attr_access_r(2, 3) |
657 cx_attr_access_r(2, 3) |
583 int cxJsonArrAddIntegers(CxJsonValue* arr, const int64_t* num, size_t count); |
658 int cxJsonArrAddIntegers(CxJsonValue* arr, const int64_t* num, size_t count); |
584 |
659 |
|
660 /** |
|
661 * Adds strings to a JSON array. |
|
662 * |
|
663 * The strings will be copied with the allocator of the array. |
|
664 * |
|
665 * @param arr the JSON array |
|
666 * @param str the array of strings |
|
667 * @param count the number of elements |
|
668 * @return zero on success, non-zero on allocation failure |
|
669 * @see cxJsonArrAddCxStrings() |
|
670 */ |
585 cx_attr_nonnull |
671 cx_attr_nonnull |
586 cx_attr_access_r(2, 3) |
672 cx_attr_access_r(2, 3) |
587 int cxJsonArrAddStrings(CxJsonValue* arr, const char* const* str, size_t count); |
673 int cxJsonArrAddStrings(CxJsonValue* arr, const char* const* str, size_t count); |
588 |
674 |
|
675 /** |
|
676 * Adds strings to a JSON array. |
|
677 * |
|
678 * The strings will be copied with the allocator of the array. |
|
679 * |
|
680 * @param arr the JSON array |
|
681 * @param str the array of strings |
|
682 * @param count the number of elements |
|
683 * @return zero on success, non-zero on allocation failure |
|
684 * @see cxJsonArrAddStrings() |
|
685 */ |
589 cx_attr_nonnull |
686 cx_attr_nonnull |
590 cx_attr_access_r(2, 3) |
687 cx_attr_access_r(2, 3) |
591 int cxJsonArrAddCxStrings(CxJsonValue* arr, const cxstring* str, size_t count); |
688 int cxJsonArrAddCxStrings(CxJsonValue* arr, const cxstring* str, size_t count); |
592 |
689 |
|
690 /** |
|
691 * Adds literals to a JSON array. |
|
692 * |
|
693 * @param arr the JSON array |
|
694 * @param lit the array of literal types |
|
695 * @param count the number of elements |
|
696 * @return zero on success, non-zero on allocation failure |
|
697 */ |
593 cx_attr_nonnull |
698 cx_attr_nonnull |
594 cx_attr_access_r(2, 3) |
699 cx_attr_access_r(2, 3) |
595 int cxJsonArrAddLiterals(CxJsonValue* arr, const CxJsonLiteral* lit, size_t count); |
700 int cxJsonArrAddLiterals(CxJsonValue* arr, const CxJsonLiteral* lit, size_t count); |
596 |
701 |
|
702 /** |
|
703 * Add arbitrary values to a JSON array. |
|
704 * |
|
705 * \note In contrast to all other add functions, this function adds the values |
|
706 * directly to the array instead of copying them. |
|
707 * |
|
708 * @param arr the JSON array |
|
709 * @param val the values |
|
710 * @param count the number of elements |
|
711 * @return zero on success, non-zero on allocation failure |
|
712 */ |
597 cx_attr_nonnull |
713 cx_attr_nonnull |
598 cx_attr_access_r(2, 3) |
714 cx_attr_access_r(2, 3) |
599 int cxJsonArrAddValues(CxJsonValue* arr, CxJsonValue* const* val, size_t count); |
715 int cxJsonArrAddValues(CxJsonValue* arr, CxJsonValue* const* val, size_t count); |
600 |
716 |
|
717 /** |
|
718 * Adds or replaces a value within a JSON object. |
|
719 * |
|
720 * The value will be directly added and not copied. |
|
721 * |
|
722 * \note If a value with the specified \p name already exists, |
|
723 * it will be (recursively) freed with its own allocator. |
|
724 * |
|
725 * @param obj the JSON object |
|
726 * @param name the name of the value |
|
727 * @param child the value |
|
728 * @return zero on success, non-zero on allocation failure |
|
729 */ |
601 cx_attr_nonnull |
730 cx_attr_nonnull |
602 int cxJsonObjPut(CxJsonValue* obj, cxstring name, CxJsonValue* child); |
731 int cxJsonObjPut(CxJsonValue* obj, cxstring name, CxJsonValue* child); |
603 |
732 |
|
733 /** |
|
734 * Creates a new JSON object and adds it to an existing object. |
|
735 * |
|
736 * @param obj the target JSON object |
|
737 * @param name the name of the new value |
|
738 * @return the new value or \c NULL if allocation fails |
|
739 * @see cxJsonObjPut() |
|
740 * @see cxJsonCreateObj() |
|
741 */ |
604 cx_attr_nonnull |
742 cx_attr_nonnull |
605 CxJsonValue* cxJsonObjPutObj(CxJsonValue* obj, cxstring name); |
743 CxJsonValue* cxJsonObjPutObj(CxJsonValue* obj, cxstring name); |
606 |
744 |
|
745 /** |
|
746 * Creates a new JSON array and adds it to an object. |
|
747 * |
|
748 * @param obj the target JSON object |
|
749 * @param name the name of the new value |
|
750 * @return the new value or \c NULL if allocation fails |
|
751 * @see cxJsonObjPut() |
|
752 * @see cxJsonCreateArr() |
|
753 */ |
607 cx_attr_nonnull |
754 cx_attr_nonnull |
608 CxJsonValue* cxJsonObjPutArr(CxJsonValue* obj, cxstring name); |
755 CxJsonValue* cxJsonObjPutArr(CxJsonValue* obj, cxstring name); |
609 |
756 |
|
757 /** |
|
758 * Creates a new JSON number and adds it to an object. |
|
759 * |
|
760 * @param obj the target JSON object |
|
761 * @param name the name of the new value |
|
762 * @param num the numeric value |
|
763 * @return the new value or \c NULL if allocation fails |
|
764 * @see cxJsonObjPut() |
|
765 * @see cxJsonCreateNumber() |
|
766 */ |
610 cx_attr_nonnull |
767 cx_attr_nonnull |
611 CxJsonValue* cxJsonObjPutNumber(CxJsonValue* obj, cxstring name, double num); |
768 CxJsonValue* cxJsonObjPutNumber(CxJsonValue* obj, cxstring name, double num); |
612 |
769 |
|
770 /** |
|
771 * Creates a new JSON number, based on an integer, and adds it to an object. |
|
772 * |
|
773 * @param obj the target JSON object |
|
774 * @param name the name of the new value |
|
775 * @param num the numeric value |
|
776 * @return the new value or \c NULL if allocation fails |
|
777 * @see cxJsonObjPut() |
|
778 * @see cxJsonCreateInteger() |
|
779 */ |
613 cx_attr_nonnull |
780 cx_attr_nonnull |
614 CxJsonValue* cxJsonObjPutInteger(CxJsonValue* obj, cxstring name, int64_t num); |
781 CxJsonValue* cxJsonObjPutInteger(CxJsonValue* obj, cxstring name, int64_t num); |
615 |
782 |
|
783 /** |
|
784 * Creates a new JSON string and adds it to an object. |
|
785 * |
|
786 * The string data is copied. |
|
787 * |
|
788 * @param obj the target JSON object |
|
789 * @param name the name of the new value |
|
790 * @param str the string data |
|
791 * @return the new value or \c NULL if allocation fails |
|
792 * @see cxJsonObjPut() |
|
793 * @see cxJsonCreateString() |
|
794 */ |
616 cx_attr_nonnull |
795 cx_attr_nonnull |
617 cx_attr_cstr_arg(3) |
796 cx_attr_cstr_arg(3) |
618 CxJsonValue* cxJsonObjPutString(CxJsonValue* obj, cxstring name, const char* str); |
797 CxJsonValue* cxJsonObjPutString(CxJsonValue* obj, cxstring name, const char* str); |
619 |
798 |
|
799 /** |
|
800 * Creates a new JSON string and adds it to an object. |
|
801 * |
|
802 * The string data is copied. |
|
803 * |
|
804 * @param obj the target JSON object |
|
805 * @param name the name of the new value |
|
806 * @param str the string data |
|
807 * @return the new value or \c NULL if allocation fails |
|
808 * @see cxJsonObjPut() |
|
809 * @see cxJsonCreateCxString() |
|
810 */ |
620 cx_attr_nonnull |
811 cx_attr_nonnull |
621 CxJsonValue* cxJsonObjPutCxString(CxJsonValue* obj, cxstring name, cxstring str); |
812 CxJsonValue* cxJsonObjPutCxString(CxJsonValue* obj, cxstring name, cxstring str); |
622 |
813 |
|
814 /** |
|
815 * Creates a new JSON literal and adds it to an object. |
|
816 * |
|
817 * @param obj the target JSON object |
|
818 * @param name the name of the new value |
|
819 * @param lit the type of literal |
|
820 * @return the new value or \c NULL if allocation fails |
|
821 * @see cxJsonObjPut() |
|
822 * @see cxJsonCreateLiteral() |
|
823 */ |
623 cx_attr_nonnull |
824 cx_attr_nonnull |
624 CxJsonValue* cxJsonObjPutLiteral(CxJsonValue* obj, cxstring name, CxJsonLiteral lit); |
825 CxJsonValue* cxJsonObjPutLiteral(CxJsonValue* obj, cxstring name, CxJsonLiteral lit); |
625 |
826 |
626 /** |
827 /** |
627 * Recursively deallocates the memory of a JSON value. |
828 * Recursively deallocates the memory of a JSON value. |