From d9728d369337b706dfa5673039e24ef7e71cd4ef Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sat, 24 Aug 2019 19:25:21 -0700 Subject: [PATCH] FuncCommand: add sed func based on krok's factoid --- PBot/FuncCommand.pm | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/PBot/FuncCommand.pm b/PBot/FuncCommand.pm index 7508b890..81744fb2 100644 --- a/PBot/FuncCommand.pm +++ b/PBot/FuncCommand.pm @@ -66,6 +66,11 @@ sub init_funcs { usage => 'uri_escape ', subref => sub { $self->func_uri_escape(@_) } }, + sed => { + desc => 'a sed-like stream editor', + usage => 'sed s///[Pig]; P preserve case; i ignore case; g replace all', + subref => sub { $self->func_sed(@_) } + }, }; } @@ -121,6 +126,38 @@ sub func_list { return $result; } +# near-verbatim insertion of krok's `sed` factoid +no warnings; +sub func_sed { + my $self = shift; + my $text = "@_"; + + if ($text =~ /^s(.)(.*?)(?