This module provides functions to solve 'East Asian Width' problems. This functions help to create text base UI.
Usage example
Text align right with multibyte string.
import eastasianwidth echo "hello".stringWidth # --> 5 echo "こんにちは".stringWidth # --> 10 echo "ABCDE".stringWidth # --> 10References:
- https://ja.wikipedia.org/wiki/%E6%9D%B1%E3%82%A2%E3%82%B8%E3%82%A2%E3%81%AE%E6%96%87%E5%AD%97%E5%B9%85
- http://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt
- http://www.unicode.org/reports/tr11/
- https://github.com/mattn/go-runewidth
- https://github.com/komagata/eastasianwidth
Types
EastAsianWidth = enum fullWidth = "F", halfWidth = "H", wide = "W", narrow = "Na", ambiguous = "A", neutral = "N"
Procs
proc eastAsianWidth(codePoint: int): EastAsianWidth {...}{.raises: [], tags: [].}
-
eastAsianWidth returns EastAsianWidth of code point.
Examples:
from unicode import runeAtPos doAssert 0x00003000.eastAsianWidth == fullWidth doAssert " ".runeAtPos(0).int.eastAsianWidth == fullWidth
proc stringWidth(s: string): int {...}{.raises: [], tags: [].}
-
stringWidth returns text looks width.
Examples:
doAssert "".stringWidth == 0 doAssert "abcde".stringWidth == 5 doAssert "あいうえお".stringWidth == 10