Permalink
Browse files

Deprecating TextHelper::trim() as it is an alias for truncate().

Expanding use of mb_ methods.
Tests updated.
  • Loading branch information...
1 parent 190a8b8 commit 06162d5022c73bc2fdaa43e0359fdbe7cb9243b5 @markstory markstory committed Sep 29, 2009
Showing with 11 additions and 17 deletions.
  1. +10 −8 cake/libs/view/helpers/text.php
  2. +1 −9 cake/tests/cases/libs/view/helpers/text.test.php
@@ -114,8 +114,8 @@ function stripLinks($text) {
function autoLinkUrls($text, $htmlOptions = array()) {
$options = 'array(';
foreach ($htmlOptions as $option => $value) {
- $value = var_export($value, true);
- $options .= "'$option' => $value, ";
+ $value = var_export($value, true);
+ $options .= "'$option' => $value, ";
}
$options .= ')';
@@ -138,7 +138,8 @@ function autoLinkEmails($text, $htmlOptions = array()) {
$options = 'array(';
foreach ($htmlOptions as $option => $value) {
- $options .= "'$option' => '$value', ";
+ $value = var_export($value, true);
+ $options .= "'$option' => $value, ";
}
$options .= ')';
@@ -226,7 +227,7 @@ function truncate($text, $length = 100, $ending = '...', $exact = true, $conside
if (mb_strlen($text) <= $length) {
return $text;
} else {
- $truncate = mb_substr($text, 0, $length - strlen($ending));
+ $truncate = mb_substr($text, 0, $length - mb_strlen($ending));
}
}
if (!$exact) {
@@ -265,6 +266,7 @@ function truncate($text, $length = 100, $ending = '...', $exact = true, $conside
* @access public
*/
function trim() {
+ trigger_error('TextHelper::trim() is deprecated. Use TextHelper::truncate() instead', E_USER_WARNING);
$args = func_get_args();
return call_user_func_array(array(&$this, 'truncate'), $args);
}
@@ -284,26 +286,26 @@ function excerpt($text, $phrase, $radius = 100, $ending = "...") {
return $this->truncate($text, $radius * 2, $ending);
}
- $phraseLen = strlen($phrase);
+ $phraseLen = mb_strlen($phrase);
if ($radius < $phraseLen) {
$radius = $phraseLen;
}
- $pos = strpos(strtolower($text), strtolower($phrase));
+ $pos = mb_strpos(mb_strtolower($text), mb_strtolower($phrase));
$startPos = 0;
if ($pos > $radius) {
$startPos = $pos - $radius;
}
- $textLen = strlen($text);
+ $textLen = mb_strlen($text);
$endPos = $pos + $phraseLen + $radius;
if ($endPos >= $textLen) {
$endPos = $textLen;
}
- $excerpt = substr($text, $startPos, $endPos - $startPos);
+ $excerpt = mb_substr($text, $startPos, $endPos - $startPos);
if ($startPos != 0) {
$excerpt = substr_replace($excerpt, $ending, 0, $phraseLen);
}
@@ -70,10 +70,7 @@ function tearDown() {
* @return void
*/
function testTruncate() {
- if (!isset($this->method)) {
- $this->method = 'truncate';
- }
- $m = $this->method;
+ $m = 'truncate';
$text1 = 'The quick brown fox jumps over the lazy dog';
$text2 = 'Heiz&ouml;lr&uuml;cksto&szlig;abd&auml;mpfung';
$text3 = '<b>&copy; 2005-2007, Cake Software Foundation, Inc.</b><br />written by Alexander Wegener';
@@ -106,11 +103,6 @@ function testTruncate() {
$this->assertIdentical($this->Text->{$m}($text7, 255), $text7);
$this->assertIdentical($this->Text->{$m}($text7, 15), 'El moño está...');
$this->assertIdentical($this->Text->{$m}($text8, 15), 'Vive la R'.chr(195).chr(169).'pu...');
-
- if ($this->method == 'truncate') {
- $this->method = 'trim';
- $this->testTruncate();
- }
}
/**

0 comments on commit 06162d5

Please sign in to comment.