Changeset View
Changeset View
Standalone View
Standalone View
src/utils/PhutilUTF8StringTruncator.php
<?php | <?php | ||||
/** | /** | ||||
* Truncate a UTF-8 string to a some maximum number of bytes, codepoints, or | * Truncate a UTF-8 string to a some maximum number of bytes, codepoints, or | ||||
* glyphs. | * glyphs. | ||||
* | * | ||||
* This class takes some UTF-8 string as input, and emits a valid UTF-8 string | * This class takes some UTF-8 string as input, and emits a valid UTF-8 string | ||||
* which is no longer than given byte, codepoint, or glyph limits. | * which is no longer than given byte, codepoint, or glyph limits. | ||||
* | * | ||||
* $short = id(new PhutilUTF8StringTruncator()) | * $short = (new PhutilUTF8StringTruncator()) | ||||
* ->setMaximumGlyphs(80) | * ->setMaximumGlyphs(80) | ||||
* ->truncateString($long); | * ->truncateString($long); | ||||
* | * | ||||
* Byte limits restrict the number of bytes the result may contain. They are | * Byte limits restrict the number of bytes the result may contain. They are | ||||
* appropriate when you care about how much storage a string requires. | * appropriate when you care about how much storage a string requires. | ||||
* | * | ||||
* Codepoint limits restrict the number of codepoints the result may contain. | * Codepoint limits restrict the number of codepoints the result may contain. | ||||
* Since codepoints may have up to 4 bytes, the resulting strings may require | * Since codepoints may have up to 4 bytes, the resulting strings may require | ||||
▲ Show 20 Lines • Show All 277 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0