21476
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
8903
|
3 |
"
|
|
4 |
COPYRIGHT (c) 2005 by eXept Software AG
|
|
5 |
All Rights Reserved
|
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
|
14 |
"{ Package: 'stx:libbasic' }"
|
|
15 |
|
|
16 |
"{ NameSpace: CharacterEncoderImplementations }"
|
|
17 |
|
|
18 |
ISO10646_to_UTF16BE subclass:#ISO10646_to_UTF16LE
|
|
19 |
instanceVariableNames:''
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'Collections-Text-Encodings'
|
|
23 |
!
|
|
24 |
|
|
25 |
!ISO10646_to_UTF16LE class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 2005 by eXept Software AG
|
|
30 |
All Rights Reserved
|
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
|
41 |
documentation
|
|
42 |
"
|
|
43 |
encodes/decodes UTF16 LittleEndian (little-end-first)
|
21302
|
44 |
|
|
45 |
Notice the naming (many are confused):
|
|
46 |
Unicode is the set of number-to-glyph assignments
|
|
47 |
whereas:
|
|
48 |
UTF8, UTF16 etc. are a concrete way of xmitting Unicode codePoints (numbers).
|
|
49 |
|
|
50 |
ST/X NEVER uses UTF8 or UTF16 internally - all characters are full 24bit characters.
|
|
51 |
Only when exchanging data, are these converted into UTF8 (or other) byte sequences.
|
8903
|
52 |
"
|
9326
|
53 |
!
|
|
54 |
|
|
55 |
examples
|
|
56 |
"
|
|
57 |
Encoding (unicode to utf16LE)
|
|
58 |
ISO10646_to_UTF16LE encodeString:'hello'.
|
|
59 |
|
|
60 |
|
|
61 |
Decoding (utf16LE to unicode):
|
|
62 |
|t|
|
|
63 |
|
22473
|
64 |
t := ISO10646_to_UTF16LE encodeString:'ÄÖÜäöüß'.
|
9326
|
65 |
ISO10646_to_UTF16LE decodeString:t.
|
|
66 |
|
|
67 |
Decoding (utf16LE-Bytes to unicode):
|
|
68 |
|bytes|
|
|
69 |
|
|
70 |
bytes := #[ 16r40 0 16r41 0 16r42 0 16r43 0 16r44 0 ].
|
|
71 |
ISO10646_to_UTF16LE decodeString:bytes.
|
|
72 |
"
|
8903
|
73 |
! !
|
|
74 |
|
14171
|
75 |
!ISO10646_to_UTF16LE methodsFor:'encoding & decoding'!
|
|
76 |
|
|
77 |
decode:codePoint
|
|
78 |
^ codePoint swapBytes
|
|
79 |
!
|
|
80 |
|
|
81 |
encode:codePoint
|
|
82 |
^ codePoint swapBytes
|
21476
|
83 |
!
|
|
84 |
|
22473
|
85 |
encodeString:aUnicodeString
|
|
86 |
"return the UTF-16 representation of a aUnicodeString.
|
|
87 |
The resulting string is only useful to be stored on some external file,
|
|
88 |
not for being used inside ST/X."
|
|
89 |
|
|
90 |
|stream size "{ Class:SmallInteger }"|
|
21476
|
91 |
|
22473
|
92 |
size := aUnicodeString size.
|
24215
|
93 |
stream := WriteStream on:(ByteArray uninitializedNew:size * 2).
|
21476
|
94 |
|
22473
|
95 |
1 to:size do:[:idx |
|
|
96 |
stream nextPutUtf16Bytes:(aUnicodeString at:idx) MSB:false.
|
|
97 |
].
|
|
98 |
|
|
99 |
^ stream contents
|
|
100 |
|
|
101 |
"Created: / 16-01-2018 / 19:45:15 / stefan"
|
24215
|
102 |
"Modified: / 28-05-2019 / 13:50:22 / Stefan Vogel"
|
21476
|
103 |
!
|
|
104 |
|
|
105 |
encodeString:aUnicodeString on:aStream
|
|
106 |
"given a string in unicode, encode it onto aStream."
|
|
107 |
|
|
108 |
aStream nextPutAllUtf16Bytes:aUnicodeString MSB:false.
|
|
109 |
|
|
110 |
"Created: / 16-02-2017 / 16:42:36 / stefan"
|
14171
|
111 |
! !
|
|
112 |
|
8903
|
113 |
!ISO10646_to_UTF16LE methodsFor:'private'!
|
|
114 |
|
|
115 |
nextTwoByteValueFrom:aStream
|
19216
|
116 |
^ aStream nextUnsignedInt16MSB:false
|
8903
|
117 |
! !
|
|
118 |
|
|
119 |
!ISO10646_to_UTF16LE methodsFor:'queries'!
|
|
120 |
|
|
121 |
nameOfEncoding
|
14171
|
122 |
^ #utf16le
|
8903
|
123 |
! !
|
|
124 |
|
22473
|
125 |
!ISO10646_to_UTF16LE methodsFor:'stream support'!
|
|
126 |
|
|
127 |
encodeCharacter:aUnicodeCharacter on:aStream
|
|
128 |
"given a character in unicode, encode it onto aStream."
|
|
129 |
|
|
130 |
aStream nextPutUtf16Bytes:aUnicodeCharacter MSB:false.
|
|
131 |
|
|
132 |
"Created: / 16-02-2017 / 16:42:19 / stefan"
|
|
133 |
"Modified (comment): / 16-01-2018 / 19:22:50 / stefan"
|
|
134 |
! !
|
|
135 |
|
8903
|
136 |
!ISO10646_to_UTF16LE class methodsFor:'documentation'!
|
|
137 |
|
|
138 |
version
|
19216
|
139 |
^ '$Header$'
|
8903
|
140 |
! !
|
19216
|
141 |
|