--- a/ExternalBytes.st Wed Mar 23 14:38:20 2016 +0100
+++ b/ExternalBytes.st Wed Mar 23 14:50:57 2016 +0100
@@ -450,10 +450,33 @@
!
newNullTerminatedFromString:aString
- ^ ((self new:aString size+1)
- replaceBytesFrom:1 to:aString size with:aString startingAt:1)
- at:aString size+1 put:0;
- yourself
+ "allocate a null terminated string containing the chars of aString"
+
+ |nChars extBytes|
+
+ nChars := aString size.
+ self assert:(aString bitsPerCharacter == 8).
+
+ extBytes := self new:nChars+1.
+ extBytes replaceBytesFrom:1 to:nChars with:aString startingAt:1.
+ extBytes at:nChars+1 put:0.
+ ^ extBytes
+!
+
+newNullTerminatedFromWideString:aString
+ "allocate a null terminated wide string containing the chars of aString"
+
+ |nChars extBytes|
+
+ nChars := aString size.
+ self assert:(aString bitsPerCharacter <= 16).
+
+ extBytes := self new:((nChars+1)*2).
+ 1 to:nChars do:[:i |
+ extBytes unsignedInt16At:(i*2) put:(aString at:i) codePoint.
+ ].
+ extBytes unsignedInt16At:((nChars+1)*2) put:0.
+ ^ extBytes
!
unprotectedNew:numberOfBytes