| 758 CX_EXPORT int cxJsonArrAddValues(CxJsonValue* arr, CxJsonValue* const* val, size_t count); |
757 CX_EXPORT int cxJsonArrAddValues(CxJsonValue* arr, CxJsonValue* const* val, size_t count); |
| 759 |
758 |
| 760 /** |
759 /** |
| 761 * Adds or replaces a value within a JSON object. |
760 * Adds or replaces a value within a JSON object. |
| 762 * |
761 * |
| 763 * The value will be directly added and not copied. |
762 * Internal function - use cxJsonObjPut(). |
| 764 * |
|
| 765 * @note If a value with the specified @p name already exists, |
|
| 766 * it will be (recursively) freed with its own allocator. |
|
| 767 * |
763 * |
| 768 * @param obj the JSON object |
764 * @param obj the JSON object |
| 769 * @param name the name of the value |
765 * @param name the name of the value |
| 770 * @param child the value |
766 * @param child the value |
| 771 * @retval zero success |
767 * @retval zero success |
| 772 * @retval non-zero allocation failure |
768 * @retval non-zero allocation failure |
| 773 */ |
769 */ |
| 774 cx_attr_nonnull |
770 cx_attr_nonnull |
| 775 CX_EXPORT int cxJsonObjPut(CxJsonValue* obj, cxstring name, CxJsonValue* child); |
771 CX_EXPORT int cx_json_obj_put(CxJsonValue* obj, cxstring name, CxJsonValue* child); |
| |
772 |
| |
773 /** |
| |
774 * Adds or replaces a value within a JSON object. |
| |
775 * |
| |
776 * The value will be directly added and not copied. |
| |
777 * |
| |
778 * @note If a value with the specified @p name already exists, |
| |
779 * it will be (recursively) freed with its own allocator. |
| |
780 * |
| |
781 * @param obj (@c CxJsonValue*) the JSON object |
| |
782 * @param name (any string) the name of the value |
| |
783 * @param child (@c CxJsonValue*) the value |
| |
784 * @retval zero success |
| |
785 * @retval non-zero allocation failure |
| |
786 */ |
| |
787 #define cxJsonObjPut(obj, name, child) cx_json_obj_put(obj, cx_strcast(name), child) |
| 776 |
788 |
| 777 /** |
789 /** |
| 778 * Creates a new JSON object and adds it to an existing object. |
790 * Creates a new JSON object and adds it to an existing object. |
| |
791 * |
| |
792 * Internal function - use cxJsonObjPutObj(). |
| 779 * |
793 * |
| 780 * @param obj the target JSON object |
794 * @param obj the target JSON object |
| 781 * @param name the name of the new value |
795 * @param name the name of the new value |
| 782 * @return the new value or @c NULL if allocation fails |
796 * @return the new value or @c NULL if allocation fails |
| 783 * @see cxJsonObjPut() |
797 * @see cxJsonObjPut() |
| 784 * @see cxJsonCreateObj() |
798 * @see cxJsonCreateObj() |
| 785 */ |
799 */ |
| 786 cx_attr_nonnull |
800 cx_attr_nonnull |
| 787 CX_EXPORT CxJsonValue* cxJsonObjPutObj(CxJsonValue* obj, cxstring name); |
801 CX_EXPORT CxJsonValue* cx_json_obj_put_obj(CxJsonValue* obj, cxstring name); |
| |
802 |
| |
803 /** |
| |
804 * Creates a new JSON object and adds it to an existing object. |
| |
805 * |
| |
806 * @param obj (@c CxJsonValue*) the target JSON object |
| |
807 * @param name (any string) the name of the new value |
| |
808 * @return (@c CxJsonValue*) the new value or @c NULL if allocation fails |
| |
809 * @see cxJsonObjPut() |
| |
810 * @see cxJsonCreateObj() |
| |
811 */ |
| |
812 #define cxJsonObjPutObj(obj, name) cx_json_obj_put_obj(obj, cx_strcast(name)) |
| 788 |
813 |
| 789 /** |
814 /** |
| 790 * Creates a new JSON array and adds it to an object. |
815 * Creates a new JSON array and adds it to an object. |
| |
816 * |
| |
817 * Internal function - use cxJsonObjPutArr(). |
| 791 * |
818 * |
| 792 * @param obj the target JSON object |
819 * @param obj the target JSON object |
| 793 * @param name the name of the new value |
820 * @param name the name of the new value |
| 794 * @return the new value or @c NULL if allocation fails |
821 * @return the new value or @c NULL if allocation fails |
| 795 * @see cxJsonObjPut() |
822 * @see cxJsonObjPut() |
| 796 * @see cxJsonCreateArr() |
823 * @see cxJsonCreateArr() |
| 797 */ |
824 */ |
| 798 cx_attr_nonnull |
825 cx_attr_nonnull |
| 799 CX_EXPORT CxJsonValue* cxJsonObjPutArr(CxJsonValue* obj, cxstring name); |
826 CX_EXPORT CxJsonValue* cx_json_obj_put_arr(CxJsonValue* obj, cxstring name); |
| |
827 |
| |
828 /** |
| |
829 * Creates a new JSON array and adds it to an object. |
| |
830 * |
| |
831 * @param obj (@c CxJsonValue*) the target JSON object |
| |
832 * @param name (any string) the name of the new value |
| |
833 * @return (@c CxJsonValue*) the new value or @c NULL if allocation fails |
| |
834 * @see cxJsonObjPut() |
| |
835 * @see cxJsonCreateArr() |
| |
836 */ |
| |
837 #define cxJsonObjPutArr(obj, name) cx_json_obj_put_arr(obj, cx_strcast(name)) |
| 800 |
838 |
| 801 /** |
839 /** |
| 802 * Creates a new JSON number and adds it to an object. |
840 * Creates a new JSON number and adds it to an object. |
| |
841 * |
| |
842 * Internal function - use cxJsonObjPutNumber(). |
| 803 * |
843 * |
| 804 * @param obj the target JSON object |
844 * @param obj the target JSON object |
| 805 * @param name the name of the new value |
845 * @param name the name of the new value |
| 806 * @param num the numeric value |
846 * @param num the numeric value |
| 807 * @return the new value or @c NULL if allocation fails |
847 * @return the new value or @c NULL if allocation fails |
| 808 * @see cxJsonObjPut() |
848 * @see cxJsonObjPut() |
| 809 * @see cxJsonCreateNumber() |
849 * @see cxJsonCreateNumber() |
| 810 */ |
850 */ |
| 811 cx_attr_nonnull |
851 cx_attr_nonnull |
| 812 CX_EXPORT CxJsonValue* cxJsonObjPutNumber(CxJsonValue* obj, cxstring name, double num); |
852 CX_EXPORT CxJsonValue* cx_json_obj_put_number(CxJsonValue* obj, cxstring name, double num); |
| |
853 |
| |
854 /** |
| |
855 * Creates a new JSON number and adds it to an object. |
| |
856 * |
| |
857 * @param obj (@c CxJsonValue*) the target JSON object |
| |
858 * @param name (any string) the name of the new value |
| |
859 * @param num (@c double) the numeric value |
| |
860 * @return (@c CxJsonValue*) the new value or @c NULL if allocation fails |
| |
861 * @see cxJsonObjPut() |
| |
862 * @see cxJsonCreateNumber() |
| |
863 */ |
| |
864 #define cxJsonObjPutNumber(obj, name, num) cx_json_obj_put_number(obj, cx_strcast(name), num) |
| 813 |
865 |
| 814 /** |
866 /** |
| 815 * Creates a new JSON number, based on an integer, and adds it to an object. |
867 * Creates a new JSON number, based on an integer, and adds it to an object. |
| |
868 * |
| |
869 * Internal function - use cxJsonObjPutInteger(). |
| 816 * |
870 * |
| 817 * @param obj the target JSON object |
871 * @param obj the target JSON object |
| 818 * @param name the name of the new value |
872 * @param name the name of the new value |
| 819 * @param num the numeric value |
873 * @param num the numeric value |
| 820 * @return the new value or @c NULL if allocation fails |
874 * @return the new value or @c NULL if allocation fails |
| 821 * @see cxJsonObjPut() |
875 * @see cxJsonObjPut() |
| 822 * @see cxJsonCreateInteger() |
876 * @see cxJsonCreateInteger() |
| 823 */ |
877 */ |
| 824 cx_attr_nonnull |
878 cx_attr_nonnull |
| 825 CX_EXPORT CxJsonValue* cxJsonObjPutInteger(CxJsonValue* obj, cxstring name, int64_t num); |
879 CX_EXPORT CxJsonValue* cx_json_obj_put_integer(CxJsonValue* obj, cxstring name, int64_t num); |
| |
880 |
| |
881 /** |
| |
882 * Creates a new JSON number, based on an integer, and adds it to an object. |
| |
883 * |
| |
884 * @param obj (@c CxJsonValue*) the target JSON object |
| |
885 * @param name (any string) the name of the new value |
| |
886 * @param num (@c int64_t) the numeric value |
| |
887 * @return (@c CxJsonValue*) the new value or @c NULL if allocation fails |
| |
888 * @see cxJsonObjPut() |
| |
889 * @see cxJsonCreateInteger() |
| |
890 */ |
| |
891 #define cxJsonObjPutInteger(obj, name, num) cx_json_obj_put_integer(obj, cx_strcast(name), num) |
| 826 |
892 |
| 827 /** |
893 /** |
| 828 * Creates a new JSON string and adds it to an object. |
894 * Creates a new JSON string and adds it to an object. |
| 829 * |
895 * |
| 830 * The string data is copied. |
896 * Internal function - use cxJsonObjPutString() |
| 831 * |
897 * |
| 832 * @param obj the target JSON object |
898 * @param obj the target JSON object |
| 833 * @param name the name of the new value |
899 * @param name the name of the new value |
| 834 * @param str the string data |
900 * @param str the string data |
| 835 * @return the new value or @c NULL if allocation fails |
901 * @return the new value or @c NULL if allocation fails |
| 836 * @see cxJsonObjPut() |
902 * @see cxJsonObjPut() |
| 837 * @see cxJsonCreateString() |
903 * @see cxJsonCreateString() |
| 838 */ |
904 */ |
| 839 cx_attr_nonnull cx_attr_cstr_arg(3) |
905 cx_attr_nonnull |
| 840 CX_EXPORT CxJsonValue* cxJsonObjPutString(CxJsonValue* obj, cxstring name, const char* str); |
906 CX_EXPORT CxJsonValue* cx_json_obj_put_string(CxJsonValue* obj, cxstring name, cxstring str); |
| 841 |
907 |
| 842 /** |
908 /** |
| 843 * Creates a new JSON string and adds it to an object. |
909 * Creates a new JSON string and adds it to an object. |
| 844 * |
910 * |
| 845 * The string data is copied. |
911 * The string data is copied. |
| 846 * |
912 * |
| 847 * @param obj the target JSON object |
913 * @param obj (@c CxJsonValue*) the target JSON object |
| 848 * @param name the name of the new value |
914 * @param name (any string) the name of the new value |
| 849 * @param str the string data |
915 * @param str (any string) the string data |
| 850 * @return the new value or @c NULL if allocation fails |
916 * @return (@c CxJsonValue*) the new value or @c NULL if allocation fails |
| 851 * @see cxJsonObjPut() |
917 * @see cxJsonObjPut() |
| 852 * @see cxJsonCreateCxString() |
918 * @see cxJsonCreateString() |
| 853 */ |
919 */ |
| 854 cx_attr_nonnull |
920 #define cxJsonObjPutString(obj, name, str) cx_json_obj_put_string(obj, cx_strcast(name), cx_strcast(str)) |
| 855 CX_EXPORT CxJsonValue* cxJsonObjPutCxString(CxJsonValue* obj, cxstring name, cxstring str); |
|
| 856 |
921 |
| 857 /** |
922 /** |
| 858 * Creates a new JSON literal and adds it to an object. |
923 * Creates a new JSON literal and adds it to an object. |
| |
924 * |
| |
925 * Internal function - use cxJsonObjPutLiteral(). |
| 859 * |
926 * |
| 860 * @param obj the target JSON object |
927 * @param obj the target JSON object |
| 861 * @param name the name of the new value |
928 * @param name the name of the new value |
| 862 * @param lit the type of literal |
929 * @param lit the type of literal |
| 863 * @return the new value or @c NULL if allocation fails |
930 * @return the new value or @c NULL if allocation fails |
| 864 * @see cxJsonObjPut() |
931 * @see cxJsonObjPut() |
| 865 * @see cxJsonCreateLiteral() |
932 * @see cxJsonCreateLiteral() |
| 866 */ |
933 */ |
| 867 cx_attr_nonnull |
934 cx_attr_nonnull |
| 868 CX_EXPORT CxJsonValue* cxJsonObjPutLiteral(CxJsonValue* obj, cxstring name, CxJsonLiteral lit); |
935 CX_EXPORT CxJsonValue* cx_json_obj_put_literal(CxJsonValue* obj, cxstring name, CxJsonLiteral lit); |
| |
936 |
| |
937 /** |
| |
938 * Creates a new JSON literal and adds it to an object. |
| |
939 * |
| |
940 * @param obj (@c CxJsonValue*) the target JSON object |
| |
941 * @param name (any string) the name of the new value |
| |
942 * @param lit (@c CxJsonLiteral) the type of literal |
| |
943 * @return (@c CxJsonValue*) the new value or @c NULL if allocation fails |
| |
944 * @see cxJsonObjPut() |
| |
945 * @see cxJsonCreateLiteral() |
| |
946 */ |
| |
947 #define cxJsonObjPutLiteral(obj, name, lit) cx_json_obj_put_literal(obj, cx_strcast(name), lit) |
| 869 |
948 |
| 870 /** |
949 /** |
| 871 * Recursively deallocates the memory of a JSON value. |
950 * Recursively deallocates the memory of a JSON value. |
| 872 * |
951 * |
| 873 * @remark The type of each deallocated value will be changed |
952 * @remark The type of each deallocated value will be changed |