You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Robert <ro...@bull-enterprises.com> on 2003/12/16 02:55:15 UTC
[Jexl] String concatination
Attached is a patch for the ASTAddNode class that will do a string
concat if the coercion to a double and long fails.
Thanks!
Robert McIntosh
Re: [Jexl] String concatination
Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Dec 29, 2003, at 7:52 PM, Robert wrote:
>
>
> Geir Magnusson Jr wrote:
>> On Dec 20, 2003, at 10:22 PM, Robert wrote:
>>> I actually thought this was in the spec, my fault! I was trying to
>>> do string building, which of course didn't work, which lead me to
>>> look at the JavaDoc this class says "either integer addition or
>>> string concatenation" and the CVS entry says something about string
>>> concatenation not working anymore, so I did this quick patch.
>>> I even tried string literal addition and it doesn't work either. It
>>> would be nice so one does have to do ${hello.concat(' world')} to
>>> build strings, but I'll understand if it isn't added.
>> What doesn't work? I don't understand.
> I'll double check but 'hello' + 'world' wouldn't work either. Perhaps
> I should just write a junit test!!
I added a unit test when I did the patch....
>
> Robert
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
--
Geir Magnusson Jr 203-247-1713(m)
geir@4quarters.com
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [Jexl] String concatination
Posted by Robert <ro...@bull-enterprises.com>.
Geir Magnusson Jr wrote:
>
> On Dec 20, 2003, at 10:22 PM, Robert wrote:
>
>> I actually thought this was in the spec, my fault! I was trying to do
>> string building, which of course didn't work, which lead me to look
>> at the JavaDoc this class says "either integer addition or string
>> concatenation" and the CVS entry says something about string
>> concatenation not working anymore, so I did this quick patch.
>
>
>> I even tried string literal addition and it doesn't work either. It
>> would be nice so one does have to do ${hello.concat(' world')} to
>> build strings, but I'll understand if it isn't added.
>
>
> What doesn't work? I don't understand.
>
I'll double check but 'hello' + 'world' wouldn't work either. Perhaps
I should just write a junit test!!
Robert
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [Jexl] String concatination
Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Dec 20, 2003, at 10:22 PM, Robert wrote:
> I actually thought this was in the spec, my fault! I was trying to do
> string building, which of course didn't work, which lead me to look at
> the JavaDoc this class says "either integer addition or string
> concatenation" and the CVS entry says something about string
> concatenation not working anymore, so I did this quick patch.
> I even tried string literal addition and it doesn't work either. It
> would be nice so one does have to do ${hello.concat(' world')} to
> build strings, but I'll understand if it isn't added.
What doesn't work? I don't understand.
>
> - Robert McIntosh
>
> Geir Magnusson Jr wrote:
>
>> Intresting. This is not what the JSP EL does. Not that we really
>> care, but it's an interesting extension. It follows Java, I suppose
>> :)
>> Patch in - lets see what people think.
>> geir
>> On Dec 15, 2003, at 8:55 PM, Robert wrote:
>>> Attached is a patch for the ASTAddNode class that will do a string
>>> concat if the coercion to a double and long fails.
>>>
>>> Thanks!
>>> Robert McIntosh
>>> Index: ASTAddNode.java
>>> ===================================================================
>>> RCS file:
>>> /home/cvspublic/jakarta-commons/jexl/src/java/org/apache/commons/
>>> jexl/ parser/ASTAddNode.java,v
>>> retrieving revision 1.2
>>> diff -u -r1.2 ASTAddNode.java
>>> --- ASTAddNode.java 17 May 2002 12:13:22 -0000 1.2
>>> +++ ASTAddNode.java 16 Dec 2003 01:47:01 -0000
>>> @@ -119,12 +119,18 @@
>>> }
>>>
>>> /*
>>> - * otherwise to longs with thee!
>>> + * attempt to use Longs
>>> */
>>> -
>>> - Long l = Coercion.coerceLong(left);
>>> - Long r = Coercion.coerceLong(right);
>>> -
>>> - return new Long(l.longValue() + r.longValue());
>>> + try {
>>> + Long l = Coercion.coerceLong(left);
>>> + Long r = Coercion.coerceLong(right);
>>> + return new Long(l.longValue() + r.longValue());
>>> + }
>>> + catch( java.lang.NumberFormatException nfe ) {
>>> + /*
>>> + * Well, use strings!
>>> + */
>>> + return left.toString().concat( right.toString() );
>>> + }
>>> }
>>> }
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
--
Geir Magnusson Jr 203-247-1713(m)
geir@4quarters.com
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [Jexl] String concatination
Posted by Robert <ro...@bull-enterprises.com>.
I actually thought this was in the spec, my fault! I was trying to do
string building, which of course didn't work, which lead me to look at
the JavaDoc this class says "either integer addition or string
concatenation" and the CVS entry says something about string
concatenation not working anymore, so I did this quick patch.
I even tried string literal addition and it doesn't work either. It
would be nice so one does have to do ${hello.concat(' world')} to build
strings, but I'll understand if it isn't added.
- Robert McIntosh
Geir Magnusson Jr wrote:
> Intresting. This is not what the JSP EL does. Not that we really
> care, but it's an interesting extension. It follows Java, I suppose :)
>
> Patch in - lets see what people think.
>
> geir
>
> On Dec 15, 2003, at 8:55 PM, Robert wrote:
>
>> Attached is a patch for the ASTAddNode class that will do a string
>> concat if the coercion to a double and long fails.
>>
>> Thanks!
>> Robert McIntosh
>> Index: ASTAddNode.java
>> ===================================================================
>> RCS file:
>> /home/cvspublic/jakarta-commons/jexl/src/java/org/apache/commons/jexl/
>> parser/ASTAddNode.java,v
>> retrieving revision 1.2
>> diff -u -r1.2 ASTAddNode.java
>> --- ASTAddNode.java 17 May 2002 12:13:22 -0000 1.2
>> +++ ASTAddNode.java 16 Dec 2003 01:47:01 -0000
>> @@ -119,12 +119,18 @@
>> }
>>
>> /*
>> - * otherwise to longs with thee!
>> + * attempt to use Longs
>> */
>> -
>> - Long l = Coercion.coerceLong(left);
>> - Long r = Coercion.coerceLong(right);
>> -
>> - return new Long(l.longValue() + r.longValue());
>> + try {
>> + Long l = Coercion.coerceLong(left);
>> + Long r = Coercion.coerceLong(right);
>> + return new Long(l.longValue() + r.longValue());
>> + }
>> + catch( java.lang.NumberFormatException nfe ) {
>> + /*
>> + * Well, use strings!
>> + */
>> + return left.toString().concat( right.toString() );
>> + }
>> }
>> }
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [Jexl] String concatination
Posted by Geir Magnusson Jr <ge...@4quarters.com>.
Intresting. This is not what the JSP EL does. Not that we really
care, but it's an interesting extension. It follows Java, I suppose :)
Patch in - lets see what people think.
geir
On Dec 15, 2003, at 8:55 PM, Robert wrote:
> Attached is a patch for the ASTAddNode class that will do a string
> concat if the coercion to a double and long fails.
>
> Thanks!
> Robert McIntosh
> Index: ASTAddNode.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-commons/jexl/src/java/org/apache/commons/jexl/
> parser/ASTAddNode.java,v
> retrieving revision 1.2
> diff -u -r1.2 ASTAddNode.java
> --- ASTAddNode.java 17 May 2002 12:13:22 -0000 1.2
> +++ ASTAddNode.java 16 Dec 2003 01:47:01 -0000
> @@ -119,12 +119,18 @@
> }
>
> /*
> - * otherwise to longs with thee!
> + * attempt to use Longs
> */
> -
> - Long l = Coercion.coerceLong(left);
> - Long r = Coercion.coerceLong(right);
> -
> - return new Long(l.longValue() + r.longValue());
> + try {
> + Long l = Coercion.coerceLong(left);
> + Long r = Coercion.coerceLong(right);
> + return new Long(l.longValue() + r.longValue());
> + }
> + catch( java.lang.NumberFormatException nfe ) {
> + /*
> + * Well, use strings!
> + */
> + return left.toString().concat( right.toString() );
> + }
> }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
--
Geir Magnusson Jr 203-247-1713(m)
geir@4quarters.com
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org