Using UTF-8 on the "down low"

16 views
Skip to first unread message

Kevin Toppenberg

unread,
Mar 28, 2024, 5:04:07 PMMar 28
to Hardhats
I wanted to be about to write UTF-8 to the terminal without enabling UTF8 support for VistA in general. 

After hours of digging on this issue, and with the input of posters on the EVERYTHING MUMPS board, I have a general purpose routine that will output UTF8 chars, as per demo below

CHARDEMO ;
  USE $P:(CHSET="UTF-8")
  NEW IDX FOR IDX=9472:1:9580 DO
  . WRITE IDX,": "
  . DO UTF8WRITE^TMGSTUTL(IDX)
  . W !
  QUIT

yottadb>DO CHARDEMO^TMGTEST
-snip-
9487: ┏
9488: ┐
9489: ┑
9490: ┒
9491: ┓
9492: └
9493: ┕
9494: ┖
9495: ┗
9496: ┘
9497: ┙
9498: ┚
-snip-

UTF8WRITE^TMGSTUTL() can be see here: https://github.com/kdtop/TMGLIB/blob/master/TMGSTUTL.m

It calls GETUTF8^TMGMISC() which returns a byte string ready for output.  It can be seen here:  https://github.com/kdtop/TMGLIB/blob/master/TMGMISC.m

Along the way I had to argue with Google Bard which was kind of helpful because it pointed me in the right direction, but also VERY frustrating because it can't count the numbers of bits used in constructing UTF8 byte strings.  Wikipedia saved the day, here: https://en.wikipedia.org/wiki/UTF-8

Kevin



Reply all
Reply to author
Forward
0 new messages