SHARYA...g::Util(3pm)

πŸ“¦
version 0.26 Β· 2 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– SHARYANTO::String::Util β€” the string glow-up toolkit πŸ’–

okay bestie, sit DOWN, because this is a Perl module called SHARYANTO::String::Util and it's part of the User Contributed Perl Documentation crowd. It does string stuff. Glorious, mundane, deeply necessary string stuff. It's giving "utility drawer but make it cute". ✨


🌸 NAME 🌸

SHARYANTO::String::Util β€” String utilities. that's it, that's the whole name, no notes πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

✨ FUNCTIONS ✨

every single one of these is a bop, let's go one by one, no skipping, I promised 🫢

  • ltrim($str) => STR β€” trims whitespaces (newlines INCLUDED, she's thorough) off the beginning of the string. Equivalent to:
$str =~ s/\A\s+//s;
  • ltrim_lines($str) => STR β€” trims whitespaces (newlines NOT included this time, she's selective) off the beginning of each line of the string. Equivalent to:
$str =~ s/^\s+//mg;
  • rtrim($str) => STR β€” trims whitespaces (newlines included) off the end of the string. Equivalent to:
$str =~ s/[ \t]+\z//s;
  • rtrim_lines($str) => STR β€” trims whitespaces (newlines not included) off the end of each line of the string. Equivalent to:
$str =~ s/[ \t]+$//mg;
  • trim($str) => STR β€” literally just ltrim + rtrim. the collab we deserved. πŸŽ€
  • trim_lines($str) => STR β€” ltrim_lines + rtrim_lines. the line-flavored sequel. 🌈
  • trim_blank_lines($str) => STR β€” trims blank lines off the beginning and the end. it will NOT touch blank lines in the middle, she minds her business. and yes, "blank lines" counts lines that have nothing but whitespaces in them. πŸ™ˆ
  • ellipsis($str[, $maxlen, $ellipsis]) => STR β€” returns $str completely unmodified if $str's length is less than $maxlen (default 80). otherwise it cuts $str down to ($maxlen - length($ellipsis)) and slaps $ellipsis (default '...') on the end. short king behavior, respectfully. βœ‚οΈ
  • indent($indent, $str, \%opts) => STR β€” indents every line in $str with $indent. example, because a girl loves a visual:
indent('  ', "one\ntwo\nthree") # "  one\n  two\n  three"

%opts is optional. known options are:

  • indent_blank_lines => BOOL (default 1) β€” if you set it to false, it does not indent blank lines (aka lines containing only zero or more whitespaces). zero. or more. whitespaces. noted. πŸ’€
  • linenum($str, \%opts) => STR β€” adds line numbers. for example:
     1|line1
     2|line2
      |
     4|line4

known options are:

  • width => INT (default: 4)
  • zeropad => BOOL (default: 0) β€” turn it on and you get something like:
     0001|line1
     0002|line2
         |
     0004|line4
  • skip_empty => BOOL (default: 1) β€” if you set it to false, it keeps printing the line number even if the line is empty:
       1|line1
       2|line2
       3|
       4|line4
  • pad($text, $width[, $which[, $padchar[, $truncate]]]) => STR β€” returns $text padded with $padchar out to $width columns. $which is either "r" or "right" for padding on the right (this is the default if you don't specify anything), "l" or "left" for padding on the right, or "c" or "center" or "centre" for left+right padding to center the text.
bestie I am relaying this EXACTLY as written: the manpage says "l"/"left" is "for padding on the right". that's the text. I am simply the messenger. πŸ’€

$padchar is whitespace if you don't specify it. it should be a string having the width of 1 column.

  • qqquote($str) => STR β€” quotes or encodes $str into the Perl double quote ("qq") literal representation of the string. examples, because obviously:
say qqquote("a");        # => "a"
say qqquote("a\n");      # => "a\n"
say qqquote('"');        # => "\""
say qqquote('$foo');     # => "\$foo"

this code is taken from "quote()" in Data::Dump. and, quoting the author's own vibe here: maybe he didn't look more closely, but he couldn't find a module that provides a function to do something like this. String::Escape, for example, provides "qqbackslash" but it does not escape "$". relatable honestly. 😭

None are exported by default, but they are exportable. πŸ‘‘


πŸ”₯ SEE ALSO πŸ”₯

SHARYANTO


🌈 HOMEPAGE 🌈

Please visit the project's homepage at <https://metacpan.org/release/SHARYANTO-String-Util>. go, run, don't walk πŸƒβ€β™€οΈπŸ’¨


🧚 SOURCE 🧚

Source repository is at HASH(0x353ed90).

not me reading that and going "bestie that's a stringified hash ref" β€” anyway, that is literally what the page says, so that is literally what you get. no cap. 🫢

⭐ BUGS ⭐

Please report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=SHARYANTO-String-Util>

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. (this is the part where you actually help, and that's the most main character energy of all πŸ’…)


πŸ‘‘ AUTHOR πŸ‘‘

Steven Haryanto <stevenharyanto@gmail.com>


This software is copyright (c) 2013 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


okay that's the whole page, you ate it, every function, every option, every default, every regex, every URL, all accounted for. ✨ this was SHARYA...g::Util (yes the header really truncates it like that, iconic of it), shipped as part of the User Contributed Perl Documentation, living its life at perl v5.26.1, dated 2018-04-07 β€” mwah, periodt, go trim something πŸ’–πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from