[antlr-interest] stringtemplate lower case/upper case question

Martin d'Anjou martin.danjou at neterion.com
Thu May 24 08:35:48 PDT 2007


Hi,

We use StringTemplate to produce many outputs based on an in-house created 
language using ANTLR to parse.  The following situation creeps up a lot: 
depending on the target output, I need the same data (usually names) in either 
upper-case, lower-case or the original mixed-case declaration.  I've found 
myself ending up writing a lot of this for example:

public String getFullName()
{
    String regName = this.name.replaceFirst("n", String.valueOf(this.currentIndex+this.startIndex));
    return regName+this.nameSuffix;
}

public String getFullNameLower()
{
    return fullName().toLowerCase();
}

public String getFullNameUpper()
{
    return fullName().toUpperCase();
}

And doing $blah.fullname$, $blah.fullNameLower$, or $blah.fullNameUpper$ in the 
templates based on context.

I was wondering is there a better way that would save the writing of the extra 
two functions (*Upper and *Lower)?  If not, would StringTemplate not benefit 
from a simple toLower and toUpper built-in syntax (e.g. $blah.fullName$, 
$blah.fullName*UpperCase$, or $blah.fullName*LowerCase$) ?

P.S.  So far I have over 30 "triplets" like this (and counting), hence my 
frustration at the extra functions ;)

Thanks!
Martin


More information about the antlr-interest mailing list