Help language development. Donate to The Perl Foundation

String::Utils zef:lizmat last updated on 2022-01-26

e04e421061afa56ca31955680d27a5802806eb61/

Actions Status

NAME

String::Utils - Provide some optimized string functions

SYNOPSIS

use String::Utils;

say before("foobar","bar");            # foo

say between("foobarbaz","foo","baz");  # bar

say between-included("foobarbaz","oo","baz");  # oobarbaz

say around("foobarbaz", "ob", "rb");   # foaz

say after("foobar","foo");             # bar

say chomp-needle("foobarbaz", "baz");  # foobar

say root <abcd abce abde>;             # ab

DESCRIPTION

String::Utils provides some simple string functions that are not (yet) provided by the core Raku Programming Language.

SUBROUTINES

after

say after("foobar","foo");   # bar

say "foobar".&after("foo");  # bar

say after("foobar","goo");   # Nil

Return the string after a given string, or Nil if the given string could not be found. The equivalent of the stringification of / <?after foo> .* /.

around

say around("foobarbaz","ob","rb");     # foaz

say "foobarbaz".&around("ob","rb");    # foaz

say around("foobarbaz","goo","baz");   # foobarbaz

Return the string around two given strings, or the string itself if either of the bounding strings could not be found. The equivalent of .subst: / <?after ob> .*? <?before rb> /.

before

say before("foobar","bar");   # foo

say "foobar".&before("bar");  # foo

say before("foobar","baz");   # Nil

Return the string before a given string, or Nil if the given string could not be found. The equivalent of the stringification of / .*? <?before bar> /.

between

say between("foobarbaz","foo","baz");   # bar

say "foobarbaz".&between("foo","baz");  # bar

say between("foobarbaz","goo","baz");   # Nil

Return the string between two given strings, or Nil if either of the bounding strings could not be found. The equivalent of the stringification of / <?after foo> .*? <?before baz> /.

between-included

say between-included("foobarbaz","oo","baz");   # oobarbaz

say "foobarbaz".&between-included("oo","baz");  # oobarbaz

say between-included("foobarbaz","goo","baz");  # Nil

Return the string between two given strings including the given strings, or Nil if either of the bounding strings could not be found. The equivalent of the stringification of / o .*? baz /.

chomp-needle

say chomp-needle("foobarbaz","baz");   # foobar

say "foobarbaz".&chomp-needle("baz");  # foobar

say chomp-needle("foobarbaz","bar");   # foobarbaz

Return the string between two given strings including the given strings, or Nil if either of the bounding strings could not be found. The equivalent of the stringification of / .* <?before baz $> /.

root

say root <abcd abce abde>;  # ab

Return the common root of the given strings, or the empty string if no common string could be found.

AUTHOR

Elizabeth Mattijsen [email protected]

Source can be located at: https://github.com/lizmat/String-Utils . Comments and Pull Requests are welcome.

COPYRIGHT AND LICENSE

Copyright 2022 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.