string truncate: now with word boundaries

rjbs on 2007-07-23T22:16:22

Since roughly forever ago, I've meant to give String::Truncate the ability to try to truncate a string at word boundary. Done! That is, instead of turning "This is your brain on drugs." into "This is your br..." it can now return "This is your...".

This is one of those cases where my desire for the feature wasn't quite sufficient to get me to implement it. Sure, I wanted it now and then, but I didn't feel like writing tests or code for it. In these cases, what usually motivates me is pride: I find some other code that does what I want, but is otherwise inferior or, equally likely, just bugs me in its interface.

It turns out that this feature took no time at all -- not surprisingly, I guess. What I like about String::Truncate is that it focuses on making the not-quite-simple cases as easy as the simple ones, so that I can do what I really want, not just what's easy, without having to care. I need to write more code like that.


You mean

Alias on 2007-07-24T02:13:42

s/(what I like about) String::Truncate/$1 a lot of CPAN/

HTML::Truncate needs this too

wirebird on 2007-09-16T22:44:48

Planet Phoenyx:

http://forum.phoenyx.net/planet/phoenyx

The entry titled "Is the result about the subjects, or about the test?"

'Nuff said.

Re:HTML::Truncate needs this too

rjbs on 2007-09-17T00:53:43

That's pretty great.

Re:HTML::Truncate needs this too

rjbs on 2007-09-17T00:54:34

I wonder if you can't just use one of the many html-to-text converters, then use String::Truncate.

Re:HTML::Truncate needs this too

wirebird on 2007-09-17T01:51:27

Yeah, that's probably what I'll end up doing, since it pulls in some fugly LiveJournal html in some of the other aggregations, and right now I'm not sanitizing the HTML at all. (It was one of those proofs-of-concept that sort of took off.)

But first I'm going to wait until Rob's entry scrolls off.