sv.c
/* Given the length of the string in both bytes and UTF-8 characters, decide
   whether to walk forwards or backwards to find the byte corresponding to
   the passed in UTF-8 offset.  */
Given the length of the string in both bytes and UTF-8 characters, decide
whether to walk forwards or backwards to find the byte corresponding to
the passed in UTF-8 offset.
Given the length of the string in both bytes and UTF - 8 characters decide whether to walk forwards or backwards to find the byte corresponding to the passed in UTF - 8 offset .
static STRLEN
S_sv_pos_u2b_midway(const U8 *const start, const U8 *send,
		    STRLEN uoffset, const STRLEN uend)
{
    STRLEN backw = uend - uoffset;
    PERL_ARGS_ASSERT_SV_POS_U2B_MIDWAY;
    if (uoffset < 2 * backw) {
	const U8 *s = start;
	while (s < send && uoffset--)
	    s += UTF8SKIP(s);
	assert (s <= send);
	if (s > send)
	    s = send;
	return s - start;
    }
    while (backw--) {
	send--;
	while (UTF8_IS_CONTINUATION(*send))
	    send--;
    }
    return send - start;
}
static STRLEN S_sv_pos_u2b_midway ( const U8 * const start , const U8 * send , STRLEN uoffset , const STRLEN uend ) { STRLEN backw = uend - uoffset ; PERL_ARGS_ASSERT_SV_POS_U2B_MIDWAY ; if ( uoffset < 2 * backw ) { const U8 * s = start ; while ( s < send && uoffset -- ) s += UTF8SKIP ( s ) ; assert ( s <= send ) ; if ( s > send ) s = send ; return s - start ; } while ( backw -- ) { send -- ; while ( UTF8_IS_CONTINUATION ( * send ) ) send -- ; } return send - start ; }
Given the length of the string in both bytes and UTF-8 characters, decide
whether to walk forwards or backwards to find the byte corresponding to
the passed in UTF-8 offset.
Given the length of the string in both bytes and UTF - 8 characters decide whether to walk forwards or backwards to find the byte corresponding to the passed in UTF - 8 offset .
/* The assumption is that going forwards is twice the speed of going
	   forward (that's where the 2 * backw comes from).
	   (The real figure of course depends on the UTF-8 data.)  */