CharacterEncoder.st
changeset 8168 8f8da8bb046d
parent 8156 bd5169c15b31
child 8176 66d1004f1806
equal deleted inserted replaced
8167:622b4431e3a0 8168:8f8da8bb046d
   197      self encoderFor:#'jis7'      
   197      self encoderFor:#'jis7'      
   198      self encoderFor:#'utf8'      
   198      self encoderFor:#'utf8'      
   199     "
   199     "
   200 !
   200 !
   201 
   201 
   202 encoderFor:encodingNameSymbol ifAbsent:exceptionValue
   202 encoderFor:encodingNameSymbolArg ifAbsent:exceptionValue
   203     "given the name of an encoding, return an encoder-instance which can map these from/into unicode."
   203     "given the name of an encoding, return an encoder-instance which can map these from/into unicode."
   204 
   204 
   205     |enc clsName cls lcName name unicodeEncoders unicodeEncoderClasses|
   205     |encodingNameSymbol enc clsName cls lcName name unicodeEncoders unicodeEncoderClasses|
   206 
   206 
       
   207     encodingNameSymbol := encodingNameSymbolArg.
   207     encodingNameSymbol isNil ifTrue:[ ^ NullEncoderInstance].
   208     encodingNameSymbol isNil ifTrue:[ ^ NullEncoderInstance].
       
   209 
       
   210     encodingNameSymbol == #'iso10646-1' ifTrue:[ encodingNameSymbol :=  #'unicode'].
       
   211     encodingNameSymbol isSymbol ifFalse:[self halt:'symbol argument expected'. encodingNameSymbol := encodingNameSymbol asSymbol].
   208 
   212 
   209     lcName := encodingNameSymbol asLowercase.
   213     lcName := encodingNameSymbol asLowercase.
   210     name := lcName asSymbolIfInterned.
   214     name := lcName asSymbolIfInterned.
   211     name isNil ifTrue:[name := lcName].
   215     name isNil ifTrue:[name := lcName].
   212 
   216 
   788     superSetEncoding := superSetEncodingArg asLowercase.
   792     superSetEncoding := superSetEncodingArg asLowercase.
   789 
   793 
   790     (subSetEncoding match:superSetEncoding) ifTrue:[^ true].
   794     (subSetEncoding match:superSetEncoding) ifTrue:[^ true].
   791 
   795 
   792     (('iso10646*' match:superSetEncoding) or:[superSetEncoding = 'unicode']) ifTrue:[
   796     (('iso10646*' match:superSetEncoding) or:[superSetEncoding = 'unicode']) ifTrue:[
   793 	('ascii*' match:subSetEncoding) ifTrue:[^ true].
   797         ('ms-*' match:subSetEncoding) ifTrue:[^ true].
   794 	('iso8859*' match:subSetEncoding) ifTrue:[^ true].
   798         ('ascii*' match:subSetEncoding) ifTrue:[^ true].
   795 	('jis*' match:subSetEncoding) ifTrue:[^ true].
   799         ('iso8859*' match:subSetEncoding) ifTrue:[^ true].
   796 	('koi8*' match:subSetEncoding) ifTrue:[^ true].
   800         ('jis*' match:subSetEncoding) ifTrue:[^ true].
   797 	('ksc*' match:subSetEncoding) ifTrue:[^ true].
   801         ('koi8*' match:subSetEncoding) ifTrue:[^ true].
   798 	('big*' match:subSetEncoding) ifTrue:[^ true].
   802         ('ksc*' match:subSetEncoding) ifTrue:[^ true].
   799 	('cns*' match:subSetEncoding) ifTrue:[^ true].
   803         ('big*' match:subSetEncoding) ifTrue:[^ true].
   800 	('gb2312*' match:subSetEncoding) ifTrue:[^ true].
   804         ('cns*' match:subSetEncoding) ifTrue:[^ true].
       
   805         ('gb2312*' match:subSetEncoding) ifTrue:[^ true].
   801     ].
   806     ].
   802 
   807 
   803     "/ if the subSet is iso8859-*, that means ascii (i.e. the lower 7 bits of iso8859 only).
   808     "/ if the subSet is iso8859-*, that means ascii (i.e. the lower 7 bits of iso8859 only).
   804     ((subSetEncoding = 'iso8859*') or:[subSetEncoding = 'iso8859-*']) ifTrue:[
   809     ((subSetEncoding = 'iso8859*') or:[subSetEncoding = 'iso8859-*']) ifTrue:[
   805 	('ascii*' match:superSetEncoding) ifTrue:[^ true].
   810         ('ascii*' match:superSetEncoding) ifTrue:[^ true].
       
   811         ('ms-ansi*' match:superSetEncoding) ifTrue:[^ true].
   806     ].
   812     ].
   807     (subSetEncoding = 'ascii') ifTrue:[
   813     (subSetEncoding = 'ascii') ifTrue:[
   808 	('iso8859*' match:superSetEncoding) ifTrue:[^ true].
   814         ('iso8859*' match:superSetEncoding) ifTrue:[^ true].
       
   815         ('ms-ansi*' match:superSetEncoding) ifTrue:[^ true].
   809     ].
   816     ].
   810 
   817 
   811     "/ TODO: check the charSets mappingTables...
   818     "/ TODO: check the charSets mappingTables...
   812     "/ self halt.
   819     "/ self halt.
   813     ^ false.
   820     ^ false.
  1241 ! !
  1248 ! !
  1242 
  1249 
  1243 !CharacterEncoder class methodsFor:'documentation'!
  1250 !CharacterEncoder class methodsFor:'documentation'!
  1244 
  1251 
  1245 version
  1252 version
  1246     ^ '$Header: /cvs/stx/stx/libbasic/CharacterEncoder.st,v 1.72 2004-03-10 16:11:42 ca Exp $'
  1253     ^ '$Header: /cvs/stx/stx/libbasic/CharacterEncoder.st,v 1.73 2004-03-12 12:44:47 cg Exp $'
  1247 ! !
  1254 ! !
  1248 
  1255 
  1249 CharacterEncoder initialize!
  1256 CharacterEncoder initialize!