develooper Front page | perl.perl5.porters | Postings from November 2015

Re: RFC: what to do about bitwise string operators (related to [perl#63574])

Thread Previous | Thread Next
Bo Lindbergh
November 17, 2015 06:48
Re: RFC: what to do about bitwise string operators (related to [perl#63574])
Message ID:
Quoth Karl Williamson:
> I still don't think that is useful in general.  Code points are not generally assigned where the relationship between them is meaningful in bit operations ways.

There is one use case for bitwise operations on code points:
you can find the length of the common prefix of two strings
by xoring them and counting leading NULs in the result.

    sub common_prefix_length
        ($_[0] ^ $_[1]) =~ /^\A\0*/;
        return $+[0];

Unrelated strong opinion: since docs for the string bitwise ops
and for the vec function reference each other, both should treat
high codepoints in the same way.  Back in the bytes-only days,
it was the case that

    vec(($a & $b), $i, $w) == vec($a, $i, $w) & vec($b, $i, $w)

(and so on for the other binary bitwise ops).  This is no longer true
for strings containing high codepoints.

/Bo Lindbergh

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