yeptris 0.6.18.2-arm-linux-eabihf

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.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/README.adoc +141 -0
  3. data/ext/build_windows_native.rb +41 -0
  4. data/ext/libyeptris/extconf.rb +57 -0
  5. data/ext/yeptris_native/cbor_ruby.c +193 -0
  6. data/ext/yeptris_native/extconf.rb +47 -0
  7. data/ext/yeptris_native/json_ruby.c +354 -0
  8. data/ext/yeptris_native/yeptris_native.c +497 -0
  9. data/lib/yeptris/cbor.rb +130 -0
  10. data/lib/yeptris/document.rb +255 -0
  11. data/lib/yeptris/ffi.rb +426 -0
  12. data/lib/yeptris/json/descriptor.rb +266 -0
  13. data/lib/yeptris/json.rb +394 -0
  14. data/lib/yeptris/materializer.rb +354 -0
  15. data/lib/yeptris/native-3.4.so +0 -0
  16. data/lib/yeptris/node.rb +453 -0
  17. data/lib/yeptris/psych/class_loader.rb +24 -0
  18. data/lib/yeptris/psych/coder_shim.rb +55 -0
  19. data/lib/yeptris/psych/drop_in.rb +63 -0
  20. data/lib/yeptris/psych/encodable.rb +14 -0
  21. data/lib/yeptris/psych/handler.rb +90 -0
  22. data/lib/yeptris/psych/parser.rb +105 -0
  23. data/lib/yeptris/psych/scalar_scanner.rb +149 -0
  24. data/lib/yeptris/psych/visitors.rb +545 -0
  25. data/lib/yeptris/psych.rb +622 -0
  26. data/lib/yeptris/schema.rb +253 -0
  27. data/lib/yeptris/valueml.rb +455 -0
  28. data/lib/yeptris/yaml/descriptor.rb +56 -0
  29. data/lib/yeptris/yaml.rb +422 -0
  30. data/lib/yeptris.rb +113 -0
  31. data/libyeptris.so +0 -0
  32. data/vendor/libyeptris/CMakeLists.txt +254 -0
  33. data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
  34. data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
  35. data/vendor/libyeptris/src/CMakeLists.txt +167 -0
  36. data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
  37. data/vendor/libyeptris/src/include/yeptris/cbor.h +101 -0
  38. data/vendor/libyeptris/src/include/yeptris/dom.h +190 -0
  39. data/vendor/libyeptris/src/include/yeptris/emit.h +81 -0
  40. data/vendor/libyeptris/src/include/yeptris/error.h +41 -0
  41. data/vendor/libyeptris/src/include/yeptris/events.h +157 -0
  42. data/vendor/libyeptris/src/include/yeptris/json.h +45 -0
  43. data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
  44. data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
  45. data/vendor/libyeptris/src/include/yeptris/marshal.h +52 -0
  46. data/vendor/libyeptris/src/include/yeptris/parse.h +48 -0
  47. data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
  48. data/vendor/libyeptris/src/include/yeptris/resolve.h +71 -0
  49. data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
  50. data/vendor/libyeptris/src/include/yeptris/tape.h +123 -0
  51. data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
  52. data/vendor/libyeptris/src/include/yeptris/values.h +102 -0
  53. data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
  54. data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
  55. data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
  56. data/vendor/libyeptris/src/include/yeptris.h +23 -0
  57. data/vendor/libyeptris/src/yeptris/build.c +376 -0
  58. data/vendor/libyeptris/src/yeptris/cbor/cbor.h +25 -0
  59. data/vendor/libyeptris/src/yeptris/cbor/decode.c +981 -0
  60. data/vendor/libyeptris/src/yeptris/cbor/encode.c +835 -0
  61. data/vendor/libyeptris/src/yeptris/cbor/sink.h +58 -0
  62. data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
  63. data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
  64. data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
  65. data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
  66. data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
  67. data/vendor/libyeptris/src/yeptris/common/error.h +79 -0
  68. data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
  69. data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
  70. data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
  71. data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
  72. data/vendor/libyeptris/src/yeptris/common/simd_text.c +49 -0
  73. data/vendor/libyeptris/src/yeptris/common/simd_text.h +295 -0
  74. data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +534 -0
  75. data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +662 -0
  76. data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +298 -0
  77. data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
  78. data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
  79. data/vendor/libyeptris/src/yeptris/doc.h +56 -0
  80. data/vendor/libyeptris/src/yeptris/dom/dom.c +1192 -0
  81. data/vendor/libyeptris/src/yeptris/dom/dom.h +312 -0
  82. data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
  83. data/vendor/libyeptris/src/yeptris/dom/mapindex.c +173 -0
  84. data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
  85. data/vendor/libyeptris/src/yeptris/dom/mutate.c +431 -0
  86. data/vendor/libyeptris/src/yeptris/emit/emit.c +434 -0
  87. data/vendor/libyeptris/src/yeptris/emit/float/api.h +38 -0
  88. data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
  89. data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +231 -0
  90. data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
  91. data/vendor/libyeptris/src/yeptris/emit/style.c +81 -0
  92. data/vendor/libyeptris/src/yeptris/emit/style.h +24 -0
  93. data/vendor/libyeptris/src/yeptris/emit/writer.c +816 -0
  94. data/vendor/libyeptris/src/yeptris/emit/writer.h +76 -0
  95. data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
  96. data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
  97. data/vendor/libyeptris/src/yeptris/encoding/transcode.c +148 -0
  98. data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
  99. data/vendor/libyeptris/src/yeptris/events/capture.c +150 -0
  100. data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
  101. data/vendor/libyeptris/src/yeptris/events/iterparse.c +208 -0
  102. data/vendor/libyeptris/src/yeptris/events/pull.c +97 -0
  103. data/vendor/libyeptris/src/yeptris/events/push.c +104 -0
  104. data/vendor/libyeptris/src/yeptris/events/recorder.c +107 -0
  105. data/vendor/libyeptris/src/yeptris/events/values.c +527 -0
  106. data/vendor/libyeptris/src/yeptris/events/values_priv.h +51 -0
  107. data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
  108. data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
  109. data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
  110. data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
  111. data/vendor/libyeptris/src/yeptris/marshal.c +782 -0
  112. data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
  113. data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
  114. data/vendor/libyeptris/src/yeptris/memory/arena.c +134 -0
  115. data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
  116. data/vendor/libyeptris/src/yeptris/memory/pool.c +122 -0
  117. data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
  118. data/vendor/libyeptris/src/yeptris/parse/engine.c +3698 -0
  119. data/vendor/libyeptris/src/yeptris/parse/engine.h +65 -0
  120. data/vendor/libyeptris/src/yeptris/parse/events.h +124 -0
  121. data/vendor/libyeptris/src/yeptris/parse/numbers.c +349 -0
  122. data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
  123. data/vendor/libyeptris/src/yeptris/parse/scalars.c +416 -0
  124. data/vendor/libyeptris/src/yeptris/parse/scalars.h +75 -0
  125. data/vendor/libyeptris/src/yeptris/parse.c +737 -0
  126. data/vendor/libyeptris/src/yeptris/plan.c +824 -0
  127. data/vendor/libyeptris/src/yeptris/resolve/compat11.c +334 -0
  128. data/vendor/libyeptris/src/yeptris/resolve/core12.c +143 -0
  129. data/vendor/libyeptris/src/yeptris/resolve/resolver.h +56 -0
  130. data/vendor/libyeptris/src/yeptris/resolve/tags.c +58 -0
  131. data/vendor/libyeptris/src/yeptris/scan/json.c +792 -0
  132. data/vendor/libyeptris/src/yeptris/scan/json.h +109 -0
  133. data/vendor/libyeptris/src/yeptris/scan/scan.c +463 -0
  134. data/vendor/libyeptris/src/yeptris/scan/scan.h +150 -0
  135. data/vendor/libyeptris/src/yeptris/schema.c +308 -0
  136. data/vendor/libyeptris/src/yeptris/tape.c +1308 -0
  137. data/vendor/libyeptris/src/yeptris/tape_in.h +19 -0
  138. data/vendor/libyeptris/src/yeptris/version.c +7 -0
  139. data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
  140. data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
  141. data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
  142. metadata +199 -0
@@ -0,0 +1,416 @@
1
+ /* scalars.c — finishing implementations. Escape truth declared here once. */
2
+
3
+ #include <string.h>
4
+
5
+ #include "scalars.h"
6
+
7
+ static char* yep_emit_cp(char* o, uint32_t cp) {
8
+ if (cp < 0x80) {
9
+ *o++ = (char)cp;
10
+ } else if (cp < 0x800) {
11
+ *o++ = (char)(0xC0 | (cp >> 6));
12
+ *o++ = (char)(0x80 | (cp & 0x3F));
13
+ } else if (cp < 0x10000) {
14
+ *o++ = (char)(0xE0 | (cp >> 12));
15
+ *o++ = (char)(0x80 | ((cp >> 6) & 0x3F));
16
+ *o++ = (char)(0x80 | (cp & 0x3F));
17
+ } else {
18
+ *o++ = (char)(0xF0 | (cp >> 18));
19
+ *o++ = (char)(0x80 | ((cp >> 12) & 0x3F));
20
+ *o++ = (char)(0x80 | ((cp >> 6) & 0x3F));
21
+ *o++ = (char)(0x80 | (cp & 0x3F));
22
+ }
23
+ return o;
24
+ }
25
+
26
+ /* Grows into the pool via a scratch buffer, returns final pool block. */
27
+ typedef struct yep_buf {
28
+ yep_pool* pool;
29
+ char* data;
30
+ size_t len, cap;
31
+ } yep_buf;
32
+
33
+ static int yep_buf_reserve(yep_buf* b, size_t need) {
34
+ if (b->len + need <= b->cap) {
35
+ return 1;
36
+ }
37
+ if (b->pool == NULL) {
38
+ return 0; /* fixed buffer: in-place decoding never exceeds cap */
39
+ }
40
+ size_t ncap = b->cap ? b->cap * 2 : 256;
41
+ while (ncap < b->len + need) {
42
+ ncap *= 2;
43
+ }
44
+ char* nd = yep_pool_alloc(b->pool, ncap, 16);
45
+ if (nd == NULL) {
46
+ return 0;
47
+ }
48
+ if (b->len > 0) {
49
+ memcpy(nd, b->data, b->len);
50
+ }
51
+ b->data = nd;
52
+ b->cap = ncap;
53
+ return 1;
54
+ }
55
+
56
+ static void yep_buf_putc(yep_buf* b, char c) {
57
+ if (yep_buf_reserve(b, 1)) {
58
+ b->data[b->len++] = c;
59
+ }
60
+ }
61
+
62
+ static void yep_buf_put(yep_buf* b, const char* s, size_t n) {
63
+ if (n && yep_buf_reserve(b, n)) {
64
+ memcpy(b->data + b->len, s, n);
65
+ b->len += n;
66
+ }
67
+ }
68
+
69
+ static uint32_t finish_double_body(const char* p, uint32_t start, uint32_t end, int multiline,
70
+ yep_buf* b);
71
+
72
+ char* yep_finish_double(const char* p, uint32_t start, uint32_t end, int multiline, yep_pool* pool,
73
+ uint32_t* out_len) {
74
+ yep_buf b = {pool, NULL, 0, 0};
75
+ *out_len = finish_double_body(p, start, end, multiline, &b);
76
+ return b.data;
77
+ }
78
+
79
+ /* Decodes into a caller buffer (no pool): decoding only shrinks, so
80
+ * cap = the raw span is a hard bound. Returns the decoded length. */
81
+ uint32_t yep_finish_double_into(const char* p, uint32_t start, uint32_t end, char* dst,
82
+ uint32_t cap) {
83
+ yep_buf b = {NULL, dst, 0, cap};
84
+ return finish_double_body(p, start, end, 0, &b);
85
+ }
86
+
87
+ static uint32_t finish_double_body(const char* p, uint32_t start, uint32_t end, int multiline,
88
+ yep_buf* b) {
89
+ size_t esc_floor = 0; /* decoded bytes below this are escape content */
90
+ size_t i = start;
91
+ while (i < end) {
92
+ unsigned char c = (unsigned char)p[i];
93
+ if (c != '\\') {
94
+ if (multiline && (c == '\n' || c == '\r')) {
95
+ /* fold: one break → ' ', n → (n-1) '\n'. Trailing
96
+ * whitespace BEFORE a break is stripped; the next line's
97
+ * leading whitespace (spaces AND tabs) is skipped; a
98
+ * whitespace-ONLY line counts as an empty line. */
99
+ uint32_t breaks = 0;
100
+ for (;;) {
101
+ while (i < end && (p[i] == '\n' || p[i] == '\r')) {
102
+ if (p[i] == '\r' && i + 1 < end && p[i + 1] == '\n') {
103
+ i++;
104
+ }
105
+ i++;
106
+ breaks++;
107
+ }
108
+ size_t save = i;
109
+ while (i < end && (p[i] == ' ' || p[i] == '\t')) {
110
+ i++;
111
+ }
112
+ if (i < end && (p[i] == '\n' || p[i] == '\r') && i > save) {
113
+ continue; /* whitespace-only line: keep counting */
114
+ }
115
+ break;
116
+ }
117
+ while (b->len > esc_floor &&
118
+ (b->data[b->len - 1] == ' ' || b->data[b->len - 1] == '\t')) {
119
+ b->len--; /* raw trailing white space strips; escapes keep */
120
+ }
121
+ if (breaks == 1) {
122
+ yep_buf_putc(b, ' ');
123
+ } else {
124
+ for (uint32_t k = 1; k < breaks; k++) {
125
+ yep_buf_putc(b, '\n');
126
+ }
127
+ }
128
+ continue;
129
+ }
130
+ yep_buf_putc(b, (char)c);
131
+ i++;
132
+ continue;
133
+ }
134
+ /* escape */
135
+ i++;
136
+ if (i >= end) {
137
+ break; /* trailing backslash before closing quote — treated literally */
138
+ }
139
+ unsigned char e = (unsigned char)p[i];
140
+ switch (e) {
141
+ case '0':
142
+ yep_buf_putc(b, '\0');
143
+ i++;
144
+ break;
145
+ case 'a':
146
+ yep_buf_putc(b, '\a');
147
+ i++;
148
+ break;
149
+ case 'b':
150
+ yep_buf_putc(b, '\b');
151
+ i++;
152
+ break;
153
+ case 't':
154
+ case '\t':
155
+ yep_buf_putc(b, '\t');
156
+ i++;
157
+ break;
158
+ case 'n':
159
+ yep_buf_putc(b, '\n');
160
+ i++;
161
+ break;
162
+ case 'v':
163
+ yep_buf_putc(b, '\v');
164
+ i++;
165
+ break;
166
+ case 'f':
167
+ yep_buf_putc(b, '\f');
168
+ i++;
169
+ break;
170
+ case 'r':
171
+ yep_buf_putc(b, '\r');
172
+ i++;
173
+ break;
174
+ case 'e':
175
+ yep_buf_putc(b, 0x1B);
176
+ i++;
177
+ break;
178
+ case ' ':
179
+ yep_buf_putc(b, ' ');
180
+ i++;
181
+ break;
182
+ case '"':
183
+ yep_buf_putc(b, '"');
184
+ i++;
185
+ break;
186
+ case '/':
187
+ yep_buf_putc(b, '/');
188
+ i++;
189
+ break;
190
+ case '\\':
191
+ yep_buf_putc(b, '\\');
192
+ i++;
193
+ break;
194
+ case 'N': /* U+0085 NEL */ {
195
+ char tmp[2] = {(char)(unsigned char)0xC2, (char)(unsigned char)0x85};
196
+ yep_buf_put(b, tmp, 2);
197
+ i++;
198
+ break;
199
+ }
200
+ case '_': /* U+00A0 */ {
201
+ char tmp[2] = {(char)(unsigned char)0xC2, (char)(unsigned char)0xA0};
202
+ yep_buf_put(b, tmp, 2);
203
+ i++;
204
+ break;
205
+ }
206
+ case 'L': /* U+2028 */ {
207
+ char tmp[3] = {(char)(unsigned char)0xE2, (char)(unsigned char)0x80,
208
+ (char)(unsigned char)0xA8};
209
+ yep_buf_put(b, tmp, 3);
210
+ i++;
211
+ break;
212
+ }
213
+ case 'P': /* U+2029 */ {
214
+ char tmp[3] = {(char)(unsigned char)0xE2, (char)(unsigned char)0x80,
215
+ (char)(unsigned char)0xA9};
216
+ yep_buf_put(b, tmp, 3);
217
+ i++;
218
+ break;
219
+ }
220
+ case 'x':
221
+ case 'u':
222
+ case 'U': {
223
+ int digits = (e == 'x') ? 2 : (e == 'u') ? 4 : 8;
224
+ uint32_t cp = 0;
225
+ int ok = 1;
226
+ for (int k = 0; k < digits; k++) {
227
+ int hv =
228
+ (i + 1 + (size_t)k < end) ? hexval((unsigned char)p[i + 1 + (size_t)k]) : -1;
229
+ if (hv < 0) {
230
+ ok = 0;
231
+ break;
232
+ }
233
+ cp = (cp << 4) | (uint32_t)hv;
234
+ }
235
+ if (!ok) {
236
+ yep_buf_putc(b, '\\');
237
+ yep_buf_putc(b, (char)e);
238
+ i++;
239
+ break;
240
+ }
241
+ if (e == 'u' && cp >= 0xD800 && cp <= 0xDBFF && i + 1 + 4 + 6 <= end &&
242
+ p[i + 1 + 4] == '\\' && p[i + 2 + 4] == 'u') {
243
+ /* surrogate pair: combine into one scalar */
244
+ uint32_t lo = 0;
245
+ int lok = 1;
246
+ for (int k = 0; k < 4; k++) {
247
+ int hv2 = hexval((unsigned char)p[i + 3 + 4 + (size_t)k]);
248
+ if (hv2 < 0) {
249
+ lok = 0;
250
+ break;
251
+ }
252
+ lo = (lo << 4) | (uint32_t)hv2;
253
+ }
254
+ if (lok && lo >= 0xDC00 && lo <= 0xDFFF) {
255
+ cp = 0x10000 + ((cp - 0xD800) << 10) + (lo - 0xDC00);
256
+ i += 6; /* the low escape's "\u" */
257
+ }
258
+ }
259
+ if (cp >= 0xD800 && cp <= 0xDFFF) {
260
+ /* lone surrogate: validators reject; decode defensively */
261
+ cp = 0xFFFD;
262
+ }
263
+ char tmp[4];
264
+ char* o = yep_emit_cp(tmp, cp);
265
+ yep_buf_put(b, tmp, (size_t)(o - tmp));
266
+ i += 1 + (size_t)digits;
267
+ break;
268
+ }
269
+ case '\n':
270
+ case '\r': {
271
+ /* line continuation: swallow the break and next line's leading spaces */
272
+ size_t j = i;
273
+ if (p[j] == '\r' && j + 1 < end && p[j + 1] == '\n') {
274
+ j++;
275
+ }
276
+ j++;
277
+ while (j < end && (p[j] == ' ' || p[j] == '\t')) {
278
+ j++;
279
+ }
280
+ i = j;
281
+ break;
282
+ }
283
+ default:
284
+ /* unknown escape: keep verbatim */
285
+ yep_buf_putc(b, '\\');
286
+ yep_buf_putc(b, (char)e);
287
+ i++;
288
+ break;
289
+ }
290
+ esc_floor = b->len; /* decoded content is never strippable */
291
+ }
292
+ return (uint32_t)b->len;
293
+ }
294
+
295
+ char* yep_finish_single(const char* p, uint32_t start, uint32_t end, int multiline, yep_pool* pool,
296
+ uint32_t* out_len) {
297
+ /* Count '' occurrences and breaks to decide necessity. */
298
+ int changed = 0;
299
+ for (size_t i = start; i + 1 < end; i++) {
300
+ if (p[i] == '\'' && p[i + 1] == '\'') {
301
+ changed = 1;
302
+ break;
303
+ }
304
+ }
305
+ if (!changed && !multiline) {
306
+ return NULL; /* borrow: content already final */
307
+ }
308
+
309
+ yep_buf b = {pool, NULL, 0, 0};
310
+ size_t i = start;
311
+ while (i < end) {
312
+ if (p[i] == '\'' && i + 1 < end && p[i + 1] == '\'') {
313
+ yep_buf_putc(&b, '\'');
314
+ i += 2;
315
+ continue;
316
+ }
317
+ if (multiline && (p[i] == '\n' || p[i] == '\r')) {
318
+ uint32_t breaks = 0;
319
+ for (;;) {
320
+ while (i < end && (p[i] == '\n' || p[i] == '\r')) {
321
+ if (p[i] == '\r' && i + 1 < end && p[i + 1] == '\n') {
322
+ i++;
323
+ }
324
+ i++;
325
+ breaks++;
326
+ }
327
+ size_t save = i;
328
+ while (i < end && (p[i] == ' ' || p[i] == '\t')) {
329
+ i++;
330
+ }
331
+ if (i < end && (p[i] == '\n' || p[i] == '\r') && i > save) {
332
+ continue; /* whitespace-only line: keep counting */
333
+ }
334
+ break;
335
+ }
336
+ while (b.len > 0 && (b.data[b.len - 1] == ' ' || b.data[b.len - 1] == '\t')) {
337
+ b.len--; /* trailing white space strips before breaks */
338
+ }
339
+ if (breaks == 1) {
340
+ yep_buf_putc(&b, ' ');
341
+ } else {
342
+ for (uint32_t k = 1; k < breaks; k++) {
343
+ yep_buf_putc(&b, '\n');
344
+ }
345
+ }
346
+ continue;
347
+ }
348
+ yep_buf_putc(&b, p[i]);
349
+ i++;
350
+ }
351
+ *out_len = (uint32_t)b.len;
352
+ return b.data;
353
+ }
354
+
355
+ static void yep_emit_breaks(yep_buf* b, uint32_t n) {
356
+ for (uint32_t k = 0; k < n; k++) {
357
+ yep_buf_putc(b, '\n');
358
+ }
359
+ }
360
+
361
+ /* Plain folding: 0 breaks → nothing, 1 break → ' ', n>1 → (n-1) '\n'. */
362
+ static void yep_fold_break(yep_buf* b, uint32_t breaks) {
363
+ if (breaks == 0) {
364
+ return;
365
+ }
366
+ if (breaks == 1) {
367
+ yep_buf_putc(b, ' ');
368
+ } else {
369
+ yep_emit_breaks(b, breaks - 1);
370
+ }
371
+ }
372
+
373
+ char* yep_fold_plain(const yep_fold_line* lines, size_t n, yep_pool* pool, uint32_t* out_len) {
374
+ yep_buf b = {pool, NULL, 0, 0};
375
+ for (size_t i = 0; i < n; i++) {
376
+ yep_fold_break(&b, lines[i].breaks_before);
377
+ yep_buf_put(&b, lines[i].content.p, lines[i].content.len);
378
+ }
379
+ *out_len = (uint32_t)b.len;
380
+ return b.data;
381
+ }
382
+
383
+ char* yep_finish_block(const yep_fold_line* lines, size_t n, int folded, int chomp,
384
+ uint32_t trailing_breaks, yep_pool* pool, uint32_t* out_len) {
385
+ yep_buf b = {pool, NULL, 0, 0};
386
+ for (size_t i = 0; i < n; i++) {
387
+ uint32_t br = lines[i].breaks_before;
388
+ if (!folded) {
389
+ yep_emit_breaks(&b, br); /* literal: every break is a newline */
390
+ } else {
391
+ /* folded: plain-fold, unless a more-indented neighbor forces
392
+ * every break to be kept literally. LEADING breaks (before
393
+ * the first content line) have no preceding content to fold
394
+ * against — they emit literally. */
395
+ int keep = lines[i].more_indented || (i > 0 && lines[i - 1].more_indented);
396
+ if (keep || i == 0) {
397
+ yep_emit_breaks(&b, br);
398
+ } else {
399
+ yep_fold_break(&b, br);
400
+ }
401
+ }
402
+ yep_buf_put(&b, lines[i].content.p, lines[i].content.len);
403
+ }
404
+
405
+ /* Chomping. */
406
+ if (chomp == 1) { /* strip: nothing */
407
+ } else if (chomp == 2) { /* keep: every trailing break */
408
+ yep_emit_breaks(&b, trailing_breaks);
409
+ } else { /* clip: one trailing newline, but nothing without content */
410
+ if (b.len > 0) {
411
+ yep_buf_putc(&b, '\n');
412
+ }
413
+ }
414
+ *out_len = (uint32_t)b.len;
415
+ return b.data;
416
+ }
@@ -0,0 +1,75 @@
1
+ /* scalars.h — scalar finishing (TODO.impl/09): raw spans → final content.
2
+ *
3
+ * Copy policy: single-line plain and clean single-quoted scalars stay
4
+ * borrowed views (the ENGINE decides; nothing here allocates for them).
5
+ * Everything that changes bytes (escapes, folding, block content) is
6
+ * assembled into the engine's finish pool. Escape truth is declared here
7
+ * ONCE; the emitter (13) imports these tables.
8
+ */
9
+ #ifndef YEP_SCALARS_H
10
+ #define YEP_SCALARS_H
11
+
12
+ #include <stddef.h>
13
+ #include <yeptris/api.h>
14
+
15
+ #include "common/string_view.h"
16
+ #include "memory/pool.h"
17
+
18
+ #ifdef __cplusplus
19
+ extern "C" {
20
+ #endif
21
+
22
+ /* Finishes a double-quoted content span: escape sequences (\n \t \\ \" \x
23
+ * \u \U …), backslash-at-EOL continuation, and multi-line folding.
24
+ * Returns a pool-owned buffer of out_len bytes. */
25
+ char* yep_finish_double(const char* p, uint32_t start, uint32_t end, int multiline, yep_pool* pool,
26
+ uint32_t* out_len);
27
+
28
+ /* In-place variant for fixed buffers (JSON builder's arena path):
29
+ * cap = the raw span bounds the output; returns the decoded length. */
30
+ YEPTRIS_API uint32_t yep_finish_double_into(const char* p, uint32_t start, uint32_t end, char* dst,
31
+ uint32_t cap);
32
+
33
+ /* Finishes a single-quoted content span: '' → ' '; multi-line folding.
34
+ * Returns a pool-owned buffer, or NULL when nothing changed (borrow ok). */
35
+ char* yep_finish_single(const char* p, uint32_t start, uint32_t end, int multiline, yep_pool* pool,
36
+ uint32_t* out_len);
37
+
38
+ /* One content line of a multi-line plain scalar or folded block scalar. */
39
+ typedef struct yep_fold_line {
40
+ yep_view content; /* trimmed line content (may be empty for blanks) */
41
+ uint32_t breaks_before; /* line breaks between the previous content line and this one */
42
+ int more_indented; /* folded blocks: line is more indented than the block indent */
43
+ } yep_fold_line;
44
+
45
+ /* Plain-scalar folding: 1 break → ' ', n>1 breaks → (n-1) '\n'.
46
+ * Empty-content lines contribute only their breaks. */
47
+ char* yep_fold_plain(const yep_fold_line* lines, size_t n, yep_pool* pool, uint32_t* out_len);
48
+
49
+ /* Block scalar assembly. folded=0 literal (every break is '\n'), else
50
+ * folded (plain-fold rules; breaks around more-indented lines stay '\n').
51
+ * chomp: 0 clip (single trailing '\n'), 1 strip, 2 keep (all
52
+ * trailing_breaks newlines). trailing_breaks = breaks after the last
53
+ * content line. */
54
+ char* yep_finish_block(const yep_fold_line* lines, size_t n, int folded, int chomp,
55
+ uint32_t trailing_breaks, yep_pool* pool, uint32_t* out_len);
56
+
57
+ #ifdef __cplusplus
58
+ }
59
+ #endif
60
+
61
+ /* hex digit to value, -1 when not hex (escape truth lives here) */
62
+ static inline int hexval(unsigned char c) {
63
+ if (c >= '0' && c <= '9') {
64
+ return c - '0';
65
+ }
66
+ if (c >= 'a' && c <= 'f') {
67
+ return c - 'a' + 10;
68
+ }
69
+ if (c >= 'A' && c <= 'F') {
70
+ return c - 'A' + 10;
71
+ }
72
+ return -1;
73
+ }
74
+
75
+ #endif /* YEP_SCALARS_H */