On Jun 2, 2007, at 1:02 AM, Lukas Renggli wrote:
Should I
implement my own StringReader to accomplish this in one
place?
There is no such thing in Magritte. Of course there are many places
where you could introduce such a thing. The StringReader is something
else, it transforms a string to a real object (e.g. a date object, a
number, etc).
It would be probably the best if you create a new mechanism, similar
to the one of the StringReader, that is responsible to do that?
Hi Lukas,
Even though Rails implements something more generic (pre-validation
hooks where any transformation could happen), I realized that I
really only needed it for this one specific situation (trimming
blanks off of strings and coercing them to nil if they are empty).
So I implemented my own StringReader subclass that overrides one method:
PruningStringReader>>visitStringDescription: aDescription
| trimmed |
trimmed := self contents trimBlanks.
self object: (trimmed isEmpty ifTrue: [nil] ifFalse: [trimmed])
This solves the problem that set me out on this quest in the first
place. I'm using this as my default string reader, since I can't
think of any situations in my apps where leading or trailing blanks
would be significant.
Thanks,
--
Ken Treis
Miriam Technologies, Inc.