HomePhabricator

Provide more flexible string truncation in libphutil

Description

Provide more flexible string truncation in libphutil

Summary:
Ref T3307. We sometimes need to truncate strings to a given length for display, storage, or for other reasons.

Currently, phutil_utf8_shorten() can do this for display, but because it handles combining characters it doesn't actually impose any storage limits on the result: if the input is o and 50 megabytes of combining umlauts, the output will be the same as the input, since this is only "1 display character" long.

Instead, allow truncation to specify maximum byte, codepoint (utf8 character) and glyph (display character) limits.

Test Plan: Added more unit tests.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T3307

Differential Revision: https://secure.phabricator.com/D9368

Event Timeline