On Sun, 2007-11-04 at 14:00 +0100, Robin Redeker wrote: > And indeed, skipping the iconv step would just test the JSON parser > itself. In my application that uses the JSON parser I actually can't > skip that step as I get the data from the network and have to run it > through iconv anyways.
I don't mean the input; of course that should be iconved. I'm referring
to the data structures produced by the program.
A UnicodeString, if written out, may do the conversion anyway in a way
similar to how it's done now; however, it will also first ask whether
the stream supports UnicodeString handling, in which case it'll rely on
the stream to recode it properly.
With the attached patch and removing use of "outputEncoding" from the
example, I got 2/22/3 with a great reduction in outliers (opposed to
5/34/14 before).
Let me know if you like it and I'll add it to my archive.
--
Our last-ditch plan is to change the forums into a podcast, then send
RSS feeds into the blogosphere so our users can further debate the
legality of mashups amongst this month's 20 'sexiest' gadgets.
--Richard "Lowtax" Kyanka
--- orig/examples/JSON.st
+++ mod/examples/JSON.st
@@ -76,14 +76,14 @@
!
on: aStream
- ^self on: aStream outputEncoding: String defaultEncoding
-!
-
-on: aStream outputEncoding: encString
| str |
str := aStream.
aStream isUnicode ifFalse: [ str := I18N.EncodedStream unicodeOn: str ].
- ^self new stream: str; outputEncoding: encString; yourself
+ ^self new stream: str; yourself
+!
+
+on: aStream outputEncoding: encString
+ ^(self on: aStream) outputEncoding: encString; yourself
! !
!JSONReader methodsFor: 'json'!
@@ -185,7 +185,7 @@
nextJSONString
"I'm extracting a JSON string from self and return them as String."
| c obj str |
- str := ReadWriteStream on: UnicodeString new.
+ str := WriteStream on: (UnicodeString new: 8).
self next.
[
c := stream next.
@@ -210,7 +210,9 @@
"Same as 'str contents asString: self outputEncoding', a little more efficient."
"str reset. ^(I18N.EncodedStream encoding: str as: self outputEncoding) contents"
- ^str contents asString: self outputEncoding
+ ^self outputEncoding isNil
+ ifTrue: [^str contents]
+ ifFalse: [str contents asString: self outputEncoding]
!
nextJSONNumber
signature.asc
Description: This is a digitally signed message part
_______________________________________________ help-smalltalk mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-smalltalk
