help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] [PATCH] Miscellaneous bug fixes


From: Paolo Bonzini
Subject: [Help-smalltalk] [PATCH] Miscellaneous bug fixes
Date: Tue, 28 Aug 2007 11:30:21 +0200
User-agent: Thunderbird 2.0.0.6 (Macintosh/20070728)

Found while preparing a demo.

Paolo
Summary: miscellaneous bug fixes
Keywords:

2007-08-28  Paolo Bonzini  <address@hidden>

        * kernel/Generator.st: Add #on:do:.
        * kernel/StreamOps.st: Always delegate species, fix
        PeekableStream>>#peek.

        * packages/browser/PCode.st: Turn FIXME into a comment.

        * packages/iconv/Sets.st: Add some methods, skip BOM when converting    
    to UnicodeString.

M  kernel/Generator.st
M  kernel/StreamOps.st
M  packages/browser/PCode.st
M  packages/iconv/Sets.st

* modified files

--- orig/kernel/Generator.st
+++ mod/kernel/Generator.st
@@ -82,6 +82,13 @@ on: aBlock
     ^self new
        forkOn: aBlock; 
        yourself
+!
+
+on: aCollection do: aBlock
+    "Return a generator; for each item of aCollection, evaluate aBlock
+     passing the generator and the item."
+    ^self on: [ :gen |
+       aCollection do: [ :each | aBlock value: gen value: each ] ]
 ! !
 
 !Generator methodsFor: 'stream protocol'!


--- orig/kernel/StreamOps.st
+++ mod/kernel/StreamOps.st
@@ -323,6 +323,10 @@ on: aStream
 
 !PeekableStream methodsFor: 'basic'!
 
+species
+    ^stream species
+!
+
 name
     ^stream name
 !
@@ -352,7 +356,7 @@ peek
      Returns nil when at end of stream."
     haveLookahead ifFalse: [
        stream atEnd ifTrue: [ ^nil ].
-       haveLookahead := true. lookahead := self next ].
+       haveLookahead := true. lookahead := stream next ].
     ^lookahead
 !
 


--- orig/packages/browser/PCode.st
+++ mod/packages/browser/PCode.st
@@ -177,7 +177,7 @@ highlightBlockClosure
 highlightSyntax
     | parser |
     (source = self contents) ifFalse:
-      [ 'FIXME: this is wrong, something is being dropped elsewhere with 
respect to content updates' printNl.
+      [ "FIXME: this is wrong, something is being dropped elsewhere with 
respect to content updates"
         source:=self contents
       ].
     parser := STInST.RBParser new


--- orig/packages/iconv/Sets.st
+++ mod/packages/iconv/Sets.st
@@ -569,6 +569,9 @@ unicodeOn: aStringOrStream encoding: fro
 
     "Compose iconv-produced bytes into UTF-32 character codes if needed."
     encoderFrom == Iconv ifTrue: [ pipe := self compose: pipe from: pivot ].
+
+    "Skip the BOM, if present."
+    pipe peekFor: $<16rFEFF>.
     ^pipe
 !
 
@@ -608,7 +611,7 @@ on: aStringOrStream from: fromEncoding t
        ifTrue: [ from := aStringOrStream utf16Encoding ].
 
     (to = 'UTF-32' or: [ to = 'UCS-4' ]) ifTrue: [ to := 'UTF-32BE' ].
-    (to = 'UTF-16' or: [ to = 'UCS-2' ]) ifTrue: [ to := 'UTF-32BE' ].
+    (to = 'UTF-16' or: [ to = 'UCS-2' ]) ifTrue: [ to := 'UTF-16BE' ].
 
     pivot := 'UTF-32'.
     ((from startsWith: 'UCS-4') or: [ from startsWith: 'UTF-32' ])
@@ -1265,6 +1268,16 @@ defaultEncoding: aString
 
 !CharacterArray methodsFor: 'multibyte encodings'!
 
+asString: aString
+    "Return a String with the contents of the receiver, converted
+     into the aString locale character set."
+    ^(I18N.EncodedStream on: self from: self encoding to: aString) contents!
+
+asUnicodeString
+    "Return an UnicodeString with the contents of the receiver, interpreted
+     as the default locale character set."
+    ^(I18N.EncodedStream unicodeOn: self) contents!
+
 numberOfCharacters
     "Answer the number of Unicode characters in the receiver, interpreting it
      as the default locale character set."
@@ -1272,11 +1285,6 @@ numberOfCharacters
 
 !String methodsFor: 'multibyte encodings'!
 
-asUnicodeString
-    "Return an UnicodeString with the contents of the receiver, interpreted
-     as the default locale character set."
-    ^(I18N.EncodedStream unicodeOn: self) contents!
-
 numberOfCharacters: aString
     "Answer the number of Unicode characters in the receiver, interpreting it
      in the character encoding aString."
@@ -1402,6 +1410,12 @@ printOn: aStream
 
 !ByteArray methodsFor: 'converting'!
 
+asString: aString
+    "Return a String with the contents of the receiver, interpreted
+     as the locale character set given by aString."
+    ^self asString asUnicodeString
+!
+
 asUnicodeString
     "Return an UnicodeString with the contents of the receiver, interpreted
      as the default locale character set."




reply via email to

[Prev in Thread] Current Thread [Next in Thread]