简体   繁体   中英

UTF8-aware printf?

AFAIK, strings in OCaml are just plain sequences of bytes. They have no notion of encoding.

This is fine for most purposes. However, some pieces of standard library make assumptions about the string being encoded in a single-byte charset, for example the aligning features of printf :

# printf "[%4s]\n[%4s]\n" "a" "à";;
[   a]
[  à]
- : unit = ()

Is there an upgraded printf somewhere that deals with this correctly, for example by looking at LANG and LC_* to guess the encoding being used on the terminal? (I'm using Core)

如果需要打印UTF-8数据,则可以使用Uuseg漂亮打印机

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM