juks (juks) wrote in changelog,
juks
juks
changelog

[livejournal] r17984: LJM-1599 Rules of post parsing

Committer: iaskarov
LJM-1599 Rules of post parsing
U   trunk/cgi-bin/LJ/Text.pm
Modified: trunk/cgi-bin/LJ/Text.pm
===================================================================
--- trunk/cgi-bin/LJ/Text.pm	2010-12-21 09:13:38 UTC (rev 17983)
+++ trunk/cgi-bin/LJ/Text.pm	2010-12-21 09:39:31 UTC (rev 17984)
@@ -242,7 +242,7 @@
         if ($str =~ /\s+$/) {
             $str =~ s/\s+$//;
         } else {
-            $str =~ s/\s*\S+$//;
+            $str =~ s/(?<=\S\s)\s*\S+$//;
         }
 
         return $str;
@@ -257,6 +257,7 @@
 
         $str = $remove_last_word->($str);
         $remainder = substr($original_string, $class->byte_len($str));
+        
         $str .= $ellipsis;
     }
 	
@@ -266,19 +267,31 @@
             'str' => $str,
             'chars' => $chars_trunc + 1
         );
+       
+        my $add_space = (substr($str, $chars_trunc, 1) =~ /\s/);
 
         $str = $remove_last_word->($str);
-        $remainder = substr($original_string, $class->byte_len($str));
-
-        if($punct_space && $str =~ /[,.;:!?]$/) {
+ 
+        # What kind af moron one has to be to come up with this kind of logic to be implemented? 
+        if($add_space) {
+            $str .= ' ';
+        } elsif($punct_space && $str =~ /[,.;:!?]$/) {
 			if($class->char_len($str) >= $chars - 1) {
 		        $str = $remove_last_word->($str);
-		        $remainder = substr($original_string, $class->byte_len($str));
+		        
+		        if($class->char_len($str) >= $chars - 1) {
+                    $str = $class->truncate(
+                        'str' => $str,
+                        'bytes' => $class->char_len($str) - 2
+                    );
+		        }
 			} else {
 				$str .= ' ';
 			}   	
         }
         
+        $remainder = substr($original_string, $class->byte_len($str));
+        
         $str .= $ellipsis;
     } elsif($force_ellipsis) {
         $str .= $ellipsis;

Tags: juks, livejournal, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments