On Thu, 11 Apr 2013 10:09:01 -0400
"Mark Overmeer via RT" <bug-Unicode-LineBreak@rt.cpan.org> wrote:
Show quoted text> Queue: Unicode-LineBreak
> Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=84549 >
>
> * Hatuka*nezumi - IKEDA Soji via RT (bug-Unicode-LineBreak@rt.cpan.org) [130411 12:36]:
> > <URL:
https://rt.cpan.org/Ticket/Display.html?id=84549 >
> > > sub trim($) {
> > > my ($self, $max) = @_;
> > > my $pos = $self->char_on($max);
> > > $self->substr($pos) = '' if defined $pos;
> > > $self;
> > > }
> > >
> > > # probably off-by-one errors :( Do we start counting column by 0 or 1?
> > > # return undef when outside string.
> > > sub char_on($) {
> > > my ($self, $col) = @_;
> > >
> > > my $taken_col = 0;
> > > my $pos;
> > > for($pos = 0; $pos <= $#self && $taken_col < $col; $pos++)
> > > { $taken_col += $self[$pos]->columns;
> > > }
> > > $taken_col < $col ? undef : $pos;
> > > }
> > >
> > > It seems to me, this is much more efficient in C than via Perl's tied
> > > interface. That's why I put it on the wishlist of your nice module.
> >
> > How about next() method? It seems approximately O(1).
> >
> > sub trim {
> > my $self = shift;
> > my $len = shift;
> > return '' if $len <= 0;
> >
> > my $pos = $self->pos;
> > $self->pos(0);
> >
> > my $cols = 0;
> > my $gc;
> > while (defined($gc = $self->next)) {
> > if ($len < ($cols += $gc->columns)) {
> > my $ret = $self->substr(0, $self->pos - 1);
> > $self->pos($pos);
> > return $ret;
> > }
> > }
> >
> > $self->pos($pos);
> > return $self;
> > }
> >
>
> That's the iterative version of my last example.
Yes, and it doesn't extract GCString to array.
Show quoted text> You do not think that a pure XS implementation for this is useful?
I had thought of similar thing. I believe XS version should have
slightly generalized function: It would like to support left-side
trim along with right-side trim and so on.
Since it will not be in time for next stable release (this May to
June), it would be better to use Perl version for the present.
Regards,
--
--- nezumi