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

Function jl_insert_member

src/cli/config_json_like.c:1939–1986  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1937}
1938
1939static int jl_insert_member(const char *source, size_t source_length, size_t object_start,
1940 const jl_object_t *object, const char *const *object_path,
1941 size_t path_len, size_t missing_path_index, const char *entry_key,
1942 const char *entry_json, size_t entry_length, char **result_out,
1943 size_t *result_length_out) {
1944 jl_slice_t base;
1945 jl_slice_t unit;
1946 bool close_indent_only = false;
1947 jl_detect_indent(source, object, &base, &unit, &close_indent_only);
1948 (void)close_indent_only;
1949
1950 jl_buffer_t member = {0};
1951 jl_buffer_t insertion = {0};
1952 const char *newline = jl_newline_style(source, source_length);
1953 int result = jl_build_member(&member, object_path, path_len, missing_path_index, entry_key,
1954 entry_json, entry_length, newline, base, unit);
1955 if (result == 0) {
1956 result =
1957 jl_make_insertion(source, source_length, object_start, object, &member, &insertion);
1958 }
1959 if (result != 0) {
1960 free(member.data);
1961 free(insertion.data);
1962 return -1;
1963 }
1964
1965 jl_edit_t edits[2];
1966 size_t edit_count = 0;
1967 if (object->member_count > 0U && !object->trailing_comma) {
1968 edits[edit_count++] = (jl_edit_t){
1969 .start = object->last_value_end,
1970 .end = object->last_value_end,
1971 .replacement = ",",
1972 .replacement_length = 1U,
1973 };
1974 }
1975 edits[edit_count++] = (jl_edit_t){
1976 .start = object->close_pos,
1977 .end = object->close_pos,
1978 .replacement = insertion.data,
1979 .replacement_length = insertion.length,
1980 };
1981 result =
1982 jl_apply_edits(source, source_length, edits, edit_count, result_out, result_length_out);
1983 free(member.data);
1984 free(insertion.data);
1985 return result;
1986}
1987
1988static int jl_insert_array_string(const char *source, size_t source_length, size_t array_start,
1989 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