From: Erik Veenstra Date: 2005-08-07T20:26:08+09:00 Subject: Re: Unpack binary files. > I think you should reformat gpl.txt in a text editor so that > it's exactly the way you want it to look. Then display your > new file in the widget ?? > > Otherwise you will be writing a text formatter ;) I've once written this String#reformat. It might help you. I added a test to the script. gegroet, Erik V. - http://www.erikveen.dds.nl/ ---------------------------------------------------------------- class String def wrap(width, prefix="", prefixoneveryline=true) prefix = prefix.to_s text = self.to_s res = [] while not text.empty? line = text[0..width-2-prefix.length] line = text.gsub(/ .*/, "") unless line.include?(" ") line = line.gsub(/ [^ ]*$/, "") unless line == text or text[line.length..-1] =~ /^ / res << prefix + line prefix = prefix.gsub(/./, " ") unless prefixoneveryline text = text[line.length..-1] text = text.gsub(/^ /, "") end text = res.join("\n") end def reformat(width, prefix="", prefixoneveryline=true) paragraphs = self.split(/\s*\r*\n\r*\n[\r\n]*\s*/) paragraphs.collect! do |paragraph| paragraph.gsub!(/^[\r\n\s]+/, "") paragraph.gsub!(/[\r\n\s]+$/, "") paragraph.gsub!(/[\r\n\s]+/, " ") paragraph.wrap(width, prefix, prefixoneveryline) end paragraphs.join("\n\n") end end text = DATA.read puts text.reformat(55, "# ") __END__ Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. .................................................................