While adding multiple character encoding support to Soup, I needed a
windows-1252/cp-1252 text converter so I wrote CP1252TextConverter (attached). Seems to work OK, though I've not tested it much. It seems like I'm reinventing the wheel. Is there a package with additional text converters available? If not, is a Mantis enhancement against the Multilingual project the best way to submit this? Thanks, Zulq. 'From Squeak3.10.2 of ''5 June 2008'' [latest update: #7179] on 30 December 2008 at 3:33:49 am'! TextConverter subclass: #CP1252TextConverter instanceVariableNames: '' classVariableNames: 'FromTable ToTable' poolDictionaries: '' category: 'Multilingual-TextConversion'! !CP1252TextConverter methodsFor: 'as yet unclassified' stamp: 'za 12/30/2008 02:40'! fromSqueak: aCharacter ^ FromTable at: aCharacter charCode ifAbsent: [aCharacter asciiValue]! ! !CP1252TextConverter methodsFor: 'as yet unclassified' stamp: 'za 12/30/2008 02:41'! nextFromStream: aStream | character | aStream isBinary ifTrue: [^ aStream basicNext]. character := aStream basicNext. character ifNil: [^ nil]. ^ self toSqueak: character. ! ! !CP1252TextConverter methodsFor: 'as yet unclassified' stamp: 'za 12/30/2008 02:42'! nextPut: aCharacter toStream: aStream aStream isBinary ifTrue: [^ aCharacter storeBinaryOn: aStream]. aCharacter charCode < 128 ifTrue: [aStream basicNextPut: aCharacter] ifFalse: [aStream basicNextPut: ((Character value: (self fromSqueak: aCharacter) charCode))]. ! ! !CP1252TextConverter methodsFor: 'as yet unclassified' stamp: 'za 12/30/2008 03:23'! toSqueak: aCharacter | value | value := aCharacter charCode. (value >= 128 and: [value <= 159]) ifTrue: [^ ToTable at: aCharacter charCode]. ^ aCharacter! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! CP1252TextConverter class instanceVariableNames: ''! !CP1252TextConverter class methodsFor: 'as yet unclassified' stamp: 'za 12/30/2008 02:34'! encodingNames ^ #('windows-1252' 'cp-1252') copy ! ! !CP1252TextConverter class methodsFor: 'as yet unclassified' stamp: 'za 12/30/2008 03:01'! initialize ToTable := Dictionary new. ToTable at: 16r80 put: 16r20AC. "16r81 is unused " ToTable at: 16r82 put: 16r201A. ToTable at: 16r83 put: 16r0192. ToTable at: 16r84 put: 16r201E. ToTable at: 16r85 put: 16r2026. ToTable at: 16r86 put: 16r2020. ToTable at: 16r87 put: 16r2021. ToTable at: 16r88 put: 16r02C6. ToTable at: 16r89 put: 16r2030. ToTable at: 16r8A put: 16r0160. ToTable at: 16r8B put: 16r2039. ToTable at: 16r8C put: 16r0152. "16r8D is unused " ToTable at: 16r8E put: 16r017D. "16r8F is unused " "16r90 is unused " ToTable at: 16r91 put: 16r2018. ToTable at: 16r92 put: 16r2019. ToTable at: 16r93 put: 16r201C. ToTable at: 16r94 put: 16r201D. ToTable at: 16r95 put: 16r2022. ToTable at: 16r96 put: 16r2013. ToTable at: 16r97 put: 16r2014. ToTable at: 16r98 put: 16r02DC. ToTable at: 16r99 put: 16r2122. ToTable at: 16r9A put: 16r0161. ToTable at: 16r9B put: 16r203A. ToTable at: 16r9C put: 16r0153. "16r9D is unused " ToTable at: 16r9E put: 16r017E. ToTable at: 16r9F put: 16r0178. FromTable := Dictionary new. ToTable keysAndValuesDo: [ :key :value | FromTable at: value put: key ]! ! CP1252TextConverter initialize! |
Free forum by Nabble | Edit this page |