在XS层面,你穿透或UTF-8型护卫。 在一般情况下,你的代码可能包含一个char *
,以标明其行文中的下一个项目。 用于XS的一套有用的UTF-8支助职能,改为 section of
http://cpansearch.perl.org/src/PEVANS/Tickit-0.15/lib/Tickit/Utils.xs”rel=“nofollow” http://cpansearch.perl.org/src/PEVANS/Tickit-0.15/lib/Tickit/Utils.xs。
int textwidth(str)
SV *str
INIT:
STRLEN len;
const char *s, *e;
CODE:
RETVAL = 0;
if(!SvUTF8(str)) {
str = sv_mortalcopy(str);
sv_utf8_upgrade(str);
}
s = SvPV_const(str, len);
e = s + len;
while(s < e) {
UV ord = utf8n_to_uvchr(s, e-s, &len, (UTF8_DISALLOW_SURROGATE
|UTF8_WARN_SURROGATE
|UTF8_DISALLOW_FE_FF
|UTF8_WARN_FE_FF
|UTF8_WARN_NONCHAR));
int width = wcwidth(ord);
if(width == -1)
XSRETURN_UNDEF;
s += len;
RETVAL += width;
}
OUTPUT:
RETVAL
简言之,这项职能在一段时间内使一个统法协会的编码特性发生重叠,从而累积了<代码>wcwidth()所规定的宽度。