class: CharacterEncoderImplementations::ISO10646_to_UTF8
class definition
added:
#flushSingleton
#new
make class a singleton.
Preallocate more space in Stream
#theOneAndOnlyInstance
changed: #encodeString:
--- a/CharacterEncoderImplementations__ISO10646_to_UTF8.st Sat Jul 18 12:05:38 2015 +0200
+++ b/CharacterEncoderImplementations__ISO10646_to_UTF8.st Mon Jul 20 13:19:51 2015 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 2004 by eXept Software AG
All Rights Reserved
@@ -20,6 +22,13 @@
category:'Collections-Text-Encodings'
!
+ISO10646_to_UTF8 class instanceVariableNames:'theOneAndOnlyInstance'
+
+"
+ No other class instance variables are inherited by this class.
+"
+!
+
!ISO10646_to_UTF8 class methodsFor:'documentation'!
copyright
@@ -45,11 +54,41 @@
Decoding (utf8 to unicode):
|t|
- t := ISO10646_to_UTF8 encodeString:'Helloœ'.
+ t := ISO10646_to_UTF8 encodeString:'Helloœ'.
ISO10646_to_UTF8 decodeString:t.
"
! !
+!ISO10646_to_UTF8 class methodsFor:'instance creation'!
+
+flushSingleton
+ "flushes the cached singleton"
+
+ theOneAndOnlyInstance := nil
+
+ "
+ self flushSingleton
+ "
+!
+
+new
+ "returns a singleton"
+
+ theOneAndOnlyInstance isNil ifTrue:[
+ theOneAndOnlyInstance := self basicNew initialize.
+ ].
+ ^ theOneAndOnlyInstance.
+!
+
+theOneAndOnlyInstance
+ "returns a singleton"
+
+ theOneAndOnlyInstance isNil ifTrue:[
+ theOneAndOnlyInstance := self basicNew initialize.
+ ].
+ ^ theOneAndOnlyInstance.
+! !
+
!ISO10646_to_UTF8 methodsFor:'encoding & decoding'!
decode:aCode
@@ -311,12 +350,12 @@
|s|
- "/ avoid creation of new strings
+ "/ avoid creation of new strings if possible
aUnicodeString containsNon7BitAscii ifFalse:[
^ aUnicodeString asSingleByteString
].
- s := WriteStream on:(String uninitializedNew:aUnicodeString size).
+ s := WriteStream on:(String uninitializedNew:(aUnicodeString size * 3 // 2)).
aUnicodeString do:[:eachCharacter |
|codePoint "{Class: SmallInteger }" b1 b2 b3 b4 b5 v "{Class: SmallInteger }"|