Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 6794ddd4

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

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

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

Unterschiede anzeigen:

SL/Presenter/Text.pm
12 12
sub truncate {
13 13
  my ($self, $text, %params) = @_;
14 14

  
15
  $params{at}             ||= 50;
16
  $params{at}               =  3 if 3 > $params{at};
17
  $params{at}              -= 3;
18

  
19
  return $text if length($text) < $params{at};
20
  return substr($text, 0, $params{at}) . '...';
15
  return Common::truncate($text, %params);
21 16
}
22 17

  
23 18
sub simple_format {
......
77 72
If the parameter C<skip_zero> is trueish then C<---> is returned
78 73
instead of the normal formatting if C<$value> equals 0.
79 74

  
80
=item C<truncate $text, [%params]>
75
=item C<truncate $text, %params>
81 76

  
82 77
Returns the C<$text> truncated after a certain number of
83
characters.
84

  
85
The number of characters to truncate at is determined by the parameter
86
C<at> which defaults to 50. If the text is longer than C<$params{at}>
87
then it will be truncated and postfixed with '...'. Otherwise it will
88
be returned unmodified.
78
characters. See L<Common/truncate> for the actual implementation and
79
supported parameters.
89 80

  
90 81
=item C<simple_format $text>
91 82

  

Auch abrufbar als: Unified diff