Unicode::GCString 错误消息:“新:必须给出 Unicode 字符串”

发布于 2025-01-07 22:12:56 字数 672 浏览 0 评论 0原文

这里可能出了什么问题:我收到错误消息
新:Unicode 字符串必须在...
对于线路
$gvalue = Unicode::GCString->new( $value );

use Unicode::GCString;

# ....
# ....

my $width = 0;
my $gvalue;

if ( $value ) {
    $gvalue = Unicode::GCString->new( $value );
    $width = $gvalue->columns();
}

# ....
# new: Unicode string must be given. at ...

$values 的形式如下:

for my $i ( 0 .. $#$ref ) {
    for my $j ( 0 .. $#{$ref->[$i]} ) {
        my $value = $ref->[$i][$j] // '';
        # ...

到目前为止,测试时 $ref 是硬编码的在脚本中,但它应该成为一个模块,并且 $ref 应该在例程中移动。

What could here be wrong: I get the error-message
new: Unicode string must be given at ...
for the line
$gvalue = Unicode::GCString->new( $value );

use Unicode::GCString;

# ....
# ....

my $width = 0;
my $gvalue;

if ( $value ) {
    $gvalue = Unicode::GCString->new( $value );
    $width = $gvalue->columns();
}

# ....
# new: Unicode string must be given. at ...

$values comes form:

for my $i ( 0 .. $#$ref ) {
    for my $j ( 0 .. $#{$ref->[$i]} ) {
        my $value = $ref->[$i][$j] // '';
        # ...

Until now while testing $ref is hardcoded in script but then it should become a module and $ref should be shifted in a routine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

未央 2025-01-14 22:12:56

Unicode::GCString 存在 Unicode Bug(为 UTF8 标志赋予含义):

 $ perl -MUnicode::GCString -E'
    $_=chr(0xE9);
    utf8::downgrade($_);
    Unicode::GCString->new($_);
    say "ok";
 '
 new: Unicode string must be given. at -e line 4.

 $ perl -MUnicode::GCString -E'
    $_=chr(0xE9);
    utf8::upgrade($_);
    Unicode::GCString->new($_);
    say "ok";
 '
 ok

它期望使用 UTF8=1 内部存储格式存储字符串。您可以使用 utf8::upgrade 强制字符串采用正确的格式,但这也可能表明您忘记解码字符串。

Unicode::GCString suffers from the Unicode Bug (assigns meaning to the UTF8 flag):

 $ perl -MUnicode::GCString -E'
    $_=chr(0xE9);
    utf8::downgrade($_);
    Unicode::GCString->new($_);
    say "ok";
 '
 new: Unicode string must be given. at -e line 4.

 $ perl -MUnicode::GCString -E'
    $_=chr(0xE9);
    utf8::upgrade($_);
    Unicode::GCString->new($_);
    say "ok";
 '
 ok

It expects a string in stored using the UTF8=1 internal storage format. You can force the string to the right format using utf8::upgrade, but it could also be a sign that you forgot to decode the string.

℉服软 2025-01-14 22:12:56

我忘记设置use utf8(并且我必须明确地字符串化$gstring->as_string)。

I forgot to set use utf8 (and I had to stringify explicitly $gstring->as_string).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文