From: Austin Ziegler Date: 2004-12-14T11:54:40+09:00 Subject: Re: Help writing a each_unique method On Tue, 14 Dec 2004 01:05:45 +0900, David A. Black wrote: > On Tue, 14 Dec 2004, trans. (T. Onoma) wrote: >> On Monday 13 December 2004 10:37 am, Robert Klemme wrote: >>| What about >>| >>| class String >>| def word_wrap!(n = 80) >>| raise ArgumentError, "Wrap margin too low: #{n}" if n <= 2 >>| gsub!( Regexp.new( "(.{1,#{n-1}}\\w)\\b\\s*" ), "\\1\n") >>| end >>| >>| def word_wrap(n = 80) >>| c = dup >>| c.word_wrap! n >>| c >>| end >>| end >> Thanks, robert. That's a nice basic approach, and for the lack of >> something better I think I will used. But it would be nice to >> have something a little more robust. Something that can determine >> when to divide and hyphenate a word if it is just too long. > Austin Ziegler is working on an interface to TeX's hyphenation > facilities. I'm not sure where it stands, but we were talking > about it last week and it sounded cool. Minor correction. TeX::Hyphen already does this, but it only works with English hyphenation and standard "czech" substitution. I would not trust it with any other language, which is why I'm working on Text::Hyphen. Martin DeMello ported TeX::Hyphen from the Perl version and it works incredibly well. Text::Format can use TeX::Hyphen as a plugin, so formatting can happen with hyphenation. I am in the process of reworking the architecture of TeX::Hyphen (the algorithm is not going to change; this simply WORKS!) and it will better support a wide variety of languages. I have converted 16 of 42 TeX hyphenation files to the new Text::Hyphen format that will be used for languages. After I finish Text::Hyphen (this weekend?) I will be revisiting Text::Format. Because I am changing the initialization API with no backwards compatibility, I will be renaming Text::Format to Text::Formatter and bumping the version to 1.0. After this, I will be working on Ruwiki and Diff::LCS again, but I will be open to new features for Text::Formatter. The algorithm behind Text::Formatter is extgensive; I highly recommend using this instead of trying to write your own. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca