Levente Uzonyi uploaded a new version of Multilingual to project The Trunk:
http://source.squeak.org/trunk/Multilingual-ul.121.mcz ==================== Summary ==================== Name: Multilingual-ul.121 Author: ul Time: 22 June 2010, 6:48:58.111 pm UUID: 1293f287-5ed7-354c-9df8-d36e42ef16c0 Ancestors: Multilingual-nice.120 - use #ifNil: when possible - simplified UTF8TextConverter >> #nextFromStream:empty log message =============== Diff against Multilingual-nice.120 =============== Item was changed: ----- Method: UTF8TextConverter>>nextFromStream: (in category 'conversion') ----- nextFromStream: aStream + | character value1 value2 unicode value3 value4 | + aStream isBinary ifTrue: [ ^aStream basicNext ]. + character := aStream basicNext ifNil: [ ^nil ]. + value1 := character asciiValue. + value1 <= 127 ifTrue: [ ^character ]. "1-byte character" - | character1 value1 character2 value2 unicode character3 value3 character4 value4 | - aStream isBinary ifTrue: [^ aStream basicNext]. - character1 := aStream basicNext. - character1 isNil ifTrue: [^ nil]. - value1 := character1 asciiValue. - value1 <= 127 ifTrue: [ - "1-byte character" - ^ character1 - ]. - "at least 2-byte character" + character := aStream basicNext ifNil: [ ^self errorMalformedInput ]. + value2 := character asciiValue. - character2 := aStream basicNext. - character2 = nil ifTrue: [^self errorMalformedInput]. - value2 := character2 asciiValue. - (value1 bitAnd: 16rE0) = 192 ifTrue: [ + ^ Unicode value: ((value1 bitAnd: 31) bitShift: 6) + (value2 bitAnd: 63) ]. - ^ Unicode value: ((value1 bitAnd: 31) bitShift: 6) + (value2 bitAnd: 63). - ]. - "at least 3-byte character" + character := aStream basicNext ifNil: [ ^self errorMalformedInput ]. + value3 := character asciiValue. - character3 := aStream basicNext. - character3 = nil ifTrue: [^self errorMalformedInput]. - value3 := character3 asciiValue. (value1 bitAnd: 16rF0) = 224 ifTrue: [ unicode := ((value1 bitAnd: 15) bitShift: 12) + ((value2 bitAnd: 63) bitShift: 6) + + (value3 bitAnd: 63) ]. - + (value3 bitAnd: 63). - ]. - (value1 bitAnd: 16rF8) = 240 ifTrue: [ "4-byte character" + character := aStream basicNext ifNil: [ ^self errorMalformedInput ]. + value4 := character asciiValue. - character4 := aStream basicNext. - character4 = nil ifTrue: [^self errorMalformedInput]. - value4 := character4 asciiValue. unicode := ((value1 bitAnd: 16r7) bitShift: 18) + ((value2 bitAnd: 63) bitShift: 12) + ((value3 bitAnd: 63) bitShift: 6) + + (value4 bitAnd: 63) ]. + unicode ifNil: [ ^self errorMalformedInput ]. + unicode > 16r10FFFD ifTrue: [ ^self errorMalformedInput ]. + unicode = 16rFEFF ifTrue: [ ^self nextFromStream: aStream ]. - (value4 bitAnd: 63). - ]. - - unicode isNil ifTrue: [^self errorMalformedInput]. - unicode > 16r10FFFD ifTrue: [^self errorMalformedInput]. - - unicode = 16rFEFF ifTrue: [^ self nextFromStream: aStream]. ^ Unicode value: unicode. ! Item was changed: ----- Method: EUCTextConverter>>nextFromStream: (in category 'conversion') ----- nextFromStream: aStream | character1 character2 offset value1 value2 nonUnicodeChar | aStream isBinary ifTrue: [^ aStream basicNext]. + character1 := aStream basicNext ifNil: [^ nil]. - character1 := aStream basicNext. - character1 isNil ifTrue: [^ nil]. character1 asciiValue <= 127 ifTrue: [^ character1]. + character2 := aStream basicNext ifNil: [^ nil]. - character2 := aStream basicNext. - character2 = nil ifTrue: [^ nil]. offset := 16rA1. value1 := character1 asciiValue - offset. value2 := character2 asciiValue - offset. (value1 < 0 or: [value1 > 93]) ifTrue: [^ nil]. (value2 < 0 or: [value2 > 93]) ifTrue: [^ nil]. nonUnicodeChar := Character leadingChar: self leadingChar code: value1 * 94 + value2. ^ Character leadingChar: self languageEnvironment leadingChar code: nonUnicodeChar asUnicode. ! Item was changed: ----- Method: MultiByteFileStream>>peekFor: (in category 'public') ----- peekFor: item | next state | "self atEnd ifTrue: [^ false]. -- SFStream will give nil" state := converter saveStateOf: self. + (next := self next) ifNil: [^ false]. - (next := self next) == nil ifTrue: [^ false]. item = next ifTrue: [^ true]. converter restoreStateOf: self with: state. ^ false. ! Item was changed: ----- Method: MultiByteBinaryOrTextStream>>peekFor: (in category 'public') ----- peekFor: item | next state | "self atEnd ifTrue: [^ false]. -- SFStream will give nil" state := converter saveStateOf: self. + (next := self next) ifNil: [^ false]. - (next := self next) == nil ifTrue: [^ false]. item = next ifTrue: [^ true]. converter restoreStateOf: self with: state. ^ false. ! |
Free forum by Nabble | Edit this page |