15944
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2006 by eXept Software AG
|
23107
|
3 |
COPYRIGHT (c) 2009 Jan Vrany
|
15944
|
4 |
All Rights Reserved
|
|
5 |
|
|
6 |
This software is furnished under a license and may be used
|
|
7 |
only in accordance with the terms of that license and with the
|
|
8 |
inclusion of the above copyright notice. This software may not
|
|
9 |
be provided or otherwise made available to, or used by, any
|
|
10 |
other person. No title to or ownership of the software is
|
|
11 |
hereby transferred.
|
|
12 |
"
|
|
13 |
"{ Package: 'stx:libbasic' }"
|
|
14 |
|
|
15 |
"{ NameSpace: CharacterEncoderImplementations }"
|
|
16 |
|
|
17 |
TwoByteEncoder subclass:#ISO10646_to_JavaText
|
|
18 |
instanceVariableNames:''
|
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Collections-Text-Encodings'
|
|
22 |
!
|
|
23 |
|
|
24 |
!ISO10646_to_JavaText class methodsFor:'documentation'!
|
|
25 |
|
|
26 |
copyright
|
|
27 |
"
|
|
28 |
COPYRIGHT (c) 2006 by eXept Software AG
|
23107
|
29 |
COPYRIGHT (c) 2009 Jan Vrany
|
15944
|
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 |
Translates \uXXXX-escapes in the text
|
|
44 |
"
|
|
45 |
! !
|
|
46 |
|
|
47 |
!ISO10646_to_JavaText methodsFor:'encoding & decoding'!
|
|
48 |
|
|
49 |
decode:aCode
|
|
50 |
self shouldNotImplement "/ no single byte conversion possible
|
|
51 |
!
|
|
52 |
|
|
53 |
decodeString:aStringOrByteCollection
|
|
54 |
"given a string in JavaText encoding (i.e. with \uXXXX escaped characters),
|
|
55 |
return a new string containing the same characters, in 16bit (or more) encoding.
|
|
56 |
Returns either a normal String, a TwoByteString or a FourByteString instance.
|
|
57 |
Only useful, when reading Java property and resource files.
|
|
58 |
This only handles up-to 30bit characters."
|
|
59 |
|
|
60 |
|nBits ch
|
|
61 |
in out codePoint t|
|
|
62 |
|
|
63 |
nBits := 8.
|
|
64 |
in := aStringOrByteCollection readStream.
|
|
65 |
out := WriteStream on:(String new:10).
|
|
66 |
[in atEnd] whileFalse:[
|
|
67 |
ch := in next.
|
|
68 |
ch == $\ ifTrue:[
|
|
69 |
in peekOrNil == $u ifTrue:[
|
|
70 |
in next.
|
|
71 |
codePoint := 0.
|
|
72 |
4 timesRepeat:[
|
|
73 |
ch := in peekOrNil.
|
|
74 |
codePoint := (codePoint * 16) + ch digitValue.
|
|
75 |
in next.
|
|
76 |
].
|
|
77 |
codePoint > 16rFF ifTrue:[
|
|
78 |
codePoint > 16rFFFF ifTrue:[
|
|
79 |
nBits < 32 ifTrue:[
|
|
80 |
t := out contents.
|
|
81 |
out := WriteStream on:(Unicode32String fromString:t).
|
|
82 |
out position:t size.
|
|
83 |
nBits := 32.
|
|
84 |
]
|
|
85 |
] ifFalse:[
|
|
86 |
nBits < 16 ifTrue:[
|
|
87 |
t := out contents.
|
|
88 |
out := WriteStream on:(Unicode16String fromString:t).
|
|
89 |
out position:t size.
|
|
90 |
nBits := 16.
|
|
91 |
]
|
|
92 |
]
|
|
93 |
].
|
|
94 |
out nextPut:(Character value:codePoint).
|
|
95 |
] ifFalse:[
|
|
96 |
out nextPut:ch
|
|
97 |
]
|
|
98 |
] ifFalse:[
|
|
99 |
out nextPut:ch
|
|
100 |
].
|
|
101 |
].
|
|
102 |
^ out contents
|
|
103 |
|
|
104 |
"
|
|
105 |
CharacterEncoderImplementations::ISO10646_to_JavaText
|
|
106 |
decodeString:'AB\u1234CD'
|
|
107 |
"
|
|
108 |
|
|
109 |
"Modified: / 23-10-2006 / 13:23:18 / cg"
|
|
110 |
!
|
|
111 |
|
|
112 |
encode:aCode
|
|
113 |
self shouldNotImplement "/ no single byte conversion possible
|
|
114 |
!
|
|
115 |
|
|
116 |
encodeString:aUnicodeString
|
|
117 |
"return the JavaText representation of aUnicodeString.
|
|
118 |
The resulting string is only useful to be stored on some external file,
|
|
119 |
not for being used inside ST/X."
|
|
120 |
|
|
121 |
|ch in out codePoint|
|
|
122 |
|
|
123 |
in := aUnicodeString readStream.
|
|
124 |
out := WriteStream on:(String new:10).
|
|
125 |
[in atEnd] whileFalse:[
|
|
126 |
ch := in next.
|
|
127 |
codePoint := ch codePoint.
|
|
128 |
(codePoint between:16r20 and:16r7F) ifTrue:[
|
|
129 |
out nextPut:ch.
|
|
130 |
] ifFalse:[
|
|
131 |
out nextPutAll:'\u'.
|
|
132 |
out nextPutAll:((codePoint printStringRadix:16) leftPaddedTo:4 with:$0).
|
|
133 |
].
|
|
134 |
].
|
|
135 |
^ out contents
|
|
136 |
|
|
137 |
"
|
|
138 |
CharacterEncoderImplementations::ISO10646_to_JavaText
|
|
139 |
encodeString:'hello '
|
|
140 |
|
|
141 |
CharacterEncoderImplementations::ISO10646_to_JavaText
|
|
142 |
decodeString:(CharacterEncoderImplementations::ISO10646_to_JavaText encodeString:'hello ')
|
|
143 |
"
|
|
144 |
|
|
145 |
"Modified: / 23-10-2006 / 13:25:03 / cg"
|
|
146 |
! !
|
|
147 |
|
|
148 |
!ISO10646_to_JavaText class methodsFor:'documentation'!
|
|
149 |
|
|
150 |
version
|
|
151 |
^ '$Header: /cvs/stx/stx/libbasic/CharacterEncoderImplementations__ISO10646_to_JavaText.st,v 1.1 2014-02-05 17:11:06 cg Exp $'
|
|
152 |
!
|
|
153 |
|
|
154 |
version_CVS
|
|
155 |
^ '$Header: /cvs/stx/stx/libbasic/CharacterEncoderImplementations__ISO10646_to_JavaText.st,v 1.1 2014-02-05 17:11:06 cg Exp $'
|
|
156 |
! !
|
|
157 |
|