Skip to content

Commit

Permalink
sv_pos_2ub_forwards: Replace rolled-own with utf8_hop
Browse files Browse the repository at this point in the history
  • Loading branch information
khwilliamson committed Nov 5, 2024
1 parent a67a651 commit b739b6e
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -7491,23 +7491,16 @@ S_sv_pos_u2b_forwards(const U8 *const start, const U8 *const send,

PERL_ARGS_ASSERT_SV_POS_U2B_FORWARDS;

while (s < send && uoffset) {
--uoffset;
s += UTF8SKIP(s);
}
if (s == send) {
*at_end = TRUE;
}
else if (s > send) {
SSize_t overshoot;
s = utf8_hop_forward_overshoot(s, uoffset, send, &overshoot);
if (s >= send) {
*at_end = TRUE;
/* This is the existing behaviour. Possibly it should be a croak, as
it's actually a bounds error */
s = send;
}

/* If the unicode position is beyond the end, we return the end but
shouldn't cache that position */
*canonical_position = (uoffset == 0);
*uoffset_p -= uoffset;
*canonical_position = ! overshoot;
*uoffset_p -= overshoot;
return s - start;
}

Expand Down

0 comments on commit b739b6e

Please sign in to comment.