in reply to A call to keyboards: Better chatterbox wrapping

Tested and running on the test server. Sorry about the strange regex delimiters. Several versions of Perl don't agree on how to escape the embedded delimiters and I blame mod_perl in this case (my copy of Perl agrees with me).

# Insert spaces to prevent the nodelets from getting too wide. # We leave the loopholes of using a bunch of "&nonentity;"s or # "<!--> -->" to intentionally make the nodelets wide (intended for # /msg'ing to yourself) as the problem is more accidents than abuse +. # "&123" and "&lt" work in some browsers, but we might put spaces i +n # the middle of them (if you don't like it, then remember the ";"). my $len= 0; $text =~ s[(\s+)|([^\s<&]+)|(<[^<>]*>)|(&#?\w{1,10};)|(.)]` if( $1 ) { $len= 0; $1; } elsif( length( $2 ) ) { # $2 is the only case that can be "0" (ie. false) my $res= $2; my $tot= $len + length($res); if( 18 < $tot ) { my $max = 18 - $len; my $min = $max - 9; $min = 0 if $min < 0; $res =~ s[ ( \S{$min,$max} (?: (?<!\W) (?![\w\[{(;,/]) | (?<![\w\$@%&*]) (?!\W) ) | \S{$max} )(?=\S) ][$1 ]x; $res =~ s[ ( \S{9,18} (?: (?<!\W) (?![\w\[{(;,/]) | (?<![\w\$@%&*]) (?!\W) ) | \S{18} )(?=(\S+)) ]{ length( $1 . $2 ) > 18 ? "$1 " : $1 }gex; $res =~ /(\S*)$/; $len= length( $1 ); } else { $len= $tot; } $res; } elsif( $3 ) { $3; } else { my $res= $4 || $5; my $add= $5 ? 1 : int( length($4)/3 ); $len += $add; if( 18 < $len ) { $len= $add; " $res"; } else { $res; } } `egis; return $text;

It tries to not put spaces in front of any of [{(;,/1 and not after $@%&* because they can be Perl sigils.

(Updated)

1 The first 5 because of Perl syntax, the last two because of IE silliness -- the "," is included for two reasons. IE won't wrap on " ," nor on " /".

Update2: I realized that [ will be encoded as &#91; and will be matched separately so I can remove the \[s from the regexes and probably revert to my best-practice method of using [ ] delimiters for regexes despite the mod_perl(?) bug. This also means that spaces won't be inserted in front of other characters that get encoded, namely any of <>], which is probably not worth trying to work around.

- tye        

Replies are listed 'Best First'.
Re^2: A call to keyboards: Better chatterbox wrapping (tye)
by Juerd (Abbot) on Jan 11, 2005 at 01:59 UTC

    not after $@%&* because they can be Perl sigils.

    $ that !~ /problem/; $this = ~ /problem/, though;

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      I'm not sure I've figured out what you are trying to say.

      I don't particularly care that Perl doesn't mind the space after the sigil; it is still a horrid place to insert a space (humans read code too).

      And between the two characters of =~ is excluded by the \b or its translation into my elaboration of roughly \W\w|\w\W.

      If those weren't your points or you had other points, feel free to reply with the English and code separated so they don't obfuscate each other. (:

      - tye