Trim comment bloat in Text class.
This commit is contained in:
parent
5755fdaba0
commit
a2406c0174
|
@ -17,15 +17,8 @@ public static function words($value, $limit, $end = '…')
|
|||
return $value;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Limit the words in the string.
|
||||
// -----------------------------------------------------
|
||||
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]))
|
||||
{
|
||||
$end = '';
|
||||
|
@ -49,9 +42,7 @@ public static function characters($value, $limit, $end = '…')
|
|||
return $value;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Replace new lines and whitespace in the string.
|
||||
// -----------------------------------------------------
|
||||
$value = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $value));
|
||||
|
||||
if (strlen($value) <= $limit)
|
||||
|
@ -61,10 +52,6 @@ public static function characters($value, $limit, $end = '…')
|
|||
|
||||
$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)
|
||||
{
|
||||
$out .= $val.' ';
|
||||
|
@ -90,14 +77,9 @@ public static function censor($value, $censored, $replacement = '####')
|
|||
{
|
||||
$value = ' '.$value.' ';
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Assume the word will be book-ended by the following.
|
||||
// -----------------------------------------------------
|
||||
$delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]';
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Replace the censored words.
|
||||
// -----------------------------------------------------
|
||||
foreach ($censored as $word)
|
||||
{
|
||||
if ($replacement != '')
|
||||
|
|
Loading…
Reference in New Issue