Merge jv
authorMerge Script
Mon, 11 Apr 2016 06:38:58 +0200
branchjv
changeset 19567 33f60845c4bc
parent 19559 d35a89d5c0ec (current diff)
parent 19566 e231bc8ea8a0 (diff)
child 19572 90f8a4a7060a
Merge
ByteArray.st
Character.st
ExternalStream.st
ReadStream.st
Stream.st
--- a/ByteArray.st	Fri Apr 08 07:02:36 2016 +0100
+++ b/ByteArray.st	Mon Apr 11 06:38:58 2016 +0200
@@ -2996,6 +2996,7 @@
     "
 ! !
 
+
 !ByteArray methodsFor:'searching'!
 
 indexOf:aByte startingAt:start
@@ -3061,6 +3062,7 @@
     "
 ! !
 
+
 !ByteArray methodsFor:'testing'!
 
 isByteArray
--- a/Character.st	Fri Apr 08 07:02:36 2016 +0100
+++ b/Character.st	Mon Apr 11 06:38:58 2016 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1988 by Claus Gittinger
 	      All Rights Reserved
@@ -1499,7 +1497,7 @@
     ^ s contents
 
     "
-     'ä' utf8Encoded 
+     'ä' utf8Encoded 
      'a' utf8Encoded 
     "
 ! !
@@ -2568,9 +2566,9 @@
 
     "
      $e asNonDiacritical
-     $é asNonDiacritical
-     $ä asNonDiacritical
-     $Ã¥ asNonDiacritical
+     $é asNonDiacritical
+     $ä asNonDiacritical
+     $å asNonDiacritical
     "
 !
 
--- a/ExternalStream.st	Fri Apr 08 07:02:36 2016 +0100
+++ b/ExternalStream.st	Mon Apr 11 06:38:58 2016 +0200
@@ -4176,15 +4176,15 @@
 nextWord
     <resource: #obsolete>
     "in text-mode:
-	 read the alphaNumeric next word (i.e. up to non letter-or-digit).
-	 return a string containing those characters.
+         read the alphaNumeric next word (i.e. up to non letter-or-digit).
+         return a string containing those characters.
      in binary-mode:
-	 read two bytes (msb-first) and return the value as a 16-bit
-	 unsigned Integer (for compatibility with other smalltalks)"
+         read two bytes (msb-first) and return the value as a 16-bit
+         unsigned Integer (for compatibility with other smalltalks)"
 
     binary ifTrue:[
-	self obsoleteMethodWarning:'use #nextUnsignedShortMSB:true'.
-	^ self nextUnsignedShortMSB:true
+        self obsoleteMethodWarning:'use #nextUnsignedShortMSB:true'.
+        ^ self nextUnsignedInt16MSB:true
     ].
     self obsoleteMethodWarning:'use #nextAlphaNumericWord'.
     ^ self nextAlphaNumericWord
--- a/ReadStream.st	Fri Apr 08 07:02:36 2016 +0100
+++ b/ReadStream.st	Mon Apr 11 06:38:58 2016 +0200
@@ -583,7 +583,7 @@
 !
 
 nextUnicode16CharacterMSB:msb
-    ^ Character value:(self nextUnsignedShortMSB:msb)
+    ^ Character value:(self nextUnsignedInt16MSB:msb)
 
     "
      #[16r00 16r51] readStream nextUnicode16CharacterMSB:true
@@ -592,6 +592,8 @@
 !
 
 nextUnicode16Characters:count MSB:msb
+    "easily tuned, if heavily used"
+    
     ^ (1 to:count) 
         collect:[:i | self nextUnicode16CharacterMSB:msb]
         as:Unicode16String
--- a/Stream.st	Fri Apr 08 07:02:36 2016 +0100
+++ b/Stream.st	Mon Apr 11 06:38:58 2016 +0200
@@ -276,6 +276,7 @@
 ! !
 
 
+
 !Stream methodsFor:'accessing'!
 
 contents
@@ -970,7 +971,7 @@
 
 nextBytesInto:anObject
     "read bytes into an object, regardless of binary/text mode.
-     The number of bytes to read is defined by the objects size.
+     The number of bytes to read is defined by the object's size.
      Return the number of bytes read. On EOF, 0 is returned.
      If the receiver is some socket/pipe-like stream, an exception
      is raised if the connection is broken.
@@ -1241,7 +1242,8 @@
 !
 
 nextNumber:numBytes 
-    "Return the next n bytes as a positive Integer; bytes are taken msb-first."
+    "Return the next n bytes as a positive Integer; 
+     bytes are taken msb-first."
 
     ^ self nextUnsigned:numBytes MSB:true
 !
@@ -1264,6 +1266,25 @@
     "
 !
 
+nextString:count
+    "read the next count bytes and return it as a string.
+     If EOF is encountered while reading, a truncated string is returned. 
+     If EOF is already reached before the first byte can be read,
+     an error is raised."
+
+    |data n|
+
+    data := String uninitializedNew:count.
+    n := self nextBytes:count into:data startingAt:1.
+    n ~~ count ifTrue:[
+        n == 0 ifTrue:[
+            ^ self pastEndRead.
+        ].
+        data := data copyTo:n
+    ].
+    ^ data
+!
+
 nextUnsigned:numBytes MSB:msbFlag
     "return a numBytes-sized unsigned (numBytes bytes) from the stream as an Integer.
      The receiver must support reading of binary bytes.
@@ -1753,8 +1774,19 @@
      Possibly pad with leading zeros.
      The receiver must support writing of binary bytes."
 
+    self nextNumber:n put:v MSB:true
+!
+
+nextNumber:n put:v MSB:msb
+    "Append to the receiver the argument, v, which is a positive Integer,
+     as the next n bytes. 
+     Bytes are written in the specified byte order. 
+     Possibly pad with leading zeros (trailing zeros, if lsb).
+     The receiver must support writing of binary bytes."
+
     |vlen "{ Class: SmallInteger }"
-     i    "{ Class: SmallInteger }"|
+     i    "{ Class: SmallInteger }"
+     bl bm bh bml bmh|
 
     "claus: this method is central in binaryStorage -
      therefore it has been tuned a bit (and needs even more tuning)"
@@ -1768,24 +1800,50 @@
         ].
         n == 2 ifTrue:[
             (v between:0 and:16rFFFF) ifTrue:[
-                self nextPutByte:(v bitShift:-8); nextPutByte:(v bitAnd:16rFF).
+                bl := (v bitAnd:16rFF).
+                bh := (v bitShift:-8) bitAnd:16rFF.
+                msb ifTrue:[
+                    self nextPutByte:bh; nextPutByte:bl.
+                ] ifFalse:[    
+                    self nextPutByte:bl; nextPutByte:bh.
+                ].    
                 ^ self
             ].
         ].
         n == 3 ifTrue:[
             (v between:0 and:16rFFFFFF) ifTrue:[
-                self nextPutByte:((v bitShift:-16) bitAnd:16rFF).
-                self nextPutByte:((v bitShift:-8) bitAnd:16rFF).
-                self nextPutByte:(v bitAnd:16rFF).
+                bl := (v bitAnd:16rFF).
+                bm := (v bitShift:-8) bitAnd:16rFF.
+                bh := (v bitShift:-16) bitAnd:16rFF.
+                msb ifTrue:[
+                    self nextPutByte:bh.
+                    self nextPutByte:bm.
+                    self nextPutByte:bl.
+                ] ifFalse:[
+                    self nextPutByte:bl.
+                    self nextPutByte:bm.
+                    self nextPutByte:bh.
+                ].    
                 ^ self
             ].
         ].
         n == 4 ifTrue:[
-            (v >= 0) ifTrue:[
-                self nextPutByte:((v bitShift:-24) bitAnd:16rFF).
-                self nextPutByte:((v bitShift:-16) bitAnd:16rFF).
-                self nextPutByte:((v bitShift:-8) bitAnd:16rFF).
-                self nextPutByte:(v bitAnd:16rFF).
+            (v between:0 and:16rFFFFFFFF) ifTrue:[
+                bl := (v bitAnd:16rFF).
+                bml := (v bitShift:-8) bitAnd:16rFF.
+                bmh := (v bitShift:-16) bitAnd:16rFF.
+                bh := (v bitShift:-24) bitAnd:16rFF.
+                msb ifTrue:[
+                    self nextPutByte:bh.
+                    self nextPutByte:bmh.
+                    self nextPutByte:bml.
+                    self nextPutByte:bl.
+                ] ifFalse:[
+                    self nextPutByte:bl.
+                    self nextPutByte:bml.
+                    self nextPutByte:bmh.
+                    self nextPutByte:bh.
+                ].
                 ^ self
             ].
         ].
@@ -1801,21 +1859,31 @@
         self error:'number too big'
     ].
 
-    "pad with leading zeros"
-    i := n.
-    [i > vlen] whileTrue:[
-        self nextPutByte:0. 
-        i := i - 1
-    ].
-
-    i == 1 ifTrue:[
-        ^ self nextPutByte:v
-    ].
-
-    [i > 0] whileTrue:[
-        self nextPutByte:(v digitAt:i). 
-        i := i - 1
-    ]
+    msb ifTrue:[
+        "pad with leading zeros"
+        i := n.
+        [i > vlen] whileTrue:[
+            self nextPutByte:0. 
+            i := i - 1
+        ].
+
+        i == 1 ifTrue:[
+            ^ self nextPutByte:v
+        ].
+
+        [i > 0] whileTrue:[
+            self nextPutByte:(v digitAt:i). 
+            i := i - 1
+        ]
+    ] ifFalse:[
+        1 to:vlen do:[:i |
+            self nextPutByte:(v digitAt:i).
+        ].    
+        "pad with trailing zeros"
+        vlen+1 to:n do:[:i |
+            self nextPutByte:0. 
+        ].
+    ].    
 
     "Modified: / 22-06-2006 / 11:31:13 / fm"
 !
@@ -1854,7 +1922,7 @@
 
 nextPutBytes:anObject
     "write bytes from an object; the number of bytes is defined by
-     the objects size.
+     the object's size.
      Return the number of bytes written or nil on error.
      The object must have non-pointer indexed instvars 
      (i.e. be a ByteArray, String, Float- or DoubleArray).     
@@ -1910,7 +1978,7 @@
 !
 
 nextPutBytesFrom:anObject
-    "write bytes from an object; the number of bytes is defined by the objects size.
+    "write bytes from an object; the number of bytes is defined by the object's size.
      Return the number of bytes written or nil on error.
      The object must have non-pointer indexed instvars 
      (i.e. be a ByteArray, String, Float- or DoubleArray).