Page MenuHomePhabricator

Provide more flexible string truncation in libphutil
ClosedPublic

Authored by epriestley on Jun 3 2014, 10:18 PM.
Tags
None
Referenced Files
F14597248: D9368.diff
Wed, Jan 8, 8:24 PM
Unknown Object (File)
Sat, Jan 4, 2:18 AM
Unknown Object (File)
Fri, Dec 27, 4:44 PM
Unknown Object (File)
Fri, Dec 27, 4:34 PM
Unknown Object (File)
Sat, Dec 21, 1:26 PM
Unknown Object (File)
Dec 9 2024, 12:03 AM
Unknown Object (File)
Dec 8 2024, 2:12 PM
Unknown Object (File)
Dec 8 2024, 7:39 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
Branch
utf81
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 837
Build 837: [Placeholder Plan] Wait for 30 Seconds

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