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 | |||
| * | |||
| * <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> | |||
| * @ant.converter source="java.lang.String" destination="java.lang.Byte" | |||
| */ | |||
| @@ -34,7 +37,25 @@ public class StringToByteConverter | |||
| { | |||
| 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 ) | |||
| { | |||
| @@ -16,6 +16,9 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||
| /** | |||
| * 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> | |||
| * @ant.converter source="java.lang.String" destination="java.lang.Integer" | |||
| */ | |||
| @@ -35,7 +38,25 @@ public class StringToIntegerConverter | |||
| { | |||
| 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 ) | |||
| { | |||
| @@ -15,6 +15,9 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||
| /** | |||
| * 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> | |||
| * @ant.converter source="java.lang.String" destination="java.lang.Long" | |||
| */ | |||
| @@ -34,7 +37,25 @@ public class StringToLongConverter | |||
| { | |||
| 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 ) | |||
| { | |||
| @@ -15,6 +15,9 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||
| /** | |||
| * 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> | |||
| * @ant.converter source="java.lang.String" destination="java.lang.Short" | |||
| */ | |||
| @@ -34,7 +37,25 @@ public class StringToShortConverter | |||
| { | |||
| 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 ) | |||
| { | |||