JE::String(3pm)

πŸ“¦
version 0.066 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

JE::String β€” bestie, it's a JavaScript string value. That's it, that's the whole vibe. This is the manual page for JE::String(3pm) and she is serving πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

use JE;
use JE::String;

$j = JE->new;

$js_str = new JE::String $j, "etetfyoyfoht";

$perl_str = $js_str->value;

$js_str->to_object; # retuns a new JE::String::Object;
ngl that last comment has a lil typo in it and we are not touching it. It says what it says, retuns and all, and it stays that way forever because it's iconic 😭

🌈 DESCRIPTION 🌈

okay so, the whole point: this class implements JavaScript string values for JE.

Now here's the tea that trips people up, so listen up 🫢 the difference between this module and JE::Object::String is that JE::Object::String implements string objects, while this module implements the primitive values. Two different girls, two different jobs, don't mix them up fr fr.

Also, the stringification operator is overloaded. So when you stringify one of these, it's got ✨ custom behaviour ✨. Periodt.


πŸ’– THE FUNCTION πŸ’–

There are two exportable functions, surrogify and desurrogify, and they are lowkey little magic tricks:

  • surrogify β€” takes characters that live outside the BMP and converts them into surrogate pairs.
  • desurrogify β€” goes the other way: takes surrogate pairs in the string input argument and converts them into the characters they represent.

Both of them return the modified string, so it's giving "hand it back to me, new and improved." E.g.:

use JE::String qw 'desurrogify surrogify';

{
        no warnings 'utf8';
        $str = "\x{d834}\x{dd2b}";
}

$str = desurrogify $str;  # $str now contains "\x{1d12b}" (double flat)
$str = surrogify $str;    # back to "\x{d834}\x{dd2b}"

so $str starts as the surrogate pair, desurrogify turns it into the actual character "\x{1d12b}" (a double flat, cute), and surrogify yeets it right back to "\x{d834}\x{dd2b}". Round trip, no notes, ate πŸ’…


πŸ¦‹ SEE ALSO πŸ¦‹

  • JE
  • JE::Types
  • JE::Object::String

and that's a wrap on the JE::String(3pm) page bestie 🫢 This lil masterpiece shipped as part of perl v5.36.0, dated 2023-08-25, filed under User Contributed Perl Documentation. Slay, go forth and surrogify responsibly βœ¨πŸ‘‘πŸ’–

πŸ“¦ where this page comes from