OS : Linux
PHP Version : 7.4.33
Software : Apache/2.4.6 (CentOS) PHP/7.4.33
Information System : Linux apprendre2 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
Disable Function :
Functions for operating on byte str encoded as UTF-8 Note In many cases, it is better to convert to unicode, operate on the
strings, then convert back to UTF-8. unicode type can
handle many of these functions itself. For those that it doesn’t
(removing control characters from length calculations, for instance) the
code to do so with a unicode type is often simpler. Warning All of the functions in this module are deprecated. Most of them have
been replaced with functions that operate on unicode values in
kitchen.text.display. kitchen.text.utf8.utf8_valid() has
been replaced with a function in kitchen.text.misc. Deprecated Similar to textwrap.fill() but understands
utf-8 strings and doesn’t screw up lists/blocks/etc. Use kitchen.text.display.fill() instead. Deprecated Similar to textwrap.wrap() but understands
utf-8 data and doesn’t screw up lists/blocks/etc Use kitchen.text.display.wrap() instead Deprecated Detect if a string is valid utf-8 Use kitchen.text.misc.byte_string_valid_encoding() instead. Deprecated Get the textual width of a utf-8 string Use kitchen.text.display.textual_width() instead. Deprecated Return a string chopped to a given textual width Use textual_width_chop() and
textual_width() instead: Deprecated Pad a utf-8 string to fill a specified width Use byte_string_textual_width_fill() insteadUTF-8¶
>>> msg = 'く ku ら ra と to み mi'
>>> # Old way:
>>> utf8_width_chop(msg, 5)
(5, 'く ku')
>>> # New way
>>> from kitchen.text.converters import to_bytes
>>> from kitchen.text.display import textual_width, textual_width_chop
>>> (textual_width(msg), to_bytes(textual_width_chop(msg, 5)))
(5, 'く ku')