Page MenuHomePhabricator

Provide more flexible string truncation in libphutil
ClosedPublic

Authored by epriestley on Jun 3 2014, 10:18 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Apr 24, 10:20 PM
Unknown Object (File)
Fri, Apr 19, 7:17 AM
Unknown Object (File)
Fri, Apr 19, 7:17 AM
Unknown Object (File)
Thu, Apr 11, 12:10 PM
Unknown Object (File)
Tue, Apr 2, 8:36 PM
Unknown Object (File)
Mar 10 2024, 12:02 AM
Unknown Object (File)
Feb 12 2024, 5:24 PM
Unknown Object (File)
Feb 6 2024, 3:02 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).