From: Juergen Strobel Date: 2006-06-29T02:16:14+09:00 Subject: Re: Unicode roadmap? --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 26, 2006 at 11:21:59AM +0900, Yukihiro Matsumoto wrote: > Hi, >=20 > In message "Re: Unicode roadmap?" > on Mon, 26 Jun 2006 10:22:15 +0900, "Phillip Hutchings" writes: >=20 > |> st =3D File.open("file.txt", "rb") { |f| f.read_string } > |> bv =3D File.open("file.txt", "rb") { |f| f.read_bytes } > | > |Why? This looks needlessly complex. > | > |string =3D File.open('file.txt', 'r') {f.read.to_s(:utf-8)} > | > |Or possibly > |string =3D File.open('file.txt', 'r') {f.read(:utf8)} > |bytes =3D File.open('file.txt', 'r') {f.read(:bytearray)} >=20 > They are equally more complex than the current design. If File can > return String or ByteArray, why shouldn't String with "no encoding" > behave as sequence of bytes instead of separating? Are there any > specific operations that should be in ByteArray but not in String, or > vise versa? >=20 > matz. Any additional complexity here should be offset later, when doing operations on the read data as appropriate for its type. Of course, the first line should raise an exception if file.txt is not utf8 encoded, this saves extra complexity down the line, and is a real difference between the two. I imagine Bytevector would be implemented with maximum performance and space efficiency in mind, while String is a higher level class streamlined for easy of use. There could be accessor for the Bytevector to convert it (or parts of it) to a String, for cases where you really need to read mixed string/data from somewhere. string =3D bytes.to_str(:utf8)=20 string2 =3D bytes[1..5].to_str(:utf8) Or maybe a StrStream-like interface: bytes.stream_open("r") do |b| s =3D b.read(:utf8) ... end -J=FCrgen --=20 The box said it requires Windows 95 or better so I installed Linux --IS0zKkzwUGydFO0o Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iQEVAwUBRKKdLPy64gyiEfXtAQIdmAgA5dF9kr4l3+td6v2ym5hkCgc4yZRo5YEA T4uQzmRdos1hJ13KSOE9xRWCl4dVTmMbiduDPGFeUuJ713JkIw8VuBv4gGMIs0/Q Y9Q3pudyqBQktFhSCLRjbMUfhIm4Fsb/ZkBBvkUjL8F9yi8iViXQ5qMCO4L1SsbJ klJRUCwHDuW+rpEUzFCvYaltlz9OOEVw0AZ14xytVpgXHZHGk386a4BQGUpBETCQ SgrETewM2au2T295EVS6l0s+wnojNMb0c9ewamEsjDNMOqcIhpxyfvoX+pjSM1eQ Dpz15cxI6+VTlkS98hdjRVzKbXPUgvMfVnNakp6JTiD8O6ntfKc+PA== =p+dZ -----END PGP SIGNATURE----- --IS0zKkzwUGydFO0o--