From: Ernest Ellingson Date: 2001-02-10T11:13:04+09:00 Subject: [ruby-talk:10655] Re: Word wrap algorithm Thanks for the start on the ASCII word wrap algorithm. I changed it around a little to take into account tabs and to keep formats for empty lines between paragraphs and to leave a line that is shorter than the word wrap size and has a "\n" on the end intact. You'll see the similarities to yours. puts $<.read.gsub(/\t/," ").gsub(/.{1,50}(?:\s|\Z)/){($& + 5.chr).gsub(/\n\005/,"\n").gsub(/\005/,"\n")} wraps everything to at most 50 characters wide. Ernie At 22:52 2/9/2001 +0900, you wrote: >In message <2B92A3D0D399D311BA7E00A0C90F8FDD88BF21@mailgate.snellingcorp.com> >ChrisM@SNELLINGCORP.COM writes: > > > I'm in need of a word wrap method -- anyone know of an existing one > > (preferably in Ruby) I could use? > >I have code inspired from filladapt.el.... It's not so beautiful and >effective, but at least works for usual input :-) > > >Ehm, if target strings are represented in only codeset like ASCII or >Latin1 codeset, which only uses 1 byte for each characters, Regexp for >index can be more simple.... > > >Hmm, like > > ruby -e 'puts $<.read.gsub(/\n/, " > ").gsub(/.{1,65}(?:\s|\Z)/){$&+"\n"}' foo > >for 65 coloumns. >