teptris 0.3.12.1-s390x-linux → 0.3.14.0-s390x-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 173d8f6ff382784dc094a76f0106395d0f27e8c0879679f26f70c4bb41482285
4
- data.tar.gz: 856538b1fb98fdd07f37288e468ea88d34ce670073e4d10581b90c24a4895059
3
+ metadata.gz: e68f91f05ed2a16511a60235dd8c6f5c4930a9ec4862ae794650d845ab97a7a1
4
+ data.tar.gz: 39b2cebfe841e05c3a8a7c0daffc3f274ba45db051564070bb82ce4594282717
5
5
  SHA512:
6
- metadata.gz: 79241aa7ae4a05447e4669c44ad28e43affd03285b3c93ee6b06412fa5ccf3d0f3e315bd5e329e44ac59e448efb9d61191c4089367b49438dbd820f8abc06238
7
- data.tar.gz: 253a29b49f45d670ec058ddd78b5811bbd0402794ef0aceb59f0d4ab5c9bc4eeab9fc2ab2f2102f86d6235fd850823cc773c750deab6ee1c9c3fa06393061fa0
6
+ metadata.gz: 665990589ccbd44ed9908835534d37b63d58a6df8fa898556a07b15fd631b5f5d1c90be010eab192a42470bcabf7588271eb7ecefdda8291de49b295e32267a9
7
+ data.tar.gz: 5f78377dd41e4bfd88e2efb4b65ff323a841b91178f14297243dece51c187b3c2530e40f8075f5f4fb82d8f81ab835724309043f5f5e3f633eda4f90cfd41327
@@ -1,4 +1,4 @@
1
- # libteptris 0.3.12 — vendored source
1
+ # libteptris 0.3.14 — vendored source
2
2
 
3
3
  This directory carries the COMPLETE C source of the engine this
4
4
  gem's extension was built from (the packaging doctrine: compiled
@@ -143,6 +143,20 @@ TEPTRIS_API const teptris_node * teptris_node_table_get(const teptris_node *node
143
143
  TEPTRIS_API teptris_status teptris_document_emit(const teptris_document *doc,
144
144
  char **buf, size_t *len);
145
145
 
146
+ /* In-place scalar edit (format-preserving v1): rewrite exactly the
147
+ * value bytes of one key = value line; every other byte of the source
148
+ * is preserved (comments, blank lines, formatting). dotted.key.path
149
+ * addresses the key (bare and quoted components; the path may carry a
150
+ * [table] prefix, e.g. "t.x" for x inside [t]). replacement is the
151
+ * value's TEXT (e.g. "42", "\"str\"", "2026-01-01") and must form a
152
+ * valid single-line value: it is validated by parsing "k = <text>".
153
+ * v1 rejects multiline and inline-collection targets with
154
+ * TEPTRIS_ERR_ARG. Memory: *buf is malloc'd; caller frees. */
155
+ TEPTRIS_API teptris_status teptris_edit_scalar(const char *src, size_t len,
156
+ const char *keypath,
157
+ const char *replacement,
158
+ char **buf, size_t *out_len);
159
+
146
160
  /* Emit the toml-test wire shape: scalars as {"type":..,"value":..},
147
161
  * tables as objects, arrays as lists, insertion order.
148
162
  * Memory: *buf is malloc'd; caller frees with free(). */
@@ -4,6 +4,6 @@
4
4
  #define TEPTRIS_VERSION_MAJOR 0
5
5
  #define TEPTRIS_VERSION_MINOR 3
6
6
  #define TEPTRIS_VERSION_PATCH 0
7
- #define TEPTRIS_VERSION_STRING "0.3.12"
7
+ #define TEPTRIS_VERSION_STRING "0.3.14"
8
8
 
9
9
  #endif /* TEPTRIS_VERSION_H */
@@ -0,0 +1,384 @@
1
+ /* Format-preserving scalar edit (v1): rewrite exactly the value bytes
2
+ * of one key = value line; every other byte of the source is
3
+ * preserved. The target is addressed by a dotted key path that may
4
+ * carry a [table] prefix ("t.x" addresses x inside [t]; the LAST
5
+ * component is the key, everything before it is the table path that
6
+ * must match the current [section]). The replacement is the value's
7
+ * TEXT and is validated by parsing "k = <replacement>" - the editor
8
+ * stays value-agnostic.
9
+ *
10
+ * v1 scope: single-line scalar values (numbers, booleans, dates,
11
+ * single-line quoted strings). Multiline strings and inline
12
+ * collections are rejected with TEPTRIS_ERR_ARG rather than
13
+ * half-understood. */
14
+ #include <stdio.h>
15
+ #include <stdlib.h>
16
+ #include <string.h>
17
+
18
+ #include "teptris/teptris.h"
19
+
20
+ static int edit_is_ws(char c)
21
+ {
22
+ return c == ' ' || c == '\t';
23
+ }
24
+
25
+ static const char *edit_skip_ws(const char *p, const char *end)
26
+ {
27
+ while (p < end && edit_is_ws(*p)) {
28
+ p++;
29
+ }
30
+ return p;
31
+ }
32
+
33
+ /* match one key component (bare or quoted) against the source at p;
34
+ * returns the pointer past the component, else NULL */
35
+ static const char *edit_match_component(const char *p, const char *end,
36
+ const char *comp, size_t comp_len)
37
+ {
38
+ if (p >= end) {
39
+ return NULL;
40
+ }
41
+ if (*p == '\'' || *p == '"') {
42
+ char q = *p;
43
+ p++;
44
+ size_t ci = 0;
45
+ while (p < end && *p != q) {
46
+ char c = *p;
47
+ if (c == '\n') {
48
+ return NULL;
49
+ }
50
+ if (q == '"' && c == '\\' && p + 1 < end) {
51
+ /* raw-byte comparison: an escaped component character
52
+ * simply fails to match (v1 keeps key matching
53
+ * escape-naive) */
54
+ if (ci < comp_len && comp[ci] != c) {
55
+ return NULL;
56
+ }
57
+ ci++;
58
+ p += 2;
59
+ continue;
60
+ }
61
+ if (ci >= comp_len || comp[ci] != c) {
62
+ return NULL;
63
+ }
64
+ ci++;
65
+ p++;
66
+ }
67
+ if (p >= end || ci != comp_len) {
68
+ return NULL;
69
+ }
70
+ return p + 1;
71
+ }
72
+ if (comp_len == 0) {
73
+ return NULL;
74
+ }
75
+ if ((size_t)(end - p) < comp_len || memcmp(p, comp, comp_len) != 0) {
76
+ return NULL;
77
+ }
78
+ p += comp_len;
79
+ if (p == end || p[0] == '.' || edit_is_ws(p[0]) || p[0] == '=' ||
80
+ p[0] == ']') {
81
+ return p;
82
+ }
83
+ return NULL;
84
+ }
85
+
86
+ /* match a full dotted path at p; returns the pointer past the path,
87
+ * else NULL. Dots inside quotes do not split. */
88
+ static const char *edit_match_path(const char *p, const char *end,
89
+ const char *path, size_t path_len)
90
+ {
91
+ const char *pc = path;
92
+ const char *pend = path + path_len;
93
+ for (;;) {
94
+ while (pc < pend && edit_is_ws(*pc)) {
95
+ pc++;
96
+ }
97
+ const char *cstart = pc;
98
+ int quoted = 0;
99
+ while (pc < pend) {
100
+ if (*pc == '\'' || *pc == '"') {
101
+ quoted = !quoted;
102
+ } else if (*pc == '.' && !quoted) {
103
+ break;
104
+ }
105
+ pc++;
106
+ }
107
+ if (quoted) {
108
+ return NULL;
109
+ }
110
+ const char *cend = pc;
111
+ while (cend > cstart && edit_is_ws(cend[-1])) {
112
+ cend--;
113
+ }
114
+ while (cstart < cend && edit_is_ws(*cstart)) {
115
+ cstart++;
116
+ }
117
+ if (cstart == cend) {
118
+ return NULL;
119
+ }
120
+ p = edit_match_component(p, end, cstart, (size_t)(cend - cstart));
121
+ if (p == NULL) {
122
+ return NULL;
123
+ }
124
+ p = edit_skip_ws(p, end);
125
+ if (pc < pend && *pc == '.') {
126
+ pc++;
127
+ if (p < end && *p == '.') {
128
+ p++; /* consume the source's separator too */
129
+ p = edit_skip_ws(p, end);
130
+ }
131
+ continue;
132
+ }
133
+ return p;
134
+ }
135
+ }
136
+
137
+ /* does the line carry a [section] or [[aot]] header? fills the path
138
+ * span (between the brackets, trimmed) */
139
+ static int edit_section_header(const char *p, const char *end,
140
+ const char **path, size_t *path_len)
141
+ {
142
+ p = edit_skip_ws(p, end);
143
+ if (p >= end || *p != '[') {
144
+ return 0;
145
+ }
146
+ p++;
147
+ if (p < end && *p == '[') {
148
+ p++;
149
+ }
150
+ p = edit_skip_ws(p, end);
151
+ const char *start = p;
152
+ while (p < end && *p != ']') {
153
+ if (*p == '\n') {
154
+ return 0;
155
+ }
156
+ p++;
157
+ }
158
+ if (p >= end) {
159
+ return 0;
160
+ }
161
+ const char *stop = p;
162
+ while (stop > start && edit_is_ws(stop[-1])) {
163
+ stop--;
164
+ }
165
+ *path = start;
166
+ *path_len = (size_t)(stop - start);
167
+ return 1;
168
+ }
169
+
170
+ /* the value span on a keyval line: p sits past '='. Absolute [start,
171
+ * end) of the value bytes. Single-line scalars only: returns 0, or
172
+ * -1 for multiline/inline targets. */
173
+ static int edit_value_span(const char *p, const char *end,
174
+ const char **vstart, const char **vend)
175
+ {
176
+ p = edit_skip_ws(p, end);
177
+ if (p >= end) {
178
+ return -1;
179
+ }
180
+ const char *vs = p;
181
+ if (*p == '\'') {
182
+ p++;
183
+ while (p < end && *p != '\'') {
184
+ if (*p == '\n') {
185
+ return -1;
186
+ }
187
+ p++;
188
+ }
189
+ if (p >= end) {
190
+ return -1;
191
+ }
192
+ p++;
193
+ } else if (*p == '"') {
194
+ if (p + 2 < end && p[1] == '"' && p[2] == '"') {
195
+ return -1; /* multiline basic */
196
+ }
197
+ p++;
198
+ while (p < end && *p != '"') {
199
+ if (*p == '\n') {
200
+ return -1;
201
+ }
202
+ if (*p == '\\' && p + 1 < end) {
203
+ p += 2;
204
+ continue;
205
+ }
206
+ p++;
207
+ }
208
+ if (p >= end) {
209
+ return -1;
210
+ }
211
+ p++;
212
+ } else if (*p == '{' || *p == '[') {
213
+ return -1; /* inline collections: v1 out of scope */
214
+ } else {
215
+ while (p < end && *p != '\n' && *p != '#') {
216
+ p++;
217
+ }
218
+ while (p > vs && edit_is_ws(p[-1])) {
219
+ p--;
220
+ }
221
+ }
222
+ *vstart = vs;
223
+ *vend = p;
224
+ return 0;
225
+ }
226
+
227
+ /* Split the target keypath at its LAST unquoted '.': the prefix is
228
+ * the table path (must textually match the open [section]), the last
229
+ * component is the key written on the line. A dotted key LINE
230
+ * ("a.b = 1") additionally matches when its full written path equals
231
+ * the target - handled by trying the full-path match first. */
232
+ static void edit_split_target(const char *keypath, size_t klen,
233
+ const char **prefix, size_t *prefix_len,
234
+ const char **last, size_t *last_len)
235
+ {
236
+ const char *kp_end = keypath + klen;
237
+ const char *dot = NULL;
238
+ int quoted = 0;
239
+ for (const char *q = keypath; q < kp_end; q++) {
240
+ if (*q == '\'' || *q == '"') {
241
+ quoted = !quoted;
242
+ } else if (*q == '.' && !quoted) {
243
+ dot = q;
244
+ }
245
+ }
246
+ if (dot == NULL) {
247
+ *prefix = NULL;
248
+ *prefix_len = 0;
249
+ *last = keypath;
250
+ *last_len = klen;
251
+ return;
252
+ }
253
+ *prefix = keypath;
254
+ *prefix_len = (size_t)(dot - keypath);
255
+ *last = dot + 1;
256
+ *last_len = (size_t)(kp_end - (dot + 1));
257
+ }
258
+
259
+ /* raw textual comparison of the open section against the target's
260
+ * table prefix (v1: quoting/spacing variants of the same path do not
261
+ * match; the canonical form does) */
262
+ static int edit_section_matches(const char *prefix, size_t prefix_len,
263
+ const char *sec, size_t sec_len)
264
+ {
265
+ const char *ps = prefix;
266
+ while (prefix_len > 0 && edit_is_ws(ps[0])) {
267
+ ps++;
268
+ prefix_len--;
269
+ }
270
+ while (prefix_len > 0 && edit_is_ws(ps[prefix_len - 1])) {
271
+ prefix_len--;
272
+ }
273
+ if (prefix_len == 0) {
274
+ return sec_len == 0; /* bare key: root only */
275
+ }
276
+ if (sec_len != prefix_len) {
277
+ return 0;
278
+ }
279
+ return memcmp(sec, ps, prefix_len) == 0;
280
+ }
281
+
282
+ teptris_status teptris_edit_scalar(const char *src, size_t len,
283
+ const char *keypath,
284
+ const char *replacement,
285
+ char **buf, size_t *out_len)
286
+ {
287
+ if (src == NULL || keypath == NULL || replacement == NULL ||
288
+ buf == NULL || out_len == NULL) {
289
+ return TEPTRIS_ERR_ARG;
290
+ }
291
+ const char *end = src + len;
292
+
293
+ /* validate the replacement by parsing it as a keyval */
294
+ {
295
+ size_t rlen = strlen(replacement);
296
+ if (rlen == 0 || rlen > 4096) {
297
+ return TEPTRIS_ERR_ARG;
298
+ }
299
+ if (strchr(replacement, '\n') != NULL) {
300
+ return TEPTRIS_ERR_ARG; /* v1: single-line replacements */
301
+ }
302
+ char probe[4200];
303
+ int n = snprintf(probe, sizeof probe, "k = %s\n", replacement);
304
+ if (n <= 0 || (size_t)n >= sizeof probe) {
305
+ return TEPTRIS_ERR_ARG;
306
+ }
307
+ teptris_document *probe_doc = NULL;
308
+ teptris_status st = teptris_parse(probe, (size_t)n, NULL, &probe_doc);
309
+ if (st != TEPTRIS_OK) {
310
+ if (probe_doc != NULL) {
311
+ teptris_document_free(probe_doc);
312
+ }
313
+ return TEPTRIS_ERR_ARG;
314
+ }
315
+ teptris_document_free(probe_doc);
316
+ }
317
+
318
+ size_t klen = strlen(keypath);
319
+ const char *sec = NULL; /* current [section] path span */
320
+ size_t sec_len = 0;
321
+
322
+ const char *p = src;
323
+ while (p < end) {
324
+ const char *nl = memchr(p, '\n', (size_t)(end - p));
325
+ const char *le = nl ? nl : end;
326
+ const char *t = edit_skip_ws(p, le);
327
+ if (t < le && *t != '#') {
328
+ const char *hp;
329
+ size_t hlen;
330
+ if (edit_section_header(t, le, &hp, &hlen)) {
331
+ sec = hp;
332
+ sec_len = hlen;
333
+ } else {
334
+ const char *after = NULL;
335
+ if (sec_len == 0) {
336
+ /* root: a dotted key LINE may carry the full path */
337
+ after = edit_match_path(t, le, keypath, klen);
338
+ }
339
+ if (after == NULL) {
340
+ /* the line carries just the key: the last target
341
+ * component, under a matching open section */
342
+ const char *pfx;
343
+ size_t pfx_len;
344
+ const char *lastc;
345
+ size_t last_len;
346
+ edit_split_target(keypath, klen, &pfx, &pfx_len,
347
+ &lastc, &last_len);
348
+ if (last_len > 0 &&
349
+ edit_section_matches(pfx, pfx_len, sec, sec_len)) {
350
+ after = edit_match_path(t, le, lastc, last_len);
351
+ }
352
+ }
353
+ if (after != NULL) {
354
+ const char *eq = edit_skip_ws(after, le);
355
+ if (eq < le && *eq == '=') {
356
+ const char *vs;
357
+ const char *ve;
358
+ if (edit_value_span(eq + 1, le, &vs, &ve) != 0) {
359
+ return TEPTRIS_ERR_ARG;
360
+ }
361
+ size_t rlen = strlen(replacement);
362
+ size_t pre = (size_t)(vs - src);
363
+ size_t post = (size_t)(end - ve);
364
+ char *out = malloc(pre + rlen + post);
365
+ if (out == NULL) {
366
+ return TEPTRIS_ERR_ALLOC;
367
+ }
368
+ memcpy(out, src, pre);
369
+ memcpy(out + pre, replacement, rlen);
370
+ memcpy(out + pre + rlen, ve, post);
371
+ *buf = out;
372
+ *out_len = pre + rlen + post;
373
+ return TEPTRIS_OK;
374
+ }
375
+ }
376
+ }
377
+ }
378
+ if (nl == NULL) {
379
+ break;
380
+ }
381
+ p = nl + 1;
382
+ }
383
+ return TEPTRIS_ERR_STATE; /* key not found */
384
+ }
Binary file
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Teptris
4
- VERSION = "0.3.12.1"
4
+ VERSION = "0.3.14.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.12.1
4
+ version: 0.3.14.0
5
5
  platform: s390x-linux
6
6
  authors:
7
7
  - teptris contributors
@@ -38,6 +38,7 @@ files:
38
38
  - ext/teptris_ext/engine/src/teptris/common/simd.h
39
39
  - ext/teptris_ext/engine/src/teptris/dom/dom.c
40
40
  - ext/teptris_ext/engine/src/teptris/dom/dom.h
41
+ - ext/teptris_ext/engine/src/teptris/edit/edit.c
41
42
  - ext/teptris_ext/engine/src/teptris/emit/emit_shared.h
42
43
  - ext/teptris_ext/engine/src/teptris/emit/emitter.c
43
44
  - ext/teptris_ext/engine/src/teptris/emit/emitter.h