Homec4science

Provide more flexible string truncation in libphutil

Authored by epriestley <git@epriestley.com> on Jun 20 2014, 20:47.

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

Details

Committed
epriestley <git@epriestley.com>Jun 20 2014, 20:47
Pushed
aubortMar 17 2017, 12:03
Parents
rPHU8845b0329c95: Update callsites of `phutil_json_decode`.
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPHUe0fd683ec58a: Provide more flexible string truncation in libphutil (authored by epriestley <git@epriestley.com>).Jun 20 2014, 20:47