[stringtemplate-interest] Advice: Avoiding duplication via iterating of list and applying template

Barrie Treloar baerrach at gmail.com
Tue May 24 17:48:16 PDT 2011


Is this sane?
It works and it is easier to read, but I am wondering if there is a
better way...
Note: I created the template _handleUnitNumbers() because of the
duplication there, so I may inline it instead.

I've replacing

=== orginal:start ===
^ | - | > | ^ | **    ;  handle any hyphens in a unit field ; 1 - 3EBA 1 **
<_handleUnitNumbers(unitNumberSupported,["1", "2", "3"])>

^ | - | > | > | **    ;  handle any hyphens in a unit field ; 1 - 3EBA 3EBA **
<_handleUnitNumbers(unitNumberSupported,["1", "2", "3"])>

^ | - | > | L | **    ;  handle any hyphens in a unit field ; 1 - 3EBA LOT **
<_handleUnitNumbers(unitNumberSupported,["1", "2", "3"])>

^ | - | > | @ | **    ;  handle any hyphens in a unit field ; 1 - 3EBA 6H46K **
<_handleUnitNumbers(unitNumberSupported,["1", "2", "3"])>

^ | - | > | \< | **   ;  handle any hyphens in a unit field ; 1 - 3EBA A501 **
<_handleUnitNumbers(unitNumberSupported,["1", "2", "3"])>

> | - | ^ | ^ | **    ;  handle any hyphens in a unit field ; 3EBA - 1 1 **
<_handleUnitNumbers(unitNumberSupported,["1", "2", "3"])>
=== original:end ===

With

=== new:start ===
<[
"^ | - | > | ^ | **    ;  handle any hyphens in a unit field ; 1 - 3EBA 1 **",
"^ | - | > | > | **    ;  handle any hyphens in a unit field ; 1 -
3EBA 3EBA **",
"^ | - | > | L | **    ;  handle any hyphens in a unit field ; 1 - 3EBA LOT **",
"^ | - | > | @ | **    ;  handle any hyphens in a unit field ; 1 -
3EBA 6H46K **",
"^ | - | > | < | **   ;  handle any hyphens in a unit field ; 1 - 3EBA A501 **",
"> | - | ^ | ^ | **    ;  handle any hyphens in a unit field ; 3EBA - 1 1 **",
] : { pattern |
<pattern> (NEW)
<_handleUnitNumbers(unitNumberSupported,["1", "2", "3"])>

}>
=== new:end ===


More information about the stringtemplate-interest mailing list