Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Modification to truncate_utf8()
to support word boundary-aware chopping. The added parameter is a flag that defaults to FALSE
.
An Example:
I wish I had sextants to use to navigate this sea
(Currently, you don't want to chop to 16 chars)
with word boundary-aware truncate, this will truncate to the nearest word boundary after the length:
I wish I had
This is also helpful when people post URLs as content. (otherwise we'd end up with wrong URLs)
Comment | File | Size | Author |
---|---|---|---|
common.inc.patch.txt | 946 bytes | arnabdotorg |
Comments
Comment #1
arnabdotorg CreditAttribution: arnabdotorg commentedComment #2
Steven CreditAttribution: Steven commented- The code does not conform to the coding standards.
- It's not very flexible. A word boundary is more than just a space, it can be tons of characters.
- A string without spaces gets chopped to nothing. I'm not sure if this is desirable.
PS: Set the issue status correctly next time please.
Comment #3
arnabdotorg CreditAttribution: arnabdotorg commentedCommitted to HEAD. [this is why this is fixed]
Comment #4
arnabdotorg CreditAttribution: arnabdotorg commented- coding standards were fixed in the patch applied.
- yes, we could have a whole bunch of things for boundaries, but a space is the most "resilient", imho: (e.g. URLS, etc invalidate the use of ".", ":","/" as boundaries).
- I'd rather have correct information than mangled text.
But you're right, (2) and (3) are pretty subjective issues.
Comment #5
(not verified) CreditAttribution: commented