class: String
authorStefan Vogel <sv@exept.de>
Sat, 14 Mar 2015 22:36:29 +0100
changeset 17626 07cb8b1641f9
parent 17625 585a7eb50e65
child 17627 adba1b4d01c9
class: String added: #utf8Encoded #utf8EncodedOn: optimization
String.st
--- a/String.st	Sat Mar 14 22:35:37 2015 +0100
+++ b/String.st	Sat Mar 14 22:36:29 2015 +0100
@@ -507,6 +507,7 @@
 
 
 
+
 !String class methodsFor:'queries'!
 
 defaultPlatformClass
@@ -530,6 +531,7 @@
 
 
 
+
 !String methodsFor:'Compatibility-VW5.4'!
 
 asGUID
@@ -2870,6 +2872,33 @@
 ! !
 
 
+!String methodsFor:'encoding'!
+
+utf8Encoded
+    "Return my UTF-8 representation as a new String"
+
+    self contains8BitCharacters ifTrue:[
+        ^ self basicUtf8Encoded.
+    ].
+    "speed up common case"
+    ^ self.
+!
+
+utf8EncodedOn:aStream
+    "write to aStream in utf8 encoding"
+
+    self contains8BitCharacters ifTrue:[
+        aStream nextPutAllUtf8:self.
+    ].
+    "speed up common case"
+    aStream nextPutAll:self.
+
+    "
+     'abcde1234' utf8EncodedOn:('' writeStream)
+     'abcdeäöüß' utf8EncodedOn:('' writeStream)
+    "
+! !
+
 !String methodsFor:'filling & replacing'!
 
 atAllPut:aCharacter
@@ -4129,13 +4158,14 @@
 
 ! !
 
+
 !String class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.328 2015-03-02 12:13:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.329 2015-03-14 21:36:29 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.328 2015-03-02 12:13:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.329 2015-03-14 21:36:29 stefan Exp $'
 ! !