git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271980 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -15,6 +15,9 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||||
| /** | /** | ||||
| * String to byte converter | * String to byte converter | ||||
| * | * | ||||
| * <p>Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary | |||||
| * numbers begin with 0b, all other values are assumed to be decimal.</p> | |||||
| * | |||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
| * @ant.converter source="java.lang.String" destination="java.lang.Byte" | * @ant.converter source="java.lang.String" destination="java.lang.Byte" | ||||
| */ | */ | ||||
| @@ -34,7 +37,25 @@ public class StringToByteConverter | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| return new Byte( (String)object ); | |||||
| final String value = (String)object; | |||||
| byte result = 0; | |||||
| if( value.startsWith( "0x" ) ) | |||||
| { | |||||
| result = Byte.parseByte( value.substring( 2 ), 16 ); | |||||
| } | |||||
| else if( value.startsWith( "0o" ) ) | |||||
| { | |||||
| result = Byte.parseByte( value.substring( 2 ), 8 ); | |||||
| } | |||||
| else if( value.startsWith( "0b" ) ) | |||||
| { | |||||
| result = Byte.parseByte( value.substring( 2 ), 2 ); | |||||
| } | |||||
| else | |||||
| { | |||||
| result = Byte.parseByte( value ); | |||||
| } | |||||
| return new Byte( result ); | |||||
| } | } | ||||
| catch( final NumberFormatException nfe ) | catch( final NumberFormatException nfe ) | ||||
| { | { | ||||
| @@ -16,6 +16,9 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||||
| /** | /** | ||||
| * String to integer converter. | * String to integer converter. | ||||
| * | * | ||||
| * <p>Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary | |||||
| * numbers begin with 0b, all other values are assumed to be decimal.</p> | |||||
| * | |||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
| * @ant.converter source="java.lang.String" destination="java.lang.Integer" | * @ant.converter source="java.lang.String" destination="java.lang.Integer" | ||||
| */ | */ | ||||
| @@ -35,7 +38,25 @@ public class StringToIntegerConverter | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| return new Integer( (String)object ); | |||||
| final String value = (String)object; | |||||
| int result = 0; | |||||
| if( value.startsWith( "0x" ) ) | |||||
| { | |||||
| result = Integer.parseInt( value.substring( 2 ), 16 ); | |||||
| } | |||||
| else if( value.startsWith( "0o" ) ) | |||||
| { | |||||
| result = Integer.parseInt( value.substring( 2 ), 8 ); | |||||
| } | |||||
| else if( value.startsWith( "0b" ) ) | |||||
| { | |||||
| result = Integer.parseInt( value.substring( 2 ), 2 ); | |||||
| } | |||||
| else | |||||
| { | |||||
| result = Integer.parseInt( value ); | |||||
| } | |||||
| return new Integer( result ); | |||||
| } | } | ||||
| catch( final NumberFormatException nfe ) | catch( final NumberFormatException nfe ) | ||||
| { | { | ||||
| @@ -15,6 +15,9 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||||
| /** | /** | ||||
| * String to long converter | * String to long converter | ||||
| * | * | ||||
| * <p>Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary | |||||
| * numbers begin with 0b, all other values are assumed to be decimal.</p> | |||||
| * | |||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
| * @ant.converter source="java.lang.String" destination="java.lang.Long" | * @ant.converter source="java.lang.String" destination="java.lang.Long" | ||||
| */ | */ | ||||
| @@ -34,7 +37,25 @@ public class StringToLongConverter | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| return new Long( (String)object ); | |||||
| final String value = (String)object; | |||||
| long result = 0; | |||||
| if( value.startsWith( "0x" ) ) | |||||
| { | |||||
| result = Long.parseLong( value.substring( 2 ), 16 ); | |||||
| } | |||||
| else if( value.startsWith( "0o" ) ) | |||||
| { | |||||
| result = Long.parseLong( value.substring( 2 ), 8 ); | |||||
| } | |||||
| else if( value.startsWith( "0b" ) ) | |||||
| { | |||||
| result = Long.parseLong( value.substring( 2 ), 2 ); | |||||
| } | |||||
| else | |||||
| { | |||||
| result = Long.parseLong( value ); | |||||
| } | |||||
| return new Long( result ); | |||||
| } | } | ||||
| catch( final NumberFormatException nfe ) | catch( final NumberFormatException nfe ) | ||||
| { | { | ||||
| @@ -15,6 +15,9 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||||
| /** | /** | ||||
| * String to short converter | * String to short converter | ||||
| * | * | ||||
| * <p>Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary | |||||
| * numbers begin with 0b, all other values are assumed to be decimal.</p> | |||||
| * | |||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
| * @ant.converter source="java.lang.String" destination="java.lang.Short" | * @ant.converter source="java.lang.String" destination="java.lang.Short" | ||||
| */ | */ | ||||
| @@ -34,7 +37,25 @@ public class StringToShortConverter | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| return new Short( (String)object ); | |||||
| final String value = (String)object; | |||||
| short result = 0; | |||||
| if( value.startsWith( "0x" ) ) | |||||
| { | |||||
| result = Short.parseShort( value.substring( 2 ), 16 ); | |||||
| } | |||||
| else if( value.startsWith( "0o" ) ) | |||||
| { | |||||
| result = Short.parseShort( value.substring( 2 ), 8 ); | |||||
| } | |||||
| else if( value.startsWith( "0b" ) ) | |||||
| { | |||||
| result = Short.parseShort( value.substring( 2 ), 2 ); | |||||
| } | |||||
| else | |||||
| { | |||||
| result = Short.parseShort( value ); | |||||
| } | |||||
| return new Short( result ); | |||||
| } | } | ||||
| catch( final NumberFormatException nfe ) | catch( final NumberFormatException nfe ) | ||||
| { | { | ||||