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

Function jl_make_insertion

src/cli/config_json_like.c:1181–1239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1179}
1180
1181static int jl_make_insertion(const char *text, size_t length, size_t object_start,
1182 const jl_object_t *object, const jl_buffer_t *member,
1183 jl_buffer_t *insertion) {
1184 jl_slice_t base;
1185 jl_slice_t unit;
1186 bool close_indent_only = false;
1187 jl_detect_indent(text, object, &base, &unit, &close_indent_only);
1188 const char *newline = jl_newline_style(text, length);
1189
1190 size_t gap_start = object_start + 1U;
1191 if (object->member_count > 0U) {
1192 gap_start = object->trailing_comma ? object->last_comma_pos + 1U : object->last_value_end;
1193 }
1194 bool multiline = jl_range_has_newline(text, gap_start, object->close_pos);
1195 bool empty_tight = object->member_count == 0U && gap_start == object->close_pos;
1196
1197 if (empty_tight) {
1198 if (jl_buffer_string(insertion, newline) != 0 ||
1199 jl_append_styled_indent(insertion, base, unit, 1U) != 0 ||
1200 jl_buffer_append(insertion, member->data, member->length) != 0 ||
1201 jl_buffer_string(insertion, newline) != 0 ||
1202 jl_buffer_append(insertion, base.data, base.length) != 0) {
1203 return -1;
1204 }
1205 return 0;
1206 }
1207
1208 if (multiline) {
1209 if (!close_indent_only && jl_buffer_string(insertion, newline) != 0) {
1210 return -1;
1211 }
1212 if (jl_buffer_append(insertion, unit.data, unit.length) != 0 ||
1213 jl_buffer_append(insertion, member->data, member->length) != 0) {
1214 return -1;
1215 }
1216 if (object->trailing_comma && jl_buffer_char(insertion, ',') != 0) {
1217 return -1;
1218 }
1219 if (jl_buffer_string(insertion, newline) != 0 ||
1220 jl_buffer_append(insertion, base.data, base.length) != 0) {
1221 return -1;
1222 }
1223 return 0;
1224 }
1225
1226 if (object->close_pos == gap_start ||
1227 !jl_is_space((unsigned char)text[object->close_pos - 1U])) {
1228 if (jl_buffer_char(insertion, ' ') != 0) {
1229 return -1;
1230 }
1231 }
1232 if (jl_buffer_append(insertion, member->data, member->length) != 0) {
1233 return -1;
1234 }
1235 if (object->trailing_comma && jl_buffer_char(insertion, ',') != 0) {
1236 return -1;
1237 }
1238 return jl_buffer_char(insertion, ' ');

Callers 2

jl_insert_memberFunction · 0.85
jl_insert_array_stringFunction · 0.85

Calls 8

jl_detect_indentFunction · 0.85
jl_newline_styleFunction · 0.85
jl_range_has_newlineFunction · 0.85
jl_buffer_stringFunction · 0.85
jl_append_styled_indentFunction · 0.85
jl_buffer_appendFunction · 0.85
jl_buffer_charFunction · 0.85
jl_is_spaceFunction · 0.85

Tested by

no test coverage detected