diff options
| author | Bob Lied <boblied+github@gmail.com> | 2023-07-20 21:48:13 -0500 |
|---|---|---|
| committer | Bob Lied <boblied+github@gmail.com> | 2023-07-20 21:48:13 -0500 |
| commit | 27e07f49703ef08d85a288ea73d7772a03aafe81 (patch) | |
| tree | 75eb391b703845bf0be57348af566b309d05dd39 /challenge-216 | |
| parent | 5d8fda6eb9d1e6e3558067abaef601adce85d241 (diff) | |
| download | perlweeklychallenge-club-27e07f49703ef08d85a288ea73d7772a03aafe81.tar.gz perlweeklychallenge-club-27e07f49703ef08d85a288ea73d7772a03aafe81.tar.bz2 perlweeklychallenge-club-27e07f49703ef08d85a288ea73d7772a03aafe81.zip | |
Clean up unused class
Diffstat (limited to 'challenge-216')
| -rw-r--r-- | challenge-216/bob-lied/perl/lib/SubstringIterator.pm | 62 | ||||
| -rw-r--r-- | challenge-216/bob-lied/perl/t/SubstringIterator.t | 33 |
2 files changed, 0 insertions, 95 deletions
diff --git a/challenge-216/bob-lied/perl/lib/SubstringIterator.pm b/challenge-216/bob-lied/perl/lib/SubstringIterator.pm deleted file mode 100644 index 06486b1029..0000000000 --- a/challenge-216/bob-lied/perl/lib/SubstringIterator.pm +++ /dev/null @@ -1,62 +0,0 @@ -# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: -#============================================================================= -# SubstringIterator.pm -#============================================================================= -# Copyright (c) 2023, Bob Lied -#============================================================================= -# Description: -# Iterate over all possible substrings of a string. Each iteration returns -# a triplet: the substring, and the prefix and suffix around it. -# -# We start with the longest possible substring (the string itself) and return -# new substrings in descending size. -# -# When the iterator is finished, it returns undef as the substring. -#============================================================================= - -package SubstringIterator; - -use v5.36; - -require Exporter; -our @ISA = qw(Exporter); -our @EXPORT = qw(); -our @EXPORT_OK = qw(); - -sub new -{ - my $class = shift; - $class = ref($class) || $class; - my $self = { - _target => $_[0], - _length => 0, - _pos => 0, - _size => 0, - }; - - $self->{_size} = $self->{_length} = length($self->{_target}); - bless $self, $class; - return $self; -} - -sub next($self) -{ - my ($target, $length, $pos, $size) = $self->@{ qw(_target _length _pos _size) }; - - return (undef, undef, undef) if $length == 0; - - my $sub = substr( $target, $pos, $length ); - my $before = substr( $target, 0, $pos); - my $after = substr( $target, $pos + $length, $size - $length); - my @retval = ( $before, $sub, $after ); - - if ( ($self->{_pos}++ + $length) == $size ) - { - $self->{_length}--; - $self->{_pos} = 0; - } - - return @retval; -} - -1; diff --git a/challenge-216/bob-lied/perl/t/SubstringIterator.t b/challenge-216/bob-lied/perl/t/SubstringIterator.t deleted file mode 100644 index 5d8edf584c..0000000000 --- a/challenge-216/bob-lied/perl/t/SubstringIterator.t +++ /dev/null @@ -1,33 +0,0 @@ -# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: -# -#=============================================================================== -# -# FILE: SubstringIterator.t -# -# DESCRIPTION: Unit test for SubstringIterator -#=============================================================================== - -use v5.36; - -use Test2::V0; - -use SubstringIterator; - -my $ssi = SubstringIterator->new("a"); -isa_ok( $ssi, [ qw(SubstringIterator) ] ); - -my @ret; -@ret = $ssi->next(); is ( \@ret, [ '', 'a', '' ], "Length one first"); -@ret = $ssi->next(); is ( \@ret, [ undef,undef,undef ], "Length one last"); - -$ssi = SubstringIterator->new("abc"); -@ret = $ssi->next(); is ( \@ret, [ '', 'abc', '' ], "Length 3 first"); -@ret = $ssi->next(); is ( \@ret, [ '', 'ab', 'c' ], "Length 3 2"); -@ret = $ssi->next(); is ( \@ret, [ 'a', 'bc', '' ], "Length 3 3"); -@ret = $ssi->next(); is ( \@ret, [ '', 'a', 'bc' ], "Length 3 4"); -@ret = $ssi->next(); is ( \@ret, [ 'a', 'b', 'c' ], "Length 3 5"); -@ret = $ssi->next(); is ( \@ret, [ 'ab', 'c', '' ], "Length 3 6"); -@ret = $ssi->next(); is ( \@ret, [ undef,undef,undef ], "Length one last"); - - -done_testing(); |
