Skip to content
Myr

Use codepoint index for indices/1, index/ 1 and rindex/1 (#3065)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Previsouly byte index was used. Fixes #1430 #1624 #3064

authored by Mattias Wadman · committed by GitHub · parent a7b2253 · Browse files · 2 files+25 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+25 added−3 removed

  • tests:+16 added−0 removed
  • other:+9 added−3 removed

2 files+25 added−3 removed

modified:src/jv.c+9 added-3 removed
1271 unmodified lines
1272 assert(JVP_HAS_KIND(j, JV_KIND_STRING));1273 assert(JVP_HAS_KIND(k, JV_KIND_STRING));1274 const char *jstr = jv_string_value(j);1275 const char *idxstr = jv_string_value(k);1276 const char *p;1276 const char *p, *lp;1277 int jlen = jv_string_length_bytes(jv_copy(j));1278 int idxlen = jv_string_length_bytes(jv_copy(k));1279 jv a = jv_array();12801281 if (idxlen != 0) {1282 int n = 0;1282 p = jstr;1283 p = lp = jstr;1284 while ((p = _jq_memmem(p, (jstr + jlen) - p, idxstr, idxlen)) != NULL) {1285 while (lp < p) {1286 lp += jvp_utf8_decode_length(*lp);1287 n++;1288 }12891284 a = jv_array_append(a, jv_number(p - jstr));1290 a = jv_array_append(a, jv_number(n));1291 p++;1292 }1293 }1294 jv_free(j);
689 unmodified lines
modified:tests/jq.test+16 added
1414 unmodified lines
1415indices(", ")1416"a,b, cd,e, fgh, ijkl"1417[3,9,14]14181419index("!")1420"здравствуй мир!"14211414221423.[:rindex("x")]1424"正xyz"1425"正"14261427indices("o")1428"🇬🇧oo"1429[2,3]14301431indices("o")1432"ƒoo"1433[1,2]14341435[.[]|split(",")]1436["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]1437[["a"," bc"," def"," ghij"," jklmn"," a","b"," c","d"," e","f"],["a","b","c","d"," e","f","g","h"]]1438
809 unmodified lines