OpenVMS Source Code Demos
UNICODE_TESTING
1000 !=======================================================================
! title : unicode_testing_100.bas
! author : Neil Rieck
! history: effort to develop two new functions
! ver who when what
! 100 NSR 170315 1. original effort to develop two new functions
!=======================================================================
option type=explicit !
external long function mixed_to_unicode(string, long dim()) !
external string function unicode_to_utf8(long dim()) !
!
declare string mixed$ !
declare long u(1024) ! is this too large?
declare string utf8$ !
declare long i,j,k !
!=======================================================================
! main
!=======================================================================
main: !
print "---test 001---"
mixed$ = "this is a test" !
mat u=ZER !
j = mixed_to_unicode(mixed$,u()) !
for i=1 to j !
print "i=";i;" ";u(i) !
next i !
!=======================================================================
print "---test 002---"
mixed$ = "" !
for i=1 to 255 !
mixed$ = mixed$ + chr$(i) !
next i !
j = mixed_to_unicode(mixed$,u())
for i=1 to j !
print "i=";i;" ";u(i) !
next i !
!=======================================================================
print "---test 003---"
mixed$ = chr$(x"C2") + chr$(x"A2") ! cent symbol
j = mixed_to_unicode(mixed$,u()) !
for i=1 to j !
print "i=";i;" ";u(i);" (expected 162)" !
next i !
!=======================================================================
print "---test 004---"
mixed$ = chr$(x"E2") + chr$(x"82") + chr$(x"AC") ! Euro symbol
j = mixed_to_unicode(mixed$,u()) !
for i=1 to j !
print "i=";i;" ";u(i);" (expected 8364)" !
next i !
!=======================================================================
print "---test 005---"
mixed$ = chr$(x"f0") + chr$(x"90") + chr$(x"8d") + chr$(x"88") ! Hwair symbol
j = mixed_to_unicode(mixed$,u()) !
for i=1 to j !
print "i=";i;" ";u(i);" (expected 66376)" !
next i !
!=======================================================================
print "---test 013---"
u(0) = 1 ! only passing one value
u(i) = 65 !
utf8$ = unicode_to_utf8(u()) !
for i=1 to len(utf8$) !
print "i=";i;" ";asc(mid$(utf8$,i,1)) !
next i !
print "expected 65"
!=======================================================================
print "---test 014---"
u(0) = 1 ! only passing one value
u(1) = 162 !
utf8$ = unicode_to_utf8(u()) !
for i=1 to len(utf8$) !
print "i=";i;" ";asc(mid$(utf8$,i,1)) !
next i !
print "expected 194 162"
!=======================================================================
print "---test 015---"
u(0) = 1 ! only passing one value
u(1) = 8364 !
utf8$ = unicode_to_utf8(u()) !
for i=1 to len(utf8$) !
print "i=";i;" ";asc(mid$(utf8$,i,1)) !
next i !
! print "expected 194 162"
!=======================================================================
print "---test 016---"
u(0) = 1 ! only passing one value
u(1) = 66376 !
utf8$ = unicode_to_utf8(u()) !
for i=1 to len(utf8$) !
print "i=";i;" ";asc(mid$(utf8$,i,1)) !
next i !
! print "expected 194 162"
!=======================================================================
print "-i-exiting"
32000 end !
!
32010 %include "mixed_to_unicode.fun"
!
32020 %include "unicode_to_utf8.fun"
!