A new version of JSON was added to project The Inbox: http://source.squeak.org/inbox/JSON-ul.57.mcz
==================== Summary ====================
Name: JSON-ul.57 Author: ul Time: 29 October 2023, 6:42:54.166011 pm UUID: c4b6cadf-54b3-40b2-8099-2ec44c498bc8 Ancestors: JSON-ul.56
- parse negative zero as negative zero with any exponent - the convenience methods String >> #parseAsJson and #parseAsOrderedJson will raise an error unless all the bytes of the input string have been consumed during parsing
=============== Diff against JSON-ul.56 ===============
Item was changed: ----- Method: JsonNumberParser>>nextNumber: (in category 'parsing-public') ----- nextNumber: negative
| numberOfTrailingZeroInIntegerPart oldLeadingZeroesAllowed numberOfTrailingZeroInFractionPart numberOfNonZeroFractionDigits mantissa value | integerPart := self nextUnsignedIntegerOrNil ifNil: [ ^self error: 'Missing integer part!!' ]. numberOfTrailingZeroInIntegerPart := nDigits - lastNonZero. (sourceStream peekFor: $.) ifFalse: [ "No fraction part" negative ifTrue: [ integerPart := integerPart negated ]. self readExponent ifFalse: [ ^integerPart ]. exponent > 0 ifTrue: [ ^integerPart * (self fiveRaisedTo: exponent) bitShift: exponent ]. ^self makeFloatFromMantissa: integerPart exponent: exponent ]. oldLeadingZeroesAllowed := leadingZeroesAllowed. leadingZeroesAllowed := true. fractionPart := self nextUnsignedIntegerOrNil. leadingZeroesAllowed := oldLeadingZeroesAllowed. fractionPart ifNil: [ self error: 'Missing fraction part!!' ]. fractionPart isZero ifTrue: [ + value := self readExponent + ifFalse: [ integerPart ] + ifTrue: [ + exponent >= 0 + ifTrue: [ integerPart * (self fiveRaisedTo: exponent) bitShift: exponent ] + ifFalse: [ self makeFloatFromMantissa: integerPart exponent: exponent ] ]. + negative ifFalse: [ ^value ]. + value isZero ifTrue: [ ^Float negativeZero ]. + ^value negated ]. - self readExponent ifFalse: [ - negative ifTrue: [ - integerPart isZero ifTrue: [ ^Float negativeZero ]. - ^integerPart negated ]. - ^integerPart ]. - exponent >= 0 ifTrue: [ - negative ifTrue: [ integerPart := integerPart negated ]. - ^integerPart * (self fiveRaisedTo: exponent) bitShift: exponent ]. - value := self makeFloatFromMantissa: integerPart exponent: exponent. - negative ifTrue: [ ^value negated ]. - ^value ]. numberOfTrailingZeroInFractionPart := nDigits - lastNonZero. numberOfNonZeroFractionDigits := lastNonZero. self readExponent. exponent := exponent - numberOfNonZeroFractionDigits. mantissa := (integerPart * (self fiveRaisedTo: numberOfNonZeroFractionDigits) bitShift: numberOfNonZeroFractionDigits) + (fractionPart // (self fiveRaisedTo: numberOfTrailingZeroInFractionPart) bitShift: 0 - numberOfTrailingZeroInFractionPart). value := self makeFloatFromMantissa: mantissa exponent: exponent. negative ifTrue: [ ^value negated ]. ^value!
Item was changed: ----- Method: String>>parseAsJson (in category '*JSON') ----- parseAsJson "Convenience"
+ ^self parseAsJsonWithDictionaryClass: nil! - ^Json readFrom: self readStream!
Item was added: + ----- Method: String>>parseAsJsonWithDictionaryClass: (in category '*JSON') ----- + parseAsJsonWithDictionaryClass: aClassOrNil + "Convenience" + + | input parser result | + parser := Json new. + aClassOrNil ifNotNil: [ parser dictionaryClass: aClassOrNil ]. + input := self readStream. + result := parser readFrom: input. + input atEnd ifFalse: [ parser invalid: 'Unexpected data at end of input' ]. + ^result!
Item was changed: ----- Method: String>>parseAsOrderedJson (in category '*JSON') ----- parseAsOrderedJson "Convenience"
+ ^self parseAsJsonWithDictionaryClass: OrderedJsonObject! - ^Json new - dictionaryClass: OrderedJsonObject; - readFrom: self readStream!
+1 Am 29.10.2023 19:44:04 schrieb commits@source.squeak.org commits@source.squeak.org: A new version of JSON was added to project The Inbox: http://source.squeak.org/inbox/JSON-ul.57.mcz
==================== Summary ====================
Name: JSON-ul.57 Author: ul Time: 29 October 2023, 6:42:54.166011 pm UUID: c4b6cadf-54b3-40b2-8099-2ec44c498bc8 Ancestors: JSON-ul.56
- parse negative zero as negative zero with any exponent - the convenience methods String >> #parseAsJson and #parseAsOrderedJson will raise an error unless all the bytes of the input string have been consumed during parsing
=============== Diff against JSON-ul.56 ===============
Item was changed: ----- Method: JsonNumberParser>>nextNumber: (in category 'parsing-public') ----- nextNumber: negative
| numberOfTrailingZeroInIntegerPart oldLeadingZeroesAllowed numberOfTrailingZeroInFractionPart numberOfNonZeroFractionDigits mantissa value | integerPart := self nextUnsignedIntegerOrNil ifNil: [ ^self error: 'Missing integer part!!' ]. numberOfTrailingZeroInIntegerPart := nDigits - lastNonZero. (sourceStream peekFor: $.) ifFalse: [ "No fraction part" negative ifTrue: [ integerPart := integerPart negated ]. self readExponent ifFalse: [ ^integerPart ]. exponent > 0 ifTrue: [ ^integerPart * (self fiveRaisedTo: exponent) bitShift: exponent ]. ^self makeFloatFromMantissa: integerPart exponent: exponent ]. oldLeadingZeroesAllowed := leadingZeroesAllowed. leadingZeroesAllowed := true. fractionPart := self nextUnsignedIntegerOrNil. leadingZeroesAllowed := oldLeadingZeroesAllowed. fractionPart ifNil: [ self error: 'Missing fraction part!!' ]. fractionPart isZero ifTrue: [ + value := self readExponent + ifFalse: [ integerPart ] + ifTrue: [ + exponent >= 0 + ifTrue: [ integerPart * (self fiveRaisedTo: exponent) bitShift: exponent ] + ifFalse: [ self makeFloatFromMantissa: integerPart exponent: exponent ] ]. + negative ifFalse: [ ^value ]. + value isZero ifTrue: [ ^Float negativeZero ]. + ^value negated ]. - self readExponent ifFalse: [ - negative ifTrue: [ - integerPart isZero ifTrue: [ ^Float negativeZero ]. - ^integerPart negated ]. - ^integerPart ]. - exponent >= 0 ifTrue: [ - negative ifTrue: [ integerPart := integerPart negated ]. - ^integerPart * (self fiveRaisedTo: exponent) bitShift: exponent ]. - value := self makeFloatFromMantissa: integerPart exponent: exponent. - negative ifTrue: [ ^value negated ]. - ^value ]. numberOfTrailingZeroInFractionPart := nDigits - lastNonZero. numberOfNonZeroFractionDigits := lastNonZero. self readExponent. exponent := exponent - numberOfNonZeroFractionDigits. mantissa := (integerPart * (self fiveRaisedTo: numberOfNonZeroFractionDigits) bitShift: numberOfNonZeroFractionDigits) + (fractionPart // (self fiveRaisedTo: numberOfTrailingZeroInFractionPart) bitShift: 0 - numberOfTrailingZeroInFractionPart). value := self makeFloatFromMantissa: mantissa exponent: exponent. negative ifTrue: [ ^value negated ]. ^value!
Item was changed: ----- Method: String>>parseAsJson (in category '*JSON') ----- parseAsJson "Convenience"
+ ^self parseAsJsonWithDictionaryClass: nil! - ^Json readFrom: self readStream!
Item was added: + ----- Method: String>>parseAsJsonWithDictionaryClass: (in category '*JSON') ----- + parseAsJsonWithDictionaryClass: aClassOrNil + "Convenience" + + | input parser result | + parser := Json new. + aClassOrNil ifNotNil: [ parser dictionaryClass: aClassOrNil ]. + input := self readStream. + result := parser readFrom: input. + input atEnd ifFalse: [ parser invalid: 'Unexpected data at end of input' ]. + ^result!
Item was changed: ----- Method: String>>parseAsOrderedJson (in category '*JSON') ----- parseAsOrderedJson "Convenience"
+ ^self parseAsJsonWithDictionaryClass: OrderedJsonObject! - ^Json new - dictionaryClass: OrderedJsonObject; - readFrom: self readStream!
squeak-dev@lists.squeakfoundation.org