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)

CommentFileSizeAuthor
common.inc.patch.txt946 bytesarnabdotorg
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arnabdotorg’s picture

Steven’s picture

- 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.

arnabdotorg’s picture

Committed to HEAD. [this is why this is fixed]

arnabdotorg’s picture

- 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.

Anonymous’s picture