Truncate a string after a certain number of chars.
(self, length, truncate, text)
| 212 | return self._text_chars(length, truncate, text) |
| 213 | |
| 214 | def _text_chars(self, length, truncate, text): |
| 215 | """Truncate a string after a certain number of chars.""" |
| 216 | truncate_len = calculate_truncate_chars_length(length, truncate) |
| 217 | s_len = 0 |
| 218 | end_index = None |
| 219 | for i, char in enumerate(text): |
| 220 | if unicodedata.combining(char): |
| 221 | # Don't consider combining characters |
| 222 | # as adding to the string length |
| 223 | continue |
| 224 | s_len += 1 |
| 225 | if end_index is None and s_len > truncate_len: |
| 226 | end_index = i |
| 227 | if s_len > length: |
| 228 | # Return the truncated string |
| 229 | return add_truncation_text(text[: end_index or 0], truncate) |
| 230 | |
| 231 | # Return the original string since no truncation was necessary |
| 232 | return text |
| 233 | |
| 234 | def words(self, num, truncate=None, html=False): |
| 235 | """ |
no test coverage detected