stringAt:put:size:
authorClaus Gittinger <cg@exept.de>
Thu, 18 Dec 2003 18:15:52 +0100
changeset 7812 d28a83264959
parent 7811 22e5323b414c
child 7813 3cc0b75d1684
stringAt:put:size:
UninterpretedBytes.st
--- a/UninterpretedBytes.st	Thu Dec 18 11:42:13 2003 +0100
+++ b/UninterpretedBytes.st	Thu Dec 18 18:15:52 2003 +0100
@@ -2051,6 +2051,49 @@
     "Created: / 21.1.1998 / 17:45:02 / cg"
 !
 
+stringAt:index put:aString size:maxSize
+    "copy aString to the externalBytes, starting at index up to either maxSize characters,
+     or (and including) the 0-byte, whichever is encountered first.
+     The index is a smalltalk index (i.e. 1-based)."
+
+    |remaining "{ Class: SmallInteger }"
+     i         "{ Class: SmallInteger }"|
+
+    remaining := maxSize.
+    remaining <= 0 ifTrue:[^ self].
+
+    i := index.
+    aString do:[:aChar |
+        self basicAt:i put:aChar asciiValue.
+        i := i + 1.
+        remaining := remaining - 1.
+        remaining <= 0 ifTrue:[^ self].
+    ].
+    self basicAt:i put:0.
+    ^ aString
+
+    "
+     |bytes|
+
+     bytes := ExternalBytes new:10.
+     bytes stringAt:1 put:'hello' size:3.
+     1 to:bytes size do:[:i |
+        Transcript showCR:(bytes at:i)
+     ]
+    "
+    "
+     |bytes|
+
+     bytes := ByteArray new:10 withAll:16rFF.
+     bytes stringAt:1 put:'he' size:3.
+     1 to:bytes size do:[:i |
+        Transcript showCR:(bytes at:i)
+     ]
+    "
+
+    "Created: / 21.1.1998 / 17:45:02 / cg"
+!
+
 stringAt:index size:maxSize
     "return a string starting at index up to maxSize, or a 0-byte.
      The index is a smalltalk index (i.e. 1-based)."
@@ -2132,5 +2175,5 @@
 !UninterpretedBytes class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.46 2003-05-06 12:17:01 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.47 2003-12-18 17:15:52 cg Exp $'
 ! !