ShiftJIS-String
view release on metacpan or search on metacpan
for (p = s; p < e; p += ch) {
ch = Is_SJ2BTp(p,e) ? 2 : 1;
if (!Is_SJ_SPACEpc(p,ch))
break;
}
for (anc = p; (lim <= 0 || cnt < lim - 1) && p < e; p += ch) {
ch = Is_SJ2BTp(p,e) ? 2 : 1;
if (Is_SJ_SPACEpc(p,ch)) {
if (anc != p) {
++cnt;
if (wantarray)
XPUSHs(sv_2mortal(newSVpvn((char*)anc, p - anc)));
}
anc = p + ch;
}
}
for (; p < e; p += ch) {
ch = Is_SJ2BTp(p,e) ? 2 : 1;
if (!Is_SJ_SPACEpc(p,ch))
break;
anc = p + ch;
}
if (!(lim == 0 && e == anc)) {
++cnt;
if (wantarray)
XPUSHs(sv_2mortal(newSVpvn((char*)anc, e - anc)));
}
if (!wantarray)
XPUSHs(sv_2mortal(newSViv(cnt)));
} /* end-splitspace */
else { /* other than splitspace */
sep = (U8*)SvPV(separator, sepbyte);
if (!sepbyte) { /* splitchar */
if (wantarray)
EXTEND(SP, lim <= 0 ? length(s,byte) : lim);
for (p = s, e = s + byte, cnt = 0;
(lim <= 0 || cnt < lim - 1) && p < e; cnt++)
{
ch = Is_SJ2BTp(p,e) ? 2 : 1;
if (wantarray)
PUSHs(sv_2mortal(newSVpvn((char*)p, ch)));
p += ch;
}
if (p < e || lim < 0) {
++cnt;
if (wantarray)
XPUSHs(sv_2mortal(newSVpvn((char*)p, e - p)));
}
if (!wantarray)
XPUSHs(sv_2mortal(newSViv(cnt)));
} /* end splitchar */
else { /* strsplit main */
I32 numLastEmpty = 0;
cnt = 0;
p = anc = s;
e = s + byte;
if (sepbyte <= byte) {
last = e - (sepbyte - 1); /* sepbyte after p */
while ((lim <= 0 || cnt < lim - 1) && p < last) {
if (*p == *sep && (sepbyte == 1 || memEQ(p,sep,sepbyte))) {
if (lim == 0 && p == anc)
++numLastEmpty;
else {
if (0 < numLastEmpty) {
cnt += numLastEmpty;
if (wantarray)
while (numLastEmpty--)
XPUSHs(sv_2mortal(newSVpvn("",0)));
numLastEmpty = 0;
}
++cnt;
if (wantarray)
XPUSHs(sv_2mortal(newSVpvn((char*)anc,p-anc)));
}
p += sepbyte;
anc = p;
}
else
p += Is_SJ2BTp(p,e) ? 2 : 1;
} /* end-while */
if (0 < numLastEmpty && !(lim == 0 && e == anc)) {
cnt += numLastEmpty;
if (wantarray)
while (numLastEmpty--)
XPUSHs(sv_2mortal(newSVpvn("",0)));
numLastEmpty = 0;
}
} /* sepbyte <= byte */
if (!(lim == 0 && e == anc)) {
++cnt;
if (wantarray)
XPUSHs(sv_2mortal(newSVpvn((char*)anc, e - anc)));
}
if (!wantarray)
XPUSHs(sv_2mortal(newSViv(cnt)));
} /* end strsplit main */
}
SV*
strxfrm(src)
SV * src
PROTOTYPE: $
PREINIT:
U8 *s, *p, *e, *d;
STRLEN byte;
SV *dst;
CODE:
s = (U8*)SvPV(src, byte);
dst = byte ? newSV(2 * byte) : newSVpvn("",0);
(void)SvPOK_only(dst);
d = (U8*)SvPVX(dst);
for (p = s, e = s + byte; p < e; ) {
*d++ = Is_SJ2BTp(p,e) ? *p++ : 0;
*d++ = *p++;
}
*d = '\0';
SvCUR_set(dst, d - (U8*)SvPVX(dst));
RETVAL = dst;
OUTPUT:
RETVAL
SV*
strcmp (l_sv, r_sv)
SV *l_sv
SV *r_sv
PROTOTYPE: $$
ALIAS:
strEQ = 1
strNE = 2
strLT = 3
strLE = 4
strGT = 5
strGE = 6
PREINIT:
U8 *sL, *sR, *eL, *eR, *pL, *pR;
STRLEN lbyte, rbyte;
IV rint, cL, cR, equals;
SV *dst = NULL;
CODE:
sL = (U8*)SvPV(l_sv, lbyte);
sR = (U8*)SvPV(r_sv, rbyte);
equals = (lbyte == rbyte) ? memEQ(sL, sR, lbyte) : 0;
if (ix == 1) /* EQ */
if (equals)
XSRETURN_YES;
else
XSRETURN_NO;
if (ix == 2) /* NE */
if (!equals)
( run in 0.690 second using v1.01-cache-2.11-cpan-5511b514fd6 )