[Pharo-project] Write accentuate characters in file
Hello, A small question I have: how can I write a "é" character in a file and >really< get it in Mac OS? I tried with: FileStream newFileNamed: 'test.txt' do: [ :each | each nextPutAll: 'ééé' ] and got: 'â©â©â©'. I also tried with FileSystem and got : 'ÃÃÃ'. I do not see another way to do that ... Regards, Adrien.
On 16.05.2011 16:42, Adrien BARREAU wrote:
Hello,
A small question I have: how can I write a "é" character in a file and
really< get it in Mac OS? I tried with:
FileStream newFileNamed: 'test.txt' do: [ :each | each nextPutAll: 'ééé' ]
and got: 'â©â©â©'.
I also tried with FileSystem and got : 'ÃÃÃ'.
I do not see another way to do that ...
Regards, Adrien. FileStream newFileNamed: 'test.txt' do: [ :stream | stream converter: MacRomanTextConverter new; " or: TextConverter newForEncoding: 'mac-roman' " nextPutAll: 'ééé' ].
Cheers, Henry
On Mon, May 16, 2011 at 5:01 PM, Henrik Sperre Johansen <henrik.s.johansen@veloxit.no> wrote:
FileStream newFileNamed: 'test.txt' do: [ :stream |    stream converter: MacRomanTextConverter new; " or: TextConverter newForEncoding: 'mac-roman' "    nextPutAll: 'ééé' ].
This is the correct way of solving your problem... however, your application becomes dependent of MacOS X. If you want your application to be portable to other OSes, I would advise you to use the simple approach that you give FileStream newFileNamed: 'test.txt' do: [ :each | each nextPutAll: 'ééé' ] and tell your favorite Apple editor that this is indeed UTF-8. UTF-8 is the standard, MacRoman is Apple only. -- Damien Cassou http://damiencassou.seasidehosting.st "Lambdas are relegated to relative obscurity until Java makes them popular by not having them." James Iry
You could also be friendly and tell the editor that it's UTF8 using a bom http://en.wikipedia.org/wiki/Byte_order_mark I dunno how standard that is nowadays though. On 05/16/2011 05:10 PM, Damien Cassou wrote:
On Mon, May 16, 2011 at 5:01 PM, Henrik Sperre Johansen <henrik.s.johansen@veloxit.no> wrote:
FileStream newFileNamed: 'test.txt' do: [ :stream | stream converter: MacRomanTextConverter new; " or: TextConverter newForEncoding: 'mac-roman' " nextPutAll: 'ééé' ]. This is the correct way of solving your problem... however, your application becomes dependent of MacOS X. If you want your application to be portable to other OSes, I would advise you to use the simple approach that you give
FileStream newFileNamed: 'test.txt' do: [ :each | each nextPutAll: 'ééé' ]
and tell your favorite Apple editor that this is indeed UTF-8. UTF-8 is the standard, MacRoman is Apple only.
Am 16.05.2011 um 19:06 schrieb Toon Verwaest:
You could also be friendly and tell the editor that it's UTF8 using a bom http://en.wikipedia.org/wiki/Byte_order_mark
I dunno how standard that is nowadays though.
BOM is explicitly optional. One reason is the be sort of backward compatible for older programs. And this is because utf-8 is relatively close to latin1. etc. My personal opinion is that a BOM does not solve the real problems. It is an endless story with stupid things and very good reasons for the stupid things to be there. E.g. If you have a utf-8 file on linux and on Mac they differ by design. Linux uses composed characters and Mac uses decomposed. If you are in latin1 character set this easily can drive you nuts. Norbert
On 05/16/2011 05:10 PM, Damien Cassou wrote:
On Mon, May 16, 2011 at 5:01 PM, Henrik Sperre Johansen <henrik.s.johansen@veloxit.no> wrote:
FileStream newFileNamed: 'test.txt' do: [ :stream | stream converter: MacRomanTextConverter new; " or: TextConverter newForEncoding: 'mac-roman' " nextPutAll: 'ééé' ]. This is the correct way of solving your problem... however, your application becomes dependent of MacOS X. If you want your application to be portable to other OSes, I would advise you to use the simple approach that you give
FileStream newFileNamed: 'test.txt' do: [ :each | each nextPutAll: 'ééé' ]
and tell your favorite Apple editor that this is indeed UTF-8. UTF-8 is the standard, MacRoman is Apple only.
Amazing that it is easier to go to England from France than manipulating accented characters in today's programming languages. I am surprised when I see a website in Chile that does not replace "ñ" by "??" Thanks for your help guys. I have learnt something today. Alexandre On 16 May 2011, at 11:01, Henrik Sperre Johansen wrote:
On 16.05.2011 16:42, Adrien BARREAU wrote:
Hello,
A small question I have: how can I write a "é" character in a file and >really< get it in Mac OS? I tried with:
FileStream newFileNamed: 'test.txt' do: [ :each | each nextPutAll: 'ééé' ]
and got: 'â©â©â©'.
I also tried with FileSystem and got : 'ÃÃÃ'.
I do not see another way to do that ...
Regards, Adrien. FileStream newFileNamed: 'test.txt' do: [ :stream | stream converter: MacRomanTextConverter new; " or: TextConverter newForEncoding: 'mac-roman' " nextPutAll: 'ééé' ].
Cheers, Henry
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
On 16.05.2011 16:42, Adrien BARREAU wrote:
Hello,
A small question I have: how can I write a "é" character in a file and
really< get it in Mac OS? I tried with:
FileStream newFileNamed: 'test.txt' do: [ :each | each nextPutAll: 'ééé' ]
and got: 'â©â©â©'. That IS the é character btw, in UTF8 encoding, but interpreted and displayed as MacRoman.
Cheers, Henry
On 16 May 2011, at 16:42, Adrien BARREAU wrote:
Hello,
A small question I have: how can I write a "é" character in a file and >really< get it in Mac OS? I tried with:
FileStream newFileNamed: 'test.txt' do: [ :each | each nextPutAll: 'ééé' ]
and got: 'â©â©â©'.
I also tried with FileSystem and got : 'ÃÃÃ'.
I do not see another way to do that ...
Regards, Adrien.
Works for me (Pharo 1.2.x , Mac OS X 10.6.x) FileStream newFileNamed: '/tmp/foo.txt' do: [ :each | each nextPutAll: 'ééé' ]. (FileStream fileNamed: '/tmp/foo.txt') upToEnd 'ééé' Sven
On Mon, May 16, 2011 at 5:09 PM, Sven Van Caekenberghe <sven@beta9.be> wrote:
FileStream newFileNamed: '/tmp/foo.txt' do: [ :each | each nextPutAll: 'ééé' ].
(FileStream fileNamed: '/tmp/foo.txt') upToEnd 'ééé'
sure, you stay in UTF-8 all along. You will see the problem if you visualise the file within a MacOS X file editor that is configured to display MacRoman by default. -- Damien Cassou http://damiencassou.seasidehosting.st "Lambdas are relegated to relative obscurity until Java makes them popular by not having them." James Iry
participants (7)
-
Adrien BARREAU -
Alexandre Bergel -
Damien Cassou -
Henrik Sperre Johansen -
Norbert Hartl -
Sven Van Caekenberghe -
Toon Verwaest