mirror of
https://github.com/pragma-/pbot.git
synced 2025-02-17 05:50:56 +01:00
compiler_vm: improve split_line
This commit is contained in:
parent
8c97a57eab
commit
d4853a0323
@ -317,8 +317,8 @@ sub execute {
|
|||||||
$stdin =~ s/(?<!\\)\\r/\r/mg;
|
$stdin =~ s/(?<!\\)\\r/\r/mg;
|
||||||
$stdin =~ s/(?<!\\)\\t/\t/mg;
|
$stdin =~ s/(?<!\\)\\t/\t/mg;
|
||||||
$stdin =~ s/(?<!\\)\\b/\b/mg;
|
$stdin =~ s/(?<!\\)\\b/\b/mg;
|
||||||
$stdin =~ s/(?<!\\)\\x([a-f0-9]+)/chr hex $1/ige;
|
$stdin =~ s/(?<!\\)\\x([a-f0-9]+)/chr hex $1/igme;
|
||||||
$stdin =~ s/(?<!\\)\\([0-7]+)/chr oct $1/ge;
|
$stdin =~ s/(?<!\\)\\([0-7]+)/chr oct $1/gme;
|
||||||
|
|
||||||
my $pretty_code = $self->pretty_format($self->{code});
|
my $pretty_code = $self->pretty_format($self->{code});
|
||||||
|
|
||||||
@ -1019,9 +1019,11 @@ sub process_interactive_edit {
|
|||||||
$self->{code} = $code;
|
$self->{code} = $code;
|
||||||
}
|
}
|
||||||
|
|
||||||
# splits line into quoted arguments while preserving quotes. handles
|
# splits line into quoted arguments while preserving quotes.
|
||||||
# unbalanced quotes gracefully by treating them as part of the argument
|
# a string is considered quoted only if they are surrounded by
|
||||||
# they were found within.
|
# whitespace or json separators.
|
||||||
|
# handles unbalanced quotes gracefully by treating them as
|
||||||
|
# part of the argument they were found within.
|
||||||
sub split_line {
|
sub split_line {
|
||||||
my ($self, $line, %opts) = @_;
|
my ($self, $line, %opts) = @_;
|
||||||
|
|
||||||
@ -1041,6 +1043,7 @@ sub split_line {
|
|||||||
my $token = '';
|
my $token = '';
|
||||||
my $ch = ' ';
|
my $ch = ' ';
|
||||||
my $last_ch;
|
my $last_ch;
|
||||||
|
my $next_ch;
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
my $pos;
|
my $pos;
|
||||||
my $ignore_quote = 0;
|
my $ignore_quote = 0;
|
||||||
@ -1065,6 +1068,7 @@ sub split_line {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ch = $chars[$i++];
|
$ch = $chars[$i++];
|
||||||
|
$next_ch = $chars[$i];
|
||||||
|
|
||||||
$spaces = 0 if $ch ne ' ';
|
$spaces = 0 if $ch ne ' ';
|
||||||
|
|
||||||
@ -1084,7 +1088,7 @@ sub split_line {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (defined $quote) {
|
if (defined $quote) {
|
||||||
if ($ch eq $quote) {
|
if ($ch eq $quote and (not defined $next_ch or $next_ch =~ /[\s,:;})\].+=]/)) {
|
||||||
# closing quote
|
# closing quote
|
||||||
$token .= $ch unless $opts{strip_quotes};
|
$token .= $ch unless $opts{strip_quotes};
|
||||||
push @args, $token;
|
push @args, $token;
|
||||||
@ -1097,7 +1101,7 @@ sub split_line {
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($last_ch eq ' ' or $last_ch eq ':' or $last_ch eq '(') and not defined $quote and ($ch eq "'" or $ch eq '"')) {
|
if (($last_ch =~ /[\s:{(\[.+=]/) and not defined $quote and ($ch eq "'" or $ch eq '"')) {
|
||||||
if ($ignore_quote) {
|
if ($ignore_quote) {
|
||||||
# treat unbalanced quote as part of this argument
|
# treat unbalanced quote as part of this argument
|
||||||
$token .= $ch;
|
$token .= $ch;
|
||||||
|
@ -81,9 +81,11 @@ sub execute {
|
|||||||
return ($exitval, $stdout, $stderr);
|
return ($exitval, $stdout, $stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
# splits line into quoted arguments while preserving quotes. handles
|
# splits line into quoted arguments while preserving quotes.
|
||||||
# unbalanced quotes gracefully by treating them as part of the argument
|
# a string is considered quoted only if they are surrounded by
|
||||||
# they were found within.
|
# whitespace or json separators.
|
||||||
|
# handles unbalanced quotes gracefully by treating them as
|
||||||
|
# part of the argument they were found within.
|
||||||
sub split_line {
|
sub split_line {
|
||||||
my ($self, $line, %opts) = @_;
|
my ($self, $line, %opts) = @_;
|
||||||
|
|
||||||
@ -103,6 +105,7 @@ sub split_line {
|
|||||||
my $token = '';
|
my $token = '';
|
||||||
my $ch = ' ';
|
my $ch = ' ';
|
||||||
my $last_ch;
|
my $last_ch;
|
||||||
|
my $next_ch;
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
my $pos;
|
my $pos;
|
||||||
my $ignore_quote = 0;
|
my $ignore_quote = 0;
|
||||||
@ -127,6 +130,7 @@ sub split_line {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ch = $chars[$i++];
|
$ch = $chars[$i++];
|
||||||
|
$next_ch = $chars[$i];
|
||||||
|
|
||||||
$spaces = 0 if $ch ne ' ';
|
$spaces = 0 if $ch ne ' ';
|
||||||
|
|
||||||
@ -146,7 +150,7 @@ sub split_line {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (defined $quote) {
|
if (defined $quote) {
|
||||||
if ($ch eq $quote) {
|
if ($ch eq $quote and (not defined $next_ch or $next_ch =~ /[\s,:;})\].+=]/)) {
|
||||||
# closing quote
|
# closing quote
|
||||||
$token .= $ch unless $opts{strip_quotes};
|
$token .= $ch unless $opts{strip_quotes};
|
||||||
push @args, $token;
|
push @args, $token;
|
||||||
@ -159,7 +163,7 @@ sub split_line {
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($last_ch eq ' ' or $last_ch eq ':' or $last_ch eq '(') and not defined $quote and ($ch eq "'" or $ch eq '"')) {
|
if (($last_ch =~ /[\s:{(\[.+=]/) and not defined $quote and ($ch eq "'" or $ch eq '"')) {
|
||||||
if ($ignore_quote) {
|
if ($ignore_quote) {
|
||||||
# treat unbalanced quote as part of this argument
|
# treat unbalanced quote as part of this argument
|
||||||
$token .= $ch;
|
$token .= $ch;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user