I'm mainly posting this as a joke. So keep that in mind. But. You could do something like, um... well...

---
#set( $mask = '0.1.254.255' )
#set( $imask = '' )

#macro( numchar $char $x $m )
#if( $char=='0' )#set( $num = 0 )
#elseif( $char=='1' )#set( $num = 1 )
#elseif( $char=='2' )#set( $num = 2 )
#elseif( $char=='3' )#set( $num = 3 )
#elseif( $char=='4' )#set( $num = 4 )
#elseif( $char=='5' )#set( $num = 5 )
#elseif( $char=='6' )#set( $num = 6 )
#elseif( $char=='7' )#set( $num = 7 )
#elseif( $char=='8' )#set( $num = 8 )
#else( $char=='9' )#set( $num = 9 )
#end
#set( $x = $x + $num * $m )
#end
#set( $bytes = $mask.split('\.') )
#foreach( $byte in $bytes )
#if( 3 == $byte.length() )
   #set( $h = $byte.substring(0,1) )
   #set( $t = $byte.substring(1,2) )
   #set( $o = $byte.substring(2,3) )
#elseif( 2 == $byte.length() )
   #set( $h = '0' )
   #set( $t = $byte.substring(0,1) )
   #set( $o = $byte.substring(1,2) )
#else
   #set( $h = '0' )
   #set( $t = '0' )
   #set( $o = $byte.substring(0,1) )
#end
#set( $x = 0 )
#numchar( $o $x 1 )
#numchar( $t $x 10 )
#numchar( $h $x 100 )
#set( $x = 255 - $x )
#set( $imask = "${imask}.$x" )
#end
#set( $imask = $imask.substring(1) )

Your mask was <b>$mask</b><br/>
Your inverse mask is <b>$imask</b>
---

That will print out

Your mask was *0.1.254.255*
Your inverse mask is *255.254.1.0*

Hehe.

Jason Pettiss
[EMAIL PROTECTED]

Ramin Dousti wrote:

Thanks, Jason. I have access only to templates for doing what I want
to do. Meaning, I have no access to the java code behind it. So, I guess
I'm out of luck there to do what you're suggesting.

Having said that, is there any way I can get "255 - $value" with $value
being a string?

Ramin
On 5/25/05, Jason Pettiss <[EMAIL PROTECTED]> wrote:
You should really try to avoid being too clever in a template.  Java is
good for doing logical operations.  Templates are good for creating
content.  Try to keep the business logic in Java.

Btw, to split on '.' in Java you'd need to do "\\.".  You need to escape
the backslash so that a literal backslash goes to the regexp evaluator.
But in a template you'd just need something like $mask.split('\.').
Note the use of single quotes!

If you want to use a static method you need to wrap it with an instance
method.  As long as you're doing that why not just implement the full
method to do what you need.  Make life easier for yourself.  Write
yourself a method which does the right thing.  And toss an instance of
that object into your Context.

Jason Pettiss
[EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to