# character escapes, but not delimiters that might need to be escaped
sub escape_str { # ASCII, UTF8
my($str) = @_;
- $str =~ s/(.)/ord($1)>255 ? sprintf("\\x{%x}", ord($1)) : $1/eg;
+ $str =~ s/(.)/ord($1) > 255 ? sprintf("\\x{%x}", ord($1)) : $1/eg;
$str =~ s/\a/\\a/g;
# $str =~ s/\cH/\\b/g; # \b means something different in a regex
$str =~ s/\t/\\t/g;
$str =~ s/\e/\\e/g;
$str =~ s/\f/\\f/g;
$str =~ s/\r/\\r/g;
- $str =~ s/([\cA-\cZ])/'\\c' . chr(ord('@') + ord($1))/ge;
- $str =~ s/([^[:print:]])/'\\' . sprintf("%03o", ord($1))/ge;
+ $str =~ s/([\cA-\cZ])/sprintf("\\c%c", ord('@') + ord($1))/ge;
+ $str =~ s/([[:^print:]])/sprintf("\\%03o", ord($1))/ge;
return $str;
}
# Leave whitespace unmangled.
sub escape_extended_re {
my($str) = @_;
- $str =~ s/(.)/ord($1)>255 ? sprintf("\\x{%x}", ord($1)) : $1/eg;
- $str =~ s/([^[:print:]])/'\\' . sprintf("%03o", ord($1))/ge;
+ $str =~ s/(.)/ord($1) > 255 ? sprintf("\\x{%x}", ord($1)) : $1/eg;
+ $str =~ s/([[:^print:]])/sprintf("\\%03o", ord($1))/ge;
$str =~ s/\n/\n\f/g;
return $str;
}
my($str) = @_;
# the insane complexity here is due to the behaviour of "\c\"
- $str =~ s/(^|[^\\]|\\c\\)(?<!\\c)\\(\\\\)*(?=[^[:print:]])/$1$2/g;
+ $str =~ s/(^|[^\\]|\\c\\)(?<!\\c)\\(\\\\)*(?=[[:^print:]])/$1$2/g;
return $str;
}