Changeset 4840


Ignore:
Timestamp:
2003-07-01T11:55:31+12:00 (21 years ago)
Author:
davidb
Message:

-removesuffix option added to provide similar funtionality to -removeprefix

Location:
trunk/gsdl/perllib/classify
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/classify/AZCompactList.pm

    r4786 r4840  
    6868      { 'name' => "removeprefix",
    6969    'desc' => "A prefix to ignore in the Metadata values for the field when sorting.",
     70    'type' => "string",
     71    'deft' => "",
     72    'reqd' => "no" },
     73      { 'name' => "removesuffix",
     74    'desc' => "A suffix to ignore in the Metadata values for the field when sorting.",
    7075    'type' => "string",
    7176    'deft' => "",
     
    142147
    143148
    144     my ($metaname, $title, $removeprefix);
     149    my ($metaname, $title, $removeprefix, $removesuffix);
    145150    my $mingroup = 2;
    146151    my $minnesting = 20;
     
    156161             q^buttonname/.*/^, \$title,
    157162             q^removeprefix/.*/^, \$removeprefix,
     163             q^removesuffix/.*/^, \$removesuffix,
    158164             q^mingroup/.*/2^, \$mingroup,
    159165             q^minnesting/.*/20^, \$minnesting,
     
    187193    $self->{'title'} = "$title";     # title for the titlebar.
    188194    if (defined($removeprefix) && $removeprefix) {
     195    $removeprefix =~ s/^\^//; # don't need a leading ^
    189196    $self->{'removeprefix'} = $removeprefix;
     197    }
     198    if (defined($removesuffix) && $removesuffix) {
     199    $removesuffix =~ s/\$$//; # don't need a trailing $
     200    $self->{'removesuffix'} = $removesuffix;
    190201    }
    191202    $self->{'mingroup'} = $mingroup;
     
    277288        if (defined $metavalue && $metavalue =~ /\w/)
    278289        {
    279         if ($self->{'removeprefix'}) {
     290        if (defined($self->{'removeprefix'}) &&
     291            length($self->{'removeprefix'})) {
    280292            $metavalue =~ s/^$self->{'removeprefix'}//;
     293
     294            # check that it's not now empty
     295            if (!$metavalue) {next;}
     296        }
     297
     298        if (defined($self->{'removesuffix'}) &&
     299            length($self->{'removesuffix'})) {
     300            $metavalue =~ s/$self->{'removesuffix'}$//;
    281301
    282302            # check that it's not now empty
     
    423443        my $formatted_node = $metavalue;
    424444
    425         if ($self->{'removeprefix'}) {
     445        if (defined($self->{'removeprefix'}) &&
     446            length($self->{'removeprefix'})) {
    426447            $formatted_node =~ s/^$self->{'removeprefix'}//;
     448            # check that it's not now empty
     449            if (!$formatted_node) {next;}
     450        }
     451        if (defined($self->{'removesuffix'}) &&
     452            length($self->{'removesuffix'})) {
     453            $formatted_node =~ s/$self->{'removesuffix'}$//;
    427454            # check that it's not now empty
    428455            if (!$formatted_node) {next;}
  • trunk/gsdl/perllib/classify/AZList.pm

    r4786 r4840  
    5050    'type' => "string",
    5151    'deft' => "",
    52     'reqd' => "no" } ];
     52    'reqd' => "no" } ,
     53      { 'name' => "removesuffix",
     54    'desc' => "A suffix to ignore in the Metadata values for the field when sorting.",
     55    'type' => "string",
     56    'deft' => "",
     57    'reqd' => "no" }
     58      ];
    5359
    5460my $options = { 'name'     => "AZList",
     
    8187    push( @{$option_list}, $options );
    8288   
    83     my ($metaname, $title, $removeprefix);
     89    my ($metaname, $title, $removeprefix, $removesuffix);
    8490   
    8591    if (!parsargv::parse(\@_,
     
    8793             q^buttonname/.*/^, \$title,
    8894             q^removeprefix/.*/^, \$removeprefix,
     95             q^removesuffix/.*/^, \$removesuffix,
    8996             "allow_extra_options")) {
    9097   
     
    109116    $self->{'removeprefix'} = $removeprefix;
    110117    }
     118    if (defined($removesuffix) && $removesuffix) {
     119    $removesuffix =~ s/\$$//; # don't need a trailing $
     120    $self->{'removesuffix'} = $removesuffix;
     121    }
    111122
    112123    return bless $self, $class;
     
    133144        length($self->{'removeprefix'})) {
    134145        $metavalue =~ s/^$self->{'removeprefix'}//;
     146    }
     147    if (defined($self->{'removesuffix'}) &&
     148        length($self->{'removesuffix'})) {
     149        $metavalue =~ s/$self->{'removesuffix'}$//;
    135150    }
    136151
Note: See TracChangeset for help on using the changeset viewer.