MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / jl_insert_member

Function jl_insert_member

src/cli/config_json_like.c:1872–1919  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1870}
1871
1872static int jl_insert_member(const char *source, size_t source_length, size_t object_start,
1873 const jl_object_t *object, const char *const *object_path,
1874 size_t path_len, size_t missing_path_index, const char *entry_key,
1875 const char *entry_json, size_t entry_length, char **result_out,
1876 size_t *result_length_out) {
1877 jl_slice_t base;
1878 jl_slice_t unit;
1879 bool close_indent_only = false;
1880 jl_detect_indent(source, object, &base, &unit, &close_indent_only);
1881 (void)close_indent_only;
1882
1883 jl_buffer_t member = {0};
1884 jl_buffer_t insertion = {0};
1885 const char *newline = jl_newline_style(source, source_length);
1886 int result = jl_build_member(&member, object_path, path_len, missing_path_index, entry_key,
1887 entry_json, entry_length, newline, base, unit);
1888 if (result == 0) {
1889 result =
1890 jl_make_insertion(source, source_length, object_start, object, &member, &insertion);
1891 }
1892 if (result != 0) {
1893 free(member.data);
1894 free(insertion.data);
1895 return -1;
1896 }
1897
1898 jl_edit_t edits[2];
1899 size_t edit_count = 0;
1900 if (object->member_count > 0U && !object->trailing_comma) {
1901 edits[edit_count++] = (jl_edit_t){
1902 .start = object->last_value_end,
1903 .end = object->last_value_end,
1904 .replacement = ",",
1905 .replacement_length = 1U,
1906 };
1907 }
1908 edits[edit_count++] = (jl_edit_t){
1909 .start = object->close_pos,
1910 .end = object->close_pos,
1911 .replacement = insertion.data,
1912 .replacement_length = insertion.length,
1913 };
1914 result =
1915 jl_apply_edits(source, source_length, edits, edit_count, result_out, result_length_out);
1916 free(member.data);
1917 free(insertion.data);
1918 return result;
1919}
1920
1921static int jl_insert_array_string(const char *source, size_t source_length, size_t array_start,
1922 const jl_array_t *array, const char *string_value,

Callers 2

jl_upsert_entryFunction · 0.85

Calls 5

jl_detect_indentFunction · 0.85
jl_newline_styleFunction · 0.85
jl_build_memberFunction · 0.85
jl_make_insertionFunction · 0.85
jl_apply_editsFunction · 0.85

Tested by

no test coverage detected