in src/couch_quickjs/quickjs/libunicode.c [462:512]
int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,
const uint32_t *b_pt, int b_len, int op)
{
int a_idx, b_idx, is_in;
uint32_t v;
a_idx = 0;
b_idx = 0;
for(;;) {
/* get one more point from a or b in increasing order */
if (a_idx < a_len && b_idx < b_len) {
if (a_pt[a_idx] < b_pt[b_idx]) {
goto a_add;
} else if (a_pt[a_idx] == b_pt[b_idx]) {
v = a_pt[a_idx];
a_idx++;
b_idx++;
} else {
goto b_add;
}
} else if (a_idx < a_len) {
a_add:
v = a_pt[a_idx++];
} else if (b_idx < b_len) {
b_add:
v = b_pt[b_idx++];
} else {
break;
}
/* add the point if the in/out status changes */
switch(op) {
case CR_OP_UNION:
is_in = (a_idx & 1) | (b_idx & 1);
break;
case CR_OP_INTER:
is_in = (a_idx & 1) & (b_idx & 1);
break;
case CR_OP_XOR:
is_in = (a_idx & 1) ^ (b_idx & 1);
break;
default:
abort();
}
if (is_in != (cr->len & 1)) {
if (cr_add_point(cr, v))
return -1;
}
}
cr_compress(cr);
return 0;
}