CharacterArray.st
changeset 17600 0a26280816a3
parent 17543 bb01d670ad82
child 17625 585a7eb50e65
--- a/CharacterArray.st	Wed Mar 11 17:09:49 2015 +0100
+++ b/CharacterArray.st	Wed Mar 11 17:13:49 2015 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1994 by Claus Gittinger
               All Rights Reserved
@@ -728,7 +730,6 @@
     ^ self == CharacterArray
 ! !
 
-
 !CharacterArray methodsFor:'Compatibility-ANSI'!
 
 addLineDelimiters
@@ -3428,7 +3429,42 @@
      of the programmer's concern; except when strings are passed to the outside world,
      such as wide-string ffi calls or file contents."
 
-    ^ self as:Unicode16String.
+     |sz|
+
+     sz := self size.
+
+     ^ (Unicode16String new:sz) 
+           replaceFrom:1 to:sz with:self startingAt:1;
+           yourself.
+
+    "
+        'abc' asUnicode16String
+    "
+!
+
+asUnicode16StringZ
+    "return the receiver in a two-byte per character representation.
+     Make sure that is zero terminated (last caht is 16r0000).
+     Normally, the internal ST/X representation should be transparent and not
+     of the programmer's concern; except when strings are passed to the outside world,
+     such as wide-string ffi calls or file contents."
+
+     |sz|
+
+     sz := self size.
+     (self at:sz) == (Character codePoint:0) ifTrue:[
+         ^ self.
+     ].        
+
+     ^ (Unicode16String new:sz+1) 
+           replaceFrom:1 to:sz with:self startingAt:1;
+           at:sz+1 put:(Character codePoint:0);
+           yourself.
+
+     "
+        'abc' asUnicode16StringZ
+        'abc' asUnicode16String asUnicode16StringZ
+     "
 !
 
 asUnicode32String
@@ -4205,8 +4241,8 @@
     ^ CharacterEncoder encodeString:self from:oldEncoding into:newEncoding
 
     "
-     'äüö' encodeFrom:#iso8859 into:#utf8
-     ('äüö' encodeFrom:#iso8859 into:#utf8) encodeFrom:#utf8 into:#unicode
+     'äüö' encodeFrom:#iso8859 into:#utf8
+     ('äüö' encodeFrom:#iso8859 into:#utf8) encodeFrom:#utf8 into:#unicode
     "
 !
 
@@ -4262,7 +4298,7 @@
 
     "
      'abcde1234' utf16Encoded
-     'abcdeäöüß' utf16Encoded
+     'abcdeäöüß' utf16Encoded
     "
 
     "Modified: / 11-05-2010 / 19:12:37 / cg"
@@ -4349,7 +4385,7 @@
 
     "
      'abcde1234' utf8Encoded
-     'abcdeäöüß' utf8Encoded
+     'abcdeäöüß' utf8Encoded
     "
 
     "Modified: / 11-05-2010 / 19:12:37 / cg"
@@ -6690,7 +6726,6 @@
     "
 ! !
 
-
 !CharacterArray methodsFor:'substring searching'!
 
 findRangeOfString:subString
@@ -6946,11 +6981,11 @@
     ^ exceptionBlock value
 
     "
-     'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:1 ifAbsent:0 caseSensitive:false ignoreDiacritics:true. 5
-     'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:6 ifAbsent:0 caseSensitive:false ignoreDiacritics:true. 0
-
-     'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:1 ifAbsent:0 caseSensitive:false ignoreDiacritics:false. 5
-     'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:6 ifAbsent:0 caseSensitive:false ignoreDiacritics:false. 0
+     'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:1 ifAbsent:0 caseSensitive:false ignoreDiacritics:true. 5
+     'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:6 ifAbsent:0 caseSensitive:false ignoreDiacritics:true. 0
+
+     'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:1 ifAbsent:0 caseSensitive:false ignoreDiacritics:false. 5
+     'bla depot bla dépots' indexOfSubCollection:'dep' startingAt:6 ifAbsent:0 caseSensitive:false ignoreDiacritics:false. 0
     "
 !
 
@@ -7294,11 +7329,11 @@
 !CharacterArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.576 2015-02-23 18:37:09 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.577 2015-03-11 16:13:49 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.576 2015-02-23 18:37:09 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.577 2015-03-11 16:13:49 stefan Exp $'
 ! !