use Symbol;
use ExtUtils::ParseXS::Utilities qw(
standard_typemap_locations
+ trim_whitespace
);
our (@ISA, @EXPORT_OK, $VERSION);
if ($mode eq 'Typemap') {
chomp;
my $line = $_;
- TrimWhitespace($_);
+ trim_whitespace($_);
# skip blank lines and comment lines
next if /^$/ or /^#/;
my($type,$kind, $proto) = /^\s*(.*?\S)\s+(\S+)\s*($proto_re*)\s*$/ or
sub errors { $errors }
-sub TrimWhitespace {
- $_[0] =~ s/^\s+|\s+$//go;
-}
-
sub TidyType {
local ($_) = @_;
s/\s+/ /g;
# trim leading & trailing whitespace
- TrimWhitespace($_);
+ trim_whitespace($_);
$_;
}
blurt ("Error: `CASE:' after unconditional `CASE:'")
if $condnum && $cond eq '';
$cond = $_;
- TrimWhitespace($cond);
+ trim_whitespace($cond);
print " ", ($condnum++ ? " else" : ""), ($cond ? " if ($cond)\n" : "\n");
$_ = '';
}
last if /^\s*NOT_IMPLEMENTED_YET/;
next unless /\S/; # skip blank lines
- TrimWhitespace($_);
+ trim_whitespace($_);
my $line = $_;
# remove trailing semicolon if no initialisation
sub C_ARGS_handler() {
my $in = merge_section();
- TrimWhitespace($in);
+ trim_whitespace($in);
$func_args = $in;
}
sub INTERFACE_MACRO_handler() {
my $in = merge_section();
- TrimWhitespace($in);
+ trim_whitespace($in);
if ($in =~ /\s/) { # two
($interface_macro, $interface_macro_set) = split ' ', $in;
}
sub INTERFACE_handler() {
my $in = merge_section();
- TrimWhitespace($in);
+ trim_whitespace($in);
foreach (split /[\s,]+/, $in) {
my $name = $_;
sub ATTRS_handler () {
for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
next unless /\S/;
- TrimWhitespace($_);
+ trim_whitespace($_);
push @Attributes, $_;
}
}
sub ALIAS_handler () {
for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
next unless /\S/;
- TrimWhitespace($_);
+ trim_whitespace($_);
GetAliases($_) if $_;
}
}
sub OVERLOAD_handler() {
for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
next unless /\S/;
- TrimWhitespace($_);
+ trim_whitespace($_);
while ( s/^\s*([\w:"\\)\+\-\*\/\%\<\>\.\&\|\^\!\~\{\}\=]+)\s*//) {
$Overload = 1 unless $Overload;
my $overload = "$Package\::(".$1;
# the rest of the current line should contain either TRUE,
# FALSE or UNDEF
- TrimWhitespace($_);
+ trim_whitespace($_);
my %map = (
TRUE => "&PL_sv_yes", 1 => "&PL_sv_yes",
FALSE => "&PL_sv_no", 0 => "&PL_sv_no",
# the rest of the current line should contain a version number
my ($Ver) = $_;
- TrimWhitespace($Ver);
+ trim_whitespace($Ver);
death ("Error: REQUIRE expects a version number")
unless $Ver;
# the rest of the current line should contain either ENABLE or
# DISABLE
- TrimWhitespace($_);
+ trim_whitespace($_);
# check for ENABLE/DISABLE
death ("Error: VERSIONCHECK: ENABLE/DISABLE")
for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
next unless /\S/;
$specified = 1;
- TrimWhitespace($_);
+ trim_whitespace($_);
if ($_ eq 'DISABLE') {
$ProtoThisXSUB = 0;
}
death("Error: Only 1 SCOPE declaration allowed per xsub")
if $scope_in_this_xsub ++;
- TrimWhitespace($_);
+ trim_whitespace($_);
death ("Error: SCOPE: ENABLE/DISABLE")
unless /^(ENABLE|DISABLE)\b/i;
$ScopeThisXSUB = ( uc($1) eq 'ENABLE' );
# the rest of the current line should contain either ENABLE or
# DISABLE
- TrimWhitespace($_);
+ trim_whitespace($_);
# check for ENABLE/DISABLE
death ("Error: PROTOTYPES: ENABLE/DISABLE")
sub INCLUDE_handler () {
# the rest of the current line should contain a valid filename
- TrimWhitespace($_);
+ trim_whitespace($_);
death("INCLUDE: filename missing")
unless $_;
sub INCLUDE_COMMAND_handler () {
# the rest of the current line should contain a valid command
- TrimWhitespace($_);
+ trim_whitespace($_);
$_ = QuoteArgs($_) if $^O eq 'VMS';
}
1;
-__END__
-
--- /dev/null
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Test::More tests => 5;
+use lib qw( lib );
+use ExtUtils::ParseXS::Utilities qw(
+ trim_whitespace
+);
+
+my $str;
+
+$str = 'overworked';
+trim_whitespace($str);
+is( $str, 'overworked', "Got expected value" );
+
+$str = ' overworked';
+trim_whitespace($str);
+is( $str, 'overworked', "Got expected value" );
+
+$str = 'overworked ';
+trim_whitespace($str);
+is( $str, 'overworked', "Got expected value" );
+
+$str = ' overworked ';
+trim_whitespace($str);
+is( $str, 'overworked', "Got expected value" );
+
+$str = "\toverworked";
+trim_whitespace($str);
+is( $str, 'overworked', "Got expected value" );