- sv_recode_to_utf8(sv, PL_encoding);
- }
- }
-
- s = SvPV(sv, len);
- if (s && len) {
- s += --len;
- if (RsPARA(PL_rs)) {
- if (*s != '\n')
- goto nope;
- ++count;
- while (len && s[-1] == '\n') {
- --len;
- --s;
- ++count;
- }
- }
- else {
- STRLEN rslen, rs_charlen;
- char *rsptr = SvPV(PL_rs, rslen);
-
- rs_charlen = SvUTF8(PL_rs)
- ? sv_len_utf8(PL_rs)
- : rslen;
-
- if (SvUTF8(PL_rs) != SvUTF8(sv)) {
- /* Assumption is that rs is shorter than the scalar. */
- if (SvUTF8(PL_rs)) {
- /* RS is utf8, scalar is 8 bit. */
- bool is_utf8 = TRUE;
- temp_buffer = (char*)bytes_from_utf8((U8*)rsptr,
- &rslen, &is_utf8);
- if (is_utf8) {
- /* Cannot downgrade, therefore cannot possibly match
- */
- assert (temp_buffer == rsptr);
- temp_buffer = NULL;
- goto nope;
- }
- rsptr = temp_buffer;
- }
- else if (PL_encoding) {
- /* RS is 8 bit, encoding.pm is used.
- * Do not recode PL_rs as a side-effect. */
- svrecode = newSVpvn(rsptr, rslen);
- sv_recode_to_utf8(svrecode, PL_encoding);
- rsptr = SvPV(svrecode, rslen);
- rs_charlen = sv_len_utf8(svrecode);
- }
- else {
- /* RS is 8 bit, scalar is utf8. */
- temp_buffer = (char*)bytes_to_utf8((U8*)rsptr, &rslen);
- rsptr = temp_buffer;
- }
- }
- if (rslen == 1) {
- if (*s != *rsptr)
- goto nope;
- ++count;
- }
- else {
- if (len < rslen - 1)
- goto nope;
- len -= rslen - 1;
- s -= rslen - 1;
- if (memNE(s, rsptr, rslen))
- goto nope;
- count += rs_charlen;
- }
- }
- s = SvPV_force(sv, n_a);
- SvCUR_set(sv, len);
- *SvEND(sv) = '\0';
- SvNIOK_off(sv);
- SvSETMAGIC(sv);
- }
- nope:
-
- if (svrecode)
- SvREFCNT_dec(svrecode);
-
- Safefree(temp_buffer);
- return count;
-}
-
-void
-Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
-{
-#ifdef LIBERAL
- register long *dl;
- register long *ll;
- register long *rl;
-#endif
- register char *dc;
- STRLEN leftlen;
- STRLEN rightlen;
- register const char *lc;
- register const char *rc;
- register I32 len;
- I32 lensave;
- const char *lsave;
- const char *rsave;
- const bool left_utf = DO_UTF8(left);
- const bool right_utf = DO_UTF8(right);
- I32 needlen = 0;
-
- if (left_utf && !right_utf)