Trim comment bloat in Text class.

This commit is contained in:
Taylor Otwell 2011-07-07 07:18:45 -07:00
parent 5755fdaba0
commit a2406c0174
1 changed files with 0 additions and 18 deletions

View File

@ -17,15 +17,8 @@ public static function words($value, $limit, $end = '…')
return $value; return $value;
} }
// -----------------------------------------------------
// Limit the words in the string.
// -----------------------------------------------------
preg_match('/^\s*+(?:\S++\s*+){1,'.$limit.'}/', $value, $matches); preg_match('/^\s*+(?:\S++\s*+){1,'.$limit.'}/', $value, $matches);
// -----------------------------------------------------
// If the string did not exceed the limit, we won't
// need an ending character.
// -----------------------------------------------------
if (strlen($value) == strlen($matches[0])) if (strlen($value) == strlen($matches[0]))
{ {
$end = ''; $end = '';
@ -49,9 +42,7 @@ public static function characters($value, $limit, $end = '…')
return $value; return $value;
} }
// -----------------------------------------------------
// Replace new lines and whitespace in the string. // Replace new lines and whitespace in the string.
// -----------------------------------------------------
$value = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $value)); $value = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $value));
if (strlen($value) <= $limit) if (strlen($value) <= $limit)
@ -61,10 +52,6 @@ public static function characters($value, $limit, $end = '&#8230;')
$out = ''; $out = '';
// -----------------------------------------------------
// The string exceeds the character limit. Add each word
// to the output individually until we reach the limit.
// -----------------------------------------------------
foreach (explode(' ', trim($value)) as $val) foreach (explode(' ', trim($value)) as $val)
{ {
$out .= $val.' '; $out .= $val.' ';
@ -90,14 +77,9 @@ public static function censor($value, $censored, $replacement = '####')
{ {
$value = ' '.$value.' '; $value = ' '.$value.' ';
// -----------------------------------------------------
// Assume the word will be book-ended by the following. // Assume the word will be book-ended by the following.
// -----------------------------------------------------
$delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]'; $delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]';
// -----------------------------------------------------
// Replace the censored words.
// -----------------------------------------------------
foreach ($censored as $word) foreach ($censored as $word)
{ {
if ($replacement != '') if ($replacement != '')