|
TEXTCLIPFUNCSyntax
DescriptionTEXTCLIPFUNC defines the the Perl function to invoke when MHonArc clips text. For example, the function specified would be invoked when a length specifier is used for a resource variable, e.g. $SUBJECTNA:72$. The syntax for TEXTCLIPFUNC is as follows: routine-name;file-of-routine The definition of each semi-colon-separated value is as follows:
Writing a Clipping FunctionIf you want to write your own function, you need to know the Perl programming language. The following information assumes you know Perl. Function InterfaceMHonArc interfaces with text clipping function by calling the routine with a specific set of arguments. The prototype of the interface routine is as follows: sub clip { my($text, $clip_length, $is_html, $has_tags) = @_; # code here } Parameter Descriptions
Return ValueThe return value should be the clipped version of Writing Tips
Default Settingmhonarc::clip_text; Resource VariablesN/A ExamplesThe Unicode example resource file sets TEXTCLIPFUNC to a routine that understands UTF-8 text. The following is the implementation (as of this writing) of MHonArc's default clipping function: sub clip_text { my $str = \shift; # Prevent unnecessary copy. my $len = shift; # Clip length my $is_html = shift; # If entity references should be considered my $has_tags = shift; # If html tags should be stripped if (!$is_html) { return substr($$str, 0, $len); } my $text = ""; my $subtext = ""; my $html_len = length($$str); my($pos, $sublen, $erlen, $real_len); my $er_len = 0; for ( $pos=0, $sublen=$len; $pos < $html_len; ) { $subtext = substr($$str, $pos, $sublen); $pos += $sublen; # strip tags if ($has_tags) { $subtext =~ s/\A[^<]*>//; # clipped tag $subtext =~ s/<[^>]*>//g; $subtext =~ s/<[^>]*\Z//; # clipped tag } # check for clipped entity reference if (($pos < $html_len) && ($subtext =~ /\&[^;]*\Z/)) { my $semi = index($$str, ';', $pos); if ($semi < 0) { # malformed entity reference $subtext .= substr($$str, $pos); $pos = $html_len; } else { $subtext .= substr($$str, $pos, $semi-$pos+1) if $semi > $pos; $pos = $semi+1; } } # compute entity reference lengths to determine "real" character # count and not raw character count. while ($subtext =~ /(\&[^;]+);/g) { $er_len += length($1); } $text .= $subtext; # done if we have enough $real_len = length($text)-$er_len; if ($real_len >= $len) { last; } $sublen = $len - (length($text)-$er_len); } $text; } Version2.5.10 See Also
$Date: 2002/08/04 03:58:27 $ MHonArc Copyright © 2002, Earl Hood, mhonarc@mhonarc.org |