summaryrefslogtreecommitdiff
path: root/toke.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2009-10-18 17:47:10 +0100
committerNicholas Clark <nick@ccl4.org>2009-10-18 17:48:10 +0100
commitaa6dbd607b0a3d8a49c43b63b63b73ed167692c3 (patch)
tree3cf8643685843540f492da953c36011c0d401152 /toke.c
parent161735889e3f206d41ba19c0a094a7e55e577462 (diff)
downloadperl-aa6dbd607b0a3d8a49c43b63b63b73ed167692c3.tar.gz
Merge S_utf16_textfilter and S_utf16rev_textfilter().
Use IoLINES() on the filter's SV to determine which encoding is in use.
Diffstat (limited to 'toke.c')
-rw-r--r--toke.c42
1 files changed, 15 insertions, 27 deletions
diff --git a/toke.c b/toke.c
index 8e47c9af4d..c7ec476b6d 100644
--- a/toke.c
+++ b/toke.c
@@ -12708,7 +12708,7 @@ S_swallow_bom(pTHX_ U8 *s)
U8 *news;
I32 newlen;
- filter_add(S_utf16rev_textfilter, NULL);
+ IoLINES(filter_add(S_utf16_textfilter, NULL)) = 1;
Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
utf16_to_utf8_reversed(s, news,
PL_bufend - (char*)s - 1,
@@ -12810,8 +12810,10 @@ S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
dVAR;
const STRLEN old = SvCUR(sv);
const I32 count = FILTER_READ(idx+1, sv, maxlen);
+ const int reverse = IoLINES(sv);
DEBUG_P(PerlIO_printf(Perl_debug_log,
- "utf16_textfilter(%p): %d %d (%d)\n",
+ "utf16%s_textfilter(%p): %d %d (%d)\n",
+ reverse ? "rev" : "",
FPTR2DPTR(void *, S_utf16_textfilter),
idx, maxlen, (int) count));
if (count) {
@@ -12819,36 +12821,22 @@ S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
I32 newlen;
Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
Copy(SvPVX_const(sv), tmps, old, char);
- utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
- SvCUR(sv) - old, &newlen);
+ if (reverse) {
+ /* You would expect this to be utf16_to_utf8_reversed()
+ It was, prior to 1de9afcdf18cf98bbdecaa782da93e907be6fe4e
+ Effectively, right now, UTF-16LE is being read in off-by-one
+ See RT #69678 */
+ utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
+ SvCUR(sv) - old, &newlen);
+ } else {
+ utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
+ SvCUR(sv) - old, &newlen);
+ }
sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
}
DEBUG_P({sv_dump(sv);});
return SvCUR(sv);
}
-
-static I32
-S_utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
-{
- dVAR;
- const STRLEN old = SvCUR(sv);
- const I32 count = FILTER_READ(idx+1, sv, maxlen);
- DEBUG_P(PerlIO_printf(Perl_debug_log,
- "utf16rev_textfilter(%p): %d %d (%d)\n",
- FPTR2DPTR(void *, utf16rev_textfilter),
- idx, maxlen, (int) count));
- if (count) {
- U8* tmps;
- I32 newlen;
- Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
- Copy(SvPVX_const(sv), tmps, old, char);
- utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
- SvCUR(sv) - old, &newlen);
- sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
- }
- DEBUG_P({ sv_dump(sv); });
- return count;
-}
#endif
/*