[Templates-cvs] cvs commit: Template2/lib/Template/Plugin String.pm

cvs@template-toolkit.org cvs@template-toolkit.org


cvs         06/01/30 16:42:14

  Modified:    lib/Template/Plugin String.pm
  Log:
  * added substr() method
  
  Revision  Changes    Path
  2.36      +23 -3     Template2/lib/Template/Plugin/String.pm
  
  Index: String.pm
  ===================================================================
  RCS file: /template-toolkit/Template2/lib/Template/Plugin/String.pm,v
  retrieving revision 2.35
  retrieving revision 2.36
  diff -u -r2.35 -r2.36
  --- String.pm	2006/01/30 15:57:19	2.35
  +++ String.pm	2006/01/30 16:42:13	2.36
  @@ -15,7 +15,7 @@
   #   modify it under the same terms as Perl itself.
   #
   # REVISION
  -#   $Id: String.pm,v 2.35 2006/01/30 15:57:19 abw Exp $
  +#   $Id: String.pm,v 2.36 2006/01/30 16:42:13 abw Exp $
   #
   #============================================================================
   
  @@ -32,7 +32,7 @@
   use overload q|""| => "text",
                fallback => 1;
   
  -$VERSION = sprintf("%d.%02d", q$Revision: 2.35 $ =~ /(\d+)\.(\d+)/);
  +$VERSION = sprintf("%d.%02d", q$Revision: 2.36 $ =~ /(\d+)\.(\d+)/);
   $ERROR   = '';
   
   *centre  = \*center;
  @@ -313,9 +313,29 @@
       return $self unless defined $length;
       $suffix ||= '';
       return $self if CORE::length $self->{ text } <= $length;
  -    $self->{ text } = substr($self->{ text }, 0, 
  +    $self->{ text } = CORE::substr($self->{ text }, 0, 
   			     $length - CORE::length($suffix)) . $suffix;
       return $self;
  +}
  +
  +
  +sub substr {
  +    my ($self, $offset, $length, $replacement) = @_;
  +    $offset ||= 0;
  +
  +    if(defined $length) {
  +        if (defined $replacement) {
  +            my $removed = CORE::substr( $self->{text}, $offset, $length );
  +            CORE::substr( $self->{text}, $offset, $length ) = $replacement;
  +            return $removed;
  +        }
  +        else {
  +            return CORE::substr( $self->{text}, $offset, $length );
  +        }
  +    } 
  +    else {
  +        return CORE::substr( $self->{text}, $offset );
  +    }
   }