Revision: 1241
Author: christian.wuerker
Date: Sat Jul 4 12:19:13 2015 UTC
Log: Fixed bug in text extender.
https://code.google.com/p/cmclasses/source/detail?r=1241
Modified:
/trunk/src/Alg/Text/Extender.php
=======================================
--- /trunk/src/Alg/Text/Extender.php Sat May 23 06:45:51 2015 UTC
+++ /trunk/src/Alg/Text/Extender.php Sat Jul 4 12:19:13 2015 UTC
@@ -8,9 +8,9 @@
return str_pad( $text, $toLength, $withString, $fromLeft ?
STR_PAD_LEFT : STR_PAD_RIGHT );
$textLength = mb_strlen( $text, self::$encoding );
$withStringLength = mb_strlen( $withString, self::$encoding );
- if( !$toLength || !$withStringLength || !$textLength || $toLength <=
$textLength )
+ if( !$toLength || !$withStringLength || /*!$textLength || */$toLength <=
$textLength )
return $text;
- $repeat = ceil( $textLength - $withStringLength + $toLength );
+ $repeat = ceil( max( 0, $textLength - $withStringLength ) + $toLength );
if( $fromLeft ){
$result = str_repeat( $withString, $repeat );
$pos = $toLength - ( ( $textLength - $withStringLength ) +
$withStringLength );
@@ -28,7 +28,7 @@
return str_pad( $text, $toLength, $withString, STR_PAD_BOTH );
$textLength = mb_strlen( $text );
$withStringLength = mb_strlen( $withString );
- if( !$toLength || !$withStringLength || !$textLength || $toLength <=
$textLength )
+ if( !$toLength || !$withStringLength || /*!$textLength || */$toLength <=
$textLength )
return $text;
$length = ( $toLength - $textLength ) / 2;
@@ -39,4 +39,3 @@
}
}
?>
-