Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 6794ddd4

Von Moritz Bunkus vor etwa 12 Jahren hinzugefügt

  • ID 6794ddd488626fce34fb07bb0d5bb4878fa3c02a
  • Vorgänger 9b3133b3
  • Nachfolger 8836016b

Text-Funktion "truncate" nach Common verschoben, dokumentiert, getestet

Unterschiede anzeigen:

SL/Common.pm
return "/tmp/kivitendo-tmp-" . unique_id();
}
sub truncate {
my ($text, %params) = @_;
$params{at} //= 50;
$params{at} = 3 if 3 > $params{at};
$params{strip} //= '';
$text =~ s/[\r\n]+$//g if $params{strip} =~ m/^(?: 1 | newlines? | full )$/x;
$text =~ s/[\r\n]+/ /g if $params{strip} =~ m/^(?: newlines? | full )$/x;
return $text if length($text) <= $params{at};
return substr($text, 0, $params{at} - 3) . '...';
}
sub retrieve_parts {
$main::lxdebug->enter_sub();
......
}
1;
__END__
=pod
=encoding utf8
=head1 NAME
Common - Common routines used in a lot of places.
=head1 SYNOPSIS
my $short_text = Common::truncate($long_text, at => 10);
=head1 FUNCTIONS
=over 4
=item C<truncate $text, %params>
Truncates C<$text> at a position and insert an ellipsis if the text is
longer. The maximum number of characters to return is given with the
paramter C<at> which defaults to 50.
The optional parameter C<strip> can be used to remove unwanted line
feed/carriage return characters from the text before truncation. It
can be set to C<1> (only strip those at the end of C<$text>) or
C<full> (replace consecutive line feed/carriage return characters in
the middle by a single space and remove tailing line feed/carriage
return characters).
=back
=head1 BUGS
Nothing here yet.
=head1 AUTHOR
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>,
Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>
=cut

Auch abrufbar als: Unified diff