Page MenuHomePhabricator

Provide more flexible string truncation in libphutil
ClosedPublic

Authored by epriestley on Jun 3 2014, 10:18 PM.
Tags
None
Referenced Files
F19086282: D9368.id.diff
Tue, Dec 2, 9:04 PM
F19065489: D9368.id.diff
Sun, Nov 30, 1:50 AM
F19049147: D9368.id.diff
Thu, Nov 27, 4:17 PM
F18876935: D9368.id.diff
Thu, Nov 6, 5:00 AM
F18804134: D9368.id.diff
Oct 18 2025, 6:16 AM
F18799195: D9368.diff
Oct 17 2025, 12:33 PM
F18760392: D9368.id23140.diff
Oct 6 2025, 9:09 AM
F18670942: D9368.id.diff
Sep 25 2025, 2:11 AM
Subscribers
Tokens
"Love" token, awarded by benjamin-bader.

Details

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.

Diff Detail

Repository
rPHU libphutil
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

epriestley retitled this revision from to Provide more flexible string truncation in libphutil.
epriestley updated this object.
epriestley edited the test plan for this revision. (Show Details)
epriestley added a reviewer: btrahan.
btrahan edited edge metadata.
This revision is now accepted and ready to land.Jun 3 2014, 10:23 PM
epriestley updated this revision to Diff 23140.

Closed by commit rPHUe0fd683ec58a (authored by @epriestley).