unicode16.praat 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. echo Unicode
  2. # Paul Boersma, 11 March 2010
  3. # This script shouldn't just run correctly, but should also do the following things correctly:
  4. # 1. Menu command "Where am I?".
  5. # 2. Menu command "Go to line...".
  6. # 3. These can be combined by doing Command-L, then OK.
  7. # 4. Menu command "Run selection".
  8. # 5. Menu command "Paste history", both into a cursor position and overwriting.
  9. Text reading preferences... UTF-8
  10. Text writing preferences... UTF-8
  11. call test
  12. Text writing preferences... UTF-16
  13. call test
  14. Text writing preferences... try ASCII, then UTF-16
  15. call test
  16. Text writing preferences... try ISO Latin-1, then UTF-16
  17. Text reading preferences... try UTF-8, then ISO Latin-1
  18. call test
  19. #
  20. # Clean up.
  21. #
  22. Text writing preferences... try ASCII, then UTF-16
  23. if macintosh
  24. Text reading preferences... try UTF-8, then MacRoman
  25. elif windows
  26. Text reading preferences... try UTF-8, then Windows Latin-1
  27. elif unix
  28. Text reading preferences... try UTF-8, then ISO Latin-1
  29. else
  30. exit Unknown operating system.
  31. endif
  32. procedure test
  33. assert length ("éééürtüéŋəü") = 11 ; precomposed (typed into ScriptEditor)
  34. assert length ("éééürtüéŋəü") = 18 ; decomposed (copied from MacOS file icon)
  35. assert "ɦɑlou" + "ɣujədɑx" = "ɦɑlouɣujədɑx" ; BMP (Unicode values up to 0xFFFF)
  36. assert left$ ("ɦɑlou", 3) = "ɦɑl"
  37. assert "ɦɑl" <> "??l"
  38. # The text I/O commands ">", ">>", and "<":
  39. deleteFile ("kanweg.txt")
  40. text$ = "adddɦɑlouɣujədɑxdɑx"
  41. text$ > kanweg.txt
  42. text$ < kanweg.txt
  43. assert text$ = "adddɦɑlouɣujədɑxdɑx" ; <<'text$'>>
  44. text$ >> kanweg.txt
  45. text$ < kanweg.txt
  46. assert text$ = "adddɦɑlouɣujədɑxdɑxadddɦɑlouɣujədɑxdɑx" ; <<'text$'>>
  47. # ASCII appending:
  48. deleteFile ("kanweg.txt")
  49. fileappend kanweg.txt abc'newline$'
  50. fileappend kanweg.txt def'newline$'
  51. fileappend kanweg.txt ghi'newline$'
  52. text$ < kanweg.txt
  53. assert text$ = "abc" + newline$ + "def" + newline$ + "ghi" + newline$
  54. # UTF-16 appending (or UTF-8, or first ISO Latin-1 then change to UTF-16):
  55. deleteFile ("kanweg.txt")
  56. fileappend kanweg.txt åbc'newline$'
  57. fileappend kanweg.txt dëf'newline$'
  58. fileappend kanweg.txt ‘ghi’וּ'newline$'
  59. text$ < kanweg.txt
  60. assert text$ = "åbc" + newline$ + "dëf" + newline$ + "‘ghi’וּ" + newline$
  61. # Append to file first in ASCII, then change the encoding of the whole file to UTF-16 (or UTF-8):
  62. deleteFile ("kanweg.txt")
  63. fileappend kanweg.txt abc'newline$'
  64. fileappend kanweg.txt dëf'newline$'
  65. fileappend kanweg.txt ‘ghi’וּ'newline$'
  66. text$ < kanweg.txt
  67. assert text$ = "abc" + newline$ + "dëf" + newline$ + "‘ghi’וּ" + newline$
  68. assert fileReadable ("kanweg.txt")
  69. deleteFile ("kanweg.txt")
  70. assert not fileReadable ("kanweg.txt")
  71. # Unicode file names (precomposed source code):
  72. assert length ("kanweg_abcåbçéü.txt") = 19 ; hopefully not 21
  73. deleteFile ("kanweg_abcåbçéü.txt")
  74. fileappend kanweg_abcåbçéü.txt hallo
  75. assert fileReadable ("kanweg_abcåbçéü.txt")
  76. deleteFile ("kanweg_abcåbçéü.txt")
  77. assert not fileReadable ("kanweg_abcåbçéü.txt")
  78. fileappend kanweg_abcåbçéü.txt hallo
  79. text$ < kanweg_abcåbçéü.txt
  80. assert text$ = "hallo"
  81. Read from file... åbçéü.wav
  82. select Sound åbçéü
  83. info$ = Info
  84. secondLine = index (info$, "Object type")
  85. header$ = left$ (mid$ (info$, secondLine, 10000), 38)
  86. assert header$ = "Object type: Sound" + newline$ + "Object name: åbçéü" + newline$ ; 'header$'
  87. Remove
  88. textgrid = Create TextGrid... 0 1 test
  89. Set interval text... 1 1 åçé
  90. Write to text file... kanweg.TextGrid
  91. textgrid2 = Read from file... kanweg.TextGrid
  92. assert objectsAreIdentical (textgrid, textgrid2)
  93. plus textgrid
  94. Remove
  95. Create Strings as file list... list *.txt
  96. n = Get number of strings
  97. for i to n
  98. fileName$ = Get string... i
  99. assert right$ (fileName$, 4) = ".txt"
  100. length = length (fileName$)
  101. printline 'length' 'fileName$'
  102. if left$ (fileName$, 10) = "kanweg_abc"
  103. assert left$ (fileName$, 15) = "kanweg_abcåbçéü" ; 'fileName$'
  104. endif
  105. deleteFile ("kanweg_abcåbçéü.txt")
  106. endfor
  107. Remove
  108. endproc
  109. printline OK