71 $length = mb_strlen($string);
75 foreach (self::$specialCharsLength as $char)
77 $regexp .= $char[
'regexp'];
79 $regexp =
'/[' . $regexp .
']/';
80 preg_match_all($regexp, $string, $matches);
83 foreach ($matches[0] as $m)
85 $length += self::$specialCharsLength[$m][
'count'] - 1;
109 protected static function mb_str_pad($string, $padLength, $padString =
" ", $padType = STR_PAD_RIGHT)
111 if (method_exists(
"\Bitrix\Main\Text\UtfSafeString",
"pad"))
113 return \Bitrix\Main\Text\UtfSafeString::pad($string, $padLength, $padString, $padType);
117 $newPadLength = \Bitrix\Main\Text\BinaryString::getLength($string) - mb_strlen($string) + $padLength;
119 return str_pad($string, $newPadLength, $padString, $padType);
131 protected static function reduceString($string, $currLength, $needLength)
133 if ($currLength <= $needLength)
138 $cropLength = $currLength - $needLength + mb_strlen(self::END_STRING);
139 $substrLength = mb_strlen($string) - $cropLength;
143 if($substrLength <= 0 )
145 $maxSpecialCharLength = 1;
146 foreach(self::$specialCharsLength as $char)
148 $maxSpecialCharLength = max($maxSpecialCharLength, $char[
'count']);
151 $substrLength = floor($needLength / $maxSpecialCharLength);
154 return mb_substr($string, 0, $substrLength).self::END_STRING;