teptris 0.3.14.0-arm-linux → 0.3.16.0-arm-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: 24835ad5218658977a3cf3ed254a16da85fdcc8ddd43842cbf48c128ecac9a9a
4
- data.tar.gz: a367749bed6a4ce5a7d26e0c33e3220e255e93e6016accce5b1b674431d3c5c5
3
+ metadata.gz: 3691092c4f91a3174252ce4536391b6ebf3fc66bce845a6eb1567ad41755396d
4
+ data.tar.gz: 951f16b3681f3ec9f3d427397ac3f80b15afff1da4d588db104b8ca04c0baf57
5
5
  SHA512:
6
- metadata.gz: cceab9025292fdf2329a3a905e1c57b726b824927b6f12b21d81f2511638b3bb941fed9e159044a8e38518bd6a216dc9b7b98d368dcdb82782c345afc2ae1497
7
- data.tar.gz: 80fb88c638ec3adcddd4a3f8ec3121caafdeb5ff20c66ba360bc8fc719e9b8f820aa786b718673c391e3748c45011f98fb071af94c2e3e5b249aeb9365d9fb7d
6
+ metadata.gz: 5262baad4efbc7abde666cdba696aad4f1ba1554387886b7f0bfa7e745bd313dad0e1650be0e767d890a2a08f25a1ae8430b979e85f4e61fa4f2c610b5ca110a
7
+ data.tar.gz: 02d75a317e1e6613872d05fd56cec5e8d68cb9f4462f7f4a203897845cb7de0fc8e27dcb30e9ff25ede59958e24f5a9304be01889691bcd6b775b50a699fc59c
@@ -1,4 +1,4 @@
1
- # libteptris 0.3.14 — vendored source
1
+ # libteptris 0.3.16 — 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,15 +143,17 @@ 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
146
+ /* In-place scalar edit (format-preserving v2): rewrite exactly the
147
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. */
148
+ * is preserved (comments, blank lines, formatting, CRLF endings).
149
+ * dotted.key.path addresses the key (bare and quoted components; the
150
+ * path may carry a [table] prefix, e.g. "t.x" for x inside [t]).
151
+ * replacement is the value's TEXT (e.g. "42", "\"str\"", "2026-01-01",
152
+ * or a multiline string value) and is validated by parsing
153
+ * "k = <text>". v2 splices multiline strings and inline collections
154
+ * too; those splices are parse-verified before handback (a
155
+ * mis-scanned span rejects with TEPTRIS_ERR_ARG instead of
156
+ * corrupting). Memory: *buf is malloc'd; caller frees. */
155
157
  TEPTRIS_API teptris_status teptris_edit_scalar(const char *src, size_t len,
156
158
  const char *keypath,
157
159
  const char *replacement,
@@ -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.14"
7
+ #define TEPTRIS_VERSION_STRING "0.3.16"
8
8
 
9
9
  #endif /* TEPTRIS_VERSION_H */
@@ -1,4 +1,4 @@
1
- /* Format-preserving scalar edit (v1): rewrite exactly the value bytes
1
+ /* Format-preserving scalar edit (v2): rewrite exactly the value bytes
2
2
  * of one key = value line; every other byte of the source is
3
3
  * preserved. The target is addressed by a dotted key path that may
4
4
  * carry a [table] prefix ("t.x" addresses x inside [t]; the LAST
@@ -7,10 +7,10 @@
7
7
  * TEXT and is validated by parsing "k = <replacement>" - the editor
8
8
  * stays value-agnostic.
9
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. */
10
+ * v2 scope: single-line scalars, multiline strings and inline
11
+ * collections all splice; v2 spans are parse-verified before handback
12
+ * so a mis-scanned span rejects instead of corrupting. CRLF line
13
+ * endings are preserved (the line-tail \r is outside the span). */
14
14
  #include <stdio.h>
15
15
  #include <stdlib.h>
16
16
  #include <string.h>
@@ -167,60 +167,106 @@ static int edit_section_header(const char *p, const char *end,
167
167
  return 1;
168
168
  }
169
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. */
170
+ /* Skip one string spanning from its opening quote at p; mirrors the
171
+ * engine's scanners: quote-run close (run >= 3 for multiline), escape
172
+ * tracking in basic strings. Returns the pointer past the string, or
173
+ * NULL when unterminated. */
174
+ static const char *edit_skip_string(const char *p, const char *end)
175
+ {
176
+ char q = *p;
177
+ int ml = (p + 2 < end && p[1] == q && p[2] == q);
178
+ p += ml ? 3 : 1;
179
+ while (p < end) {
180
+ char c = *p;
181
+ if (q == '"' && c == '\\') {
182
+ if (p + 1 >= end) {
183
+ return NULL; /* unterminated escape */
184
+ }
185
+ p += 2;
186
+ continue;
187
+ }
188
+ if (c == q) {
189
+ int run = 0;
190
+ while (p + run < end && p[run] == q) {
191
+ run++;
192
+ }
193
+ if (!ml) {
194
+ return p + 1; /* single-line closes at the first quote */
195
+ }
196
+ if (run >= 3) {
197
+ return p + run; /* multiline closes at the run */
198
+ }
199
+ p += run; /* 1-2 quotes inside multiline: content */
200
+ continue;
201
+ }
202
+ p++;
203
+ }
204
+ return NULL;
205
+ }
206
+
207
+ /* the value span of a keyval line: p sits past '='. Absolute [start,
208
+ * end) of the value bytes. Returns 0 with *verified unset for the
209
+ * single-line scalar fast path (v1 contract: no parse required), or 1
210
+ * for string/inline spans whose splice must be parse-verified, or -1
211
+ * for a malformed span. */
173
212
  static int edit_value_span(const char *p, const char *end,
174
- const char **vstart, const char **vend)
213
+ const char **vstart, const char **vend,
214
+ int *verified)
175
215
  {
176
216
  p = edit_skip_ws(p, end);
177
217
  if (p >= end) {
178
218
  return -1;
179
219
  }
180
220
  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) {
221
+ const char *ve = NULL;
222
+
223
+ if (*p == '\'' || *p == '"') {
224
+ p = edit_skip_string(p, end);
225
+ if (p == NULL) {
190
226
  return -1;
191
227
  }
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;
228
+ ve = p;
229
+ *verified = 1;
230
+ } else if (*p == '{' || *p == '[') {
231
+ int depth = 0;
232
+ while (p < end) {
233
+ char c = *p;
234
+ if (c == '\'' || c == '"') {
235
+ p = edit_skip_string(p, end);
236
+ if (p == NULL) {
237
+ return -1;
238
+ }
239
+ continue;
201
240
  }
202
- if (*p == '\\' && p + 1 < end) {
203
- p += 2;
241
+ if (c == '{' || c == '[') {
242
+ depth++;
243
+ } else if (c == '}' || c == ']') {
244
+ depth--;
245
+ p++;
246
+ if (depth == 0) {
247
+ ve = p;
248
+ break;
249
+ }
204
250
  continue;
205
251
  }
206
252
  p++;
207
253
  }
208
- if (p >= end) {
209
- return -1;
254
+ if (ve == NULL) {
255
+ return -1; /* unbalanced inline collection */
210
256
  }
211
- p++;
212
- } else if (*p == '{' || *p == '[') {
213
- return -1; /* inline collections: v1 out of scope */
257
+ *verified = 1;
214
258
  } else {
215
259
  while (p < end && *p != '\n' && *p != '#') {
216
260
  p++;
217
261
  }
218
- while (p > vs && edit_is_ws(p[-1])) {
219
- p--;
262
+ while (p > vs && (edit_is_ws(p[-1]) || p[-1] == '\r')) {
263
+ p--; /* CRLF: the line-tail \r stays outside the span */
220
264
  }
265
+ ve = p;
266
+ *verified = 0;
221
267
  }
222
268
  *vstart = vs;
223
- *vend = p;
269
+ *vend = ve;
224
270
  return 0;
225
271
  }
226
272
 
@@ -290,22 +336,23 @@ teptris_status teptris_edit_scalar(const char *src, size_t len,
290
336
  }
291
337
  const char *end = src + len;
292
338
 
293
- /* validate the replacement by parsing it as a keyval */
339
+ /* validate the replacement by parsing it as a keyval; multiline
340
+ * replacements (multiline-string values) are fine - the probe
341
+ * parse is the only gate */
294
342
  {
295
343
  size_t rlen = strlen(replacement);
296
- if (rlen == 0 || rlen > 4096) {
344
+ if (rlen == 0 || rlen > 16384) {
297
345
  return TEPTRIS_ERR_ARG;
298
346
  }
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;
347
+ char *probe = malloc(rlen + 16);
348
+ if (probe == NULL) {
349
+ return TEPTRIS_ERR_ALLOC;
306
350
  }
351
+ int n = snprintf(probe, rlen + 16, "k = %s\n", replacement);
307
352
  teptris_document *probe_doc = NULL;
308
- teptris_status st = teptris_parse(probe, (size_t)n, NULL, &probe_doc);
353
+ teptris_status st = teptris_parse(probe, (size_t)n, NULL,
354
+ &probe_doc);
355
+ free(probe);
309
356
  if (st != TEPTRIS_OK) {
310
357
  if (probe_doc != NULL) {
311
358
  teptris_document_free(probe_doc);
@@ -355,7 +402,11 @@ teptris_status teptris_edit_scalar(const char *src, size_t len,
355
402
  if (eq < le && *eq == '=') {
356
403
  const char *vs;
357
404
  const char *ve;
358
- if (edit_value_span(eq + 1, le, &vs, &ve) != 0) {
405
+ int verified = 0;
406
+ /* the span scan bounds at the whole source:
407
+ * multiline and inline values cross lines */
408
+ if (edit_value_span(eq + 1, end, &vs, &ve,
409
+ &verified) != 0) {
359
410
  return TEPTRIS_ERR_ARG;
360
411
  }
361
412
  size_t rlen = strlen(replacement);
@@ -368,6 +419,22 @@ teptris_status teptris_edit_scalar(const char *src, size_t len,
368
419
  memcpy(out, src, pre);
369
420
  memcpy(out + pre, replacement, rlen);
370
421
  memcpy(out + pre + rlen, ve, post);
422
+ if (verified) {
423
+ /* v2 spans are parse-verified: a
424
+ * mis-scanned span rejects instead of
425
+ * corrupting */
426
+ teptris_document *vd = NULL;
427
+ teptris_status vst = teptris_parse(out,
428
+ pre + rlen + post, NULL, &vd);
429
+ if (vst != TEPTRIS_OK) {
430
+ if (vd != NULL) {
431
+ teptris_document_free(vd);
432
+ }
433
+ free(out);
434
+ return TEPTRIS_ERR_ARG;
435
+ }
436
+ teptris_document_free(vd);
437
+ }
371
438
  *buf = out;
372
439
  *out_len = pre + rlen + post;
373
440
  return TEPTRIS_OK;
@@ -105,7 +105,7 @@ teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
105
105
  int mi = d2(p + 3);
106
106
  int s = 0; /* TOML 1.1: seconds optional */
107
107
  size_t consumed = 5;
108
- if (p[5] == ':') {
108
+ if ((size_t)(end - p) >= 6 && p[5] == ':') {
109
109
  if ((size_t)(end - p) < 8 || !is_dig(p + 6) || !is_dig(p + 7)) {
110
110
  return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX,
111
111
  "invalid second");
@@ -369,6 +369,35 @@ static VALUE ext_version(VALUE self) {
369
369
  return rb_str_new_cstr(teptris_version_string());
370
370
  }
371
371
 
372
+ /* ------------------------------------------------------------- edit */
373
+
374
+ /* Format-preserving edit: rewrite exactly the value bytes of one
375
+ * key = value line; every other byte of the source survives. Returns
376
+ * the edited document as a String. Teptris::Error on an absent key or
377
+ * a malformed span/replacement. */
378
+ static VALUE ext_edit(VALUE self, VALUE src, VALUE keypath, VALUE replacement) {
379
+ StringValue(src);
380
+ StringValue(keypath);
381
+ StringValue(replacement);
382
+ char *buf = NULL;
383
+ size_t out_len = 0;
384
+ teptris_status st = teptris_edit_scalar(
385
+ RSTRING_PTR(src), (size_t)RSTRING_LEN(src),
386
+ StringValueCStr(keypath), StringValueCStr(replacement),
387
+ &buf, &out_len);
388
+ if (st != TEPTRIS_OK) {
389
+ if (st == TEPTRIS_ERR_STATE)
390
+ raise_teptris("edit: key not found");
391
+ else if (st == TEPTRIS_ERR_ALLOC)
392
+ rb_memerror();
393
+ else
394
+ raise_teptris("edit: malformed key path or replacement");
395
+ }
396
+ VALUE out = rb_str_new(buf, (long)out_len);
397
+ free(buf);
398
+ return out;
399
+ }
400
+
372
401
  /* ------------------------------------------------------------------ dump */
373
402
 
374
403
  static ID id_utc_offset, id_to_s, id_to_i, id_nsec;
@@ -1341,6 +1370,7 @@ void Init_teptris_ext(void) {
1341
1370
  rb_define_module_function(m, "dump_json_natural", ext_dump_json_natural,
1342
1371
  1);
1343
1372
  rb_define_module_function(m, "engine_version", ext_version, 0);
1373
+ rb_define_module_function(m, "edit", ext_edit, 3);
1344
1374
  rb_define_module_function(m, "plan_build", ext_plan_build, 2);
1345
1375
  rb_define_module_function(m, "plan_emit", ext_plan_emit, 2);
1346
1376
  /* error/version load first (teptris.rb), then the ext bundle */
Binary file
Binary file
Binary file
data/lib/teptris/toml.rb CHANGED
@@ -173,6 +173,17 @@ module Teptris::TOML
173
173
  TeptrisExt.engine_version
174
174
  end
175
175
 
176
+ # Format-preserving edit: rewrite exactly the value bytes of one
177
+ # key = value line; every other byte of the source survives
178
+ # (comments, blank lines, formatting, CRLF endings). key_path may
179
+ # carry a [table] prefix ("t.x" edits x inside [t]); replacement
180
+ # is the value's TEXT, validated by the engine. Returns the edited
181
+ # document as a String. Raises Teptris::Error on an absent key or
182
+ # a malformed span/replacement.
183
+ def edit(source, key_path, replacement)
184
+ TeptrisExt.edit(source, key_path, replacement)
185
+ end
186
+
176
187
  def load_file(path)
177
188
  load(File.read(path))
178
189
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Teptris
4
- VERSION = "0.3.14.0"
4
+ VERSION = "0.3.16.0"
5
5
  end
data/sig/teptris.rbs CHANGED
@@ -60,6 +60,10 @@ module Teptris
60
60
 
61
61
  def self.engine_version: () -> String
62
62
 
63
+ # Format-preserving edit: rewrite exactly the value bytes of one
64
+ # key = value line; every other byte of the source survives.
65
+ def self.edit: (String source, String key_path, String replacement) -> String
66
+
63
67
  def self._validate_batch!: (untyped input, untyped safe_load,
64
68
  :native | :string datetime_policy,
65
69
  ?kind: Symbol) -> void
@@ -139,6 +143,8 @@ module TeptrisExt
139
143
 
140
144
  def self.engine_version: () -> String
141
145
 
146
+ def self.edit: (String source, String key_path, String replacement) -> String
147
+
142
148
  def self.plan_build: (Array[[String, Integer, Integer]] rows,
143
149
  Array[Integer] first_row) -> untyped
144
150
 
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.14.0
4
+ version: 0.3.16.0
5
5
  platform: arm-linux
6
6
  authors:
7
7
  - teptris contributors