Improve split_quoted_on_whitespace.

Apparently Perl has included (since version 5.0, no less) a module that
handles almost the exact case split_quoted_on_whitespace exists for.

The impetus for this is that the '${MODULE}' syntax for dest-dir is
apparently broken due to problems with the mixture of braces and quotes
in split_quoted_on_whitespace.

This change does not break the test suite (but does add a relevant test)
and does seem to fix the issue with strings with braces.

CCMAIL:rakuco@FreeBSD.org
wilder
Michael Pyne 14 years ago
parent 9be64e86e2
commit 87b88487ed
  1. 34
      kdesrc-build
  2. 2
      kdesrc-build-test.pl

@ -47,6 +47,7 @@ use File::Basename; # fileparse
use File::Spec; # tmpdir, rel2abs
use LWP::UserAgent;
use URI; # For git-clone snapshot support
use Text::ParseWords qw(parse_line);
use Sys::Hostname;
use Storable 'dclone';
use IO::Handle;
@ -3147,34 +3148,21 @@ BEGIN {
ksb::Util->import();
}
# This subroutine acts like split(' ', $_) except that double-quoted strings are not split in
# the process. Patch provided by Alain Boyer (alainboyer@gmail.com) based on a posting at
# http://www.perlmonks.org/?node_id=212174. Converted to an extended RE for readability by
# mpyne.
#
# Note: This only works if the quotes completely surround the parameter in question.
# i.e. "a=-DFOO -DBAR" works, a="-DFOO -DBAR" does not.
# This subroutine acts like split(' ', $_) except that double-quoted strings
# are not split in the process.
#
# First parameter: String to split on whitespace.
# Return value: A list of the individual words and quoted values in the string.
# The quotes themselves are not returned.
sub split_quoted_on_whitespace($)
{
my $str = shift;
my @words = $str =~
/\s* # Eat up whitespace
"? # Match 0-1 quotes
( # Open grouping expression
(?<!") # Match everything not following " (i.e. there was no quote)
\S+ # Followed by 1 or more non-whitespace (this breaks on whitespace)
(?<!") # Match everything not following " (don't read over a quote on accident)
| # or
[^"]+ # All non-quote characters (After reading a quote)
) # End grouping expression
"? # Followed by 0-1 quotes
\s* # Eat up whitespace
/xg; # g modifier repeats the match as often as possible to get all matches.
return @words;
# 0 means not to keep delimiters or quotes
my $line = shift;
# Remove leading/trailing whitespace
$line =~ s/^\s+//;
$line =~ s/\s+$//;
return parse_line('\s+', 0, $line);
}
# This function returns true if the give module uses CMake. If the user has

@ -171,6 +171,8 @@ is_deeply([ split_quoted_on_whitespace('a=b g f') ], \@result1, 'split_quoted_on
is_deeply([ split_quoted_on_whitespace(' a=b g f') ], \@result1, 'split_quoted_on_whitespace space no quotes, leading whitespace');
is_deeply([ split_quoted_on_whitespace('a=b g f ') ], \@result1, 'split_quoted_on_whitespace space no quotes, trailing whitespace');
is_deeply([ split_quoted_on_whitespace(' a=b g f ') ], \@result1, 'split_quoted_on_whitespace space no quotes, leading and trailing whitespace');
is_deeply([ split_quoted_on_whitespace('-DFOO="${MODULE}" BAR') ],
['-DFOO=${MODULE}', 'BAR'], 'split_quoted_on_whitespace with braces/quotes');
SKIP: {
skip "svn not available or network was down", 2 unless $svnAvail;

Loading…
Cancel
Save