develooper Front page | perl.perl6.users | Postings from June 2021

Buf to Str

Thread Next
Paul Procacci
June 9, 2021 04:34
Buf to Str
Message ID:
Hopefully a pretty quick question....

GIven the following:

my Buf $b .= new([72, 105, 0, 32, 97, 103, 97, 105, 110, 0]);
say $b.decode;

I would expect this to print 'Hi'.
Instead it prints 'Hi again'.

The decode documentation for Buf only states that 'Applies an encoding to
turn the blob into a Str <>; the encoding
will be UTF-8 by default.'

The zero (0) in that Buf should imply an end of string yet decode seems to
want to decode the number of elements instead.

Furthermore, If I 'say $b.decode.chars;' it counts the initial null as part
of Str.
In my mind, that means Str doesn't really mean string.

So the question, how does one ACTUALLY decode what's in a buffer to a
string where it adheres to the semantics of NULL termination for strings

Another question might be, should decode() follow null terminating
semantics instead of number of elements in a given Buf.


:(){ :|:& };:

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About