From: "Bartosz DziewoƄski" Date: 2013-02-26T03:47:08+09:00 Subject: Re: Psych being the default - what to do with invalid yaml files? On Sun, 24 Feb 2013 23:40:38 +0100, Marc Heiler wrote: > I can not do so, for various reasons. I do not use UTF-8 at all myself > either and have zero need to do so. It takes too long to explain in > detail why - I did so many times before and it ALWAYS leads to the same > response, with the final answer being "Switch to UTF-8.". Enter a loop > here ... Just a heads-up: Unicode is already *the* standard for describing text data, and UTF-8 is the most used encoding of Unicode right now (UTF-16 and UTF-32 are often used in memory of running applications, but almost never for storage). Not using Unicode is obsolete, and as years pass you're going to have more and more issues if you do so. > Anyway, what I could do, is this: > > Use my broken YAML files and save them, in another location, as UTF-8, > and then load those yaml files. I could write a ruby script doing so, > once I know how to "properly" save those files in UTF-8, in the easiest > way possible. > > Now my question is: > > What would be the easiest (ideally, a pure ruby solution) way to save my > yaml files as UTF-8? If it can not be a pure ruby solution, using a > linux-only solution is fine too. Well... # coding: utf-8 binary_data = File.binread('filename.yaml') utf8_encoded_text = binary_data.force_encoding('whatever').encode('utf-8') File.binwrite('filename-utf8.yaml', utf8_encoded_text) This is of course just one of the ways to do this. You could also use any reasonable text editor (I know that at least Notepad2 and Notepad++ for Windows and Sublime Text for all platforms can do this). > How do others save their files in a > specific encoding __without__ using their editor for doing so? Well uh, how else would you do that? Reasonable editors default to UTF-8 anyway these days. You usually either can choose the encoding during saving, or have a menu option to transcode the text. > (Part of > a reason why I can not switch is because I use a uncommon editor, and I > would have to use another editor if I were to switch completely to > UTF-8. This would take even more time, which I lack.) I can't fathom what editor you are using that doesn't allow you to choose an encoding to save files in. Even good ol' Windows Notepad does this. -- Matma Rex