P5-text-charwidth

Jul 20, 2023

Get number of occupied columns of a string on terminal

This module supplies features similar as wcwidth3 and wcswidth3 in C language.

Characters have its own width on terminal depending on locale. For example, ASCII characters occupy one column per character, east Asian fullwidth characters like Hiragana or Han Ideograph occupy two columns per character, and combining characters apperaring in ISO-8859-11 Thai, Unicode, and so on occupy zero columns per character. mbwidth gives the width of the first character of the given string and mbswidth gives the width of the whole given string.

The names of mbwidth and mbswidth came from “multibyte” versions of wcwidth and wcswidth which are “wide character” versions.

mblenstring returns number of bytes of the first character of the string. Please note that a character may consist of multiple bytes in multibyte encodings such as UTF-8, EUC-JP, EUC-KR, GB2312, or Big5.

mbwidthstring returns the width of the first character of the string. mbswidthstring returns the width of the whole string.

Parameters are to be given in locale encodings, not always in UTF-8.



Checkout these related ports:
  • Zxing-cpp - ZXing C++ Library for QR code recognition
  • Zu-hunspell - Zulu hunspell dictionaries
  • Zu-aspell - Aspell Zulu dictionary
  • Zq - Easier and faster alternative to jq
  • Zorba - General purpose C++ XQuery processor
  • Zenxml - Simple C++ XML Processing
  • Zed - Command-line tool to manage and query Zed data lakes
  • Yq - Command-line YAML and XML processor, jq wrapper for YAML/XML documents
  • Yould - Pronounceable word generator
  • Yodl - Easy to use but powerful document formatting/preparation language
  • Yi-hunspell - Yiddish hunspell dictionaries
  • Yi-aspell - Aspell Yiddish dictionary
  • Yelp-xsl - DocBook XSLT stylesheets for yelp
  • Yelp-tools - Utilities to help manage documentation for Yelp and the web
  • Ydiff - Diff readability enhancer for color terminals