From: Philipp Meier Date: 2002-08-01T21:14:24+09:00 Subject: Re: Unicode in Ruby now? --K8zN2sh9fO5jmbe4 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 01, 2002 at 07:53:07PM +0900, Curt Sampson wrote: > On Thu, 1 Aug 2002, Tobias Peters wrote: >=20 > > ... > > We also need rules how to combine strings with different encoding then. > > concatenating two strings encoded in koi8-r and iso-8859-1, respectivel= y, > > may only be possible when the result is encoded in some unicode > > representation. >=20 > Yeah. This is getting into complex nightmare city. That's why I'd prefer > to have the basic system just work completely in Unicode. One could have > a separate character system (character and string classes, byte-stream > to char converters, etc.) to work with this tagged format if one wished. Can't we follow an approach like ruby or java handles numbers? It's naturally possible to add a floating point number and an integer. The result is a floating point. I will sketch some ideas: class String alias :+ :__+ def + (other) if other.is_a? self.class self.__+(other) else self +=3D convert(other) end end end class ISO88591 < String=20 def convert_from(other) if other.is_a? ASCII return other elsif other.is_a? UTF8 return from_utf8 else convert_from(UTF8.convert_from(other)) end end def from_utf8() ... end def to_utf8() ... end =20 end class UTF8 < String def convert_from(other) other.to_utf8 end end The convert method can of course try to delegate everything to a UTF8 class, so that ascii -> iso-8859-1 will result in ascii -> utf8 -> iso8859-1. That means when introducing a new encoding one must only provide a method to convert from / to utf8. -billy. --=20 Meisterbohne S=F6flinger Stra=DFe 100 Tel: +49-731-399 499-0 eL=F6sungen 89077 Ulm Fax: +49-731-399 499-9 --K8zN2sh9fO5jmbe4 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9SSY2fBriNoqItSYRAuymAJ4yZZ2a4fhYQ7UwQJnEZHfPzmqRHgCfXSTF cpG4a+Gw1QaSMVmpy4U4jq8= =PTOx -----END PGP SIGNATURE----- --K8zN2sh9fO5jmbe4--