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

Function normalise

internal/cbm/doc_pdf.c:176–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176static bool normalise(const char *s, size_t n, u32v_t *out) {
177 size_t i = 0;
178 while (i < n) {
179 unsigned char c = (unsigned char)s[i];
180 uint32_t cp = c;
181 size_t k = 1;
182 if (c >= 0xF0 && i + 3 < n) {
183 cp = ((uint32_t)(c & 0x07) << 18) | ((uint32_t)(s[i + 1] & 0x3F) << 12) |
184 ((uint32_t)(s[i + 2] & 0x3F) << 6) | (uint32_t)(s[i + 3] & 0x3F);
185 k = 4;
186 } else if (c >= 0xE0 && i + 2 < n) {
187 cp = ((uint32_t)(c & 0x0F) << 12) | ((uint32_t)(s[i + 1] & 0x3F) << 6) |
188 (uint32_t)(s[i + 2] & 0x3F);
189 k = 3;
190 } else if (c >= 0xC0 && i + 1 < n) {
191 cp = ((uint32_t)(c & 0x1F) << 6) | (uint32_t)(s[i + 1] & 0x3F);
192 k = 2;
193 }
194 i += k;
195 const pdf_nfkc_t *m = nfkc_find(cp);
196 int cnt = m ? m->len : 1;
197 for (int j = 0; j < cnt; j++) {
198 uint32_t x = m ? PDF_NFKC_SEQ[m->off + j] : cp;
199 uint32_t comp;
200 if (out->n > 0 && ucomp(out->v[out->n - 1], x, &comp)) {
201 out->v[out->n - 1] = comp;
202 } else if (!u32_push(out, x)) {
203 return false;
204 }
205 }
206 }
207 /* zero-width characters out; U+2010/U+2011 -> '-' */
208 int k = 0;
209 for (int j = 0; j < out->n; j++) {
210 uint32_t x = out->v[j];
211 if (x == 0x200B || x == 0x200C || x == 0x200D || x == 0x2060 || x == 0xFEFF) {
212 continue;
213 }
214 if (x == 0x2010 || x == 0x2011) {
215 x = '-';
216 }
217 out->v[k++] = x;
218 }
219 out->n = k;
220 return true;
221}
222
223/* ── Character classes of the field test's regexes ───────────────── */
224

Callers 1

scan_pageFunction · 0.70

Calls 3

nfkc_findFunction · 0.85
ucompFunction · 0.85
u32_pushFunction · 0.85

Tested by

no test coverage detected