diff --git a/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToByteConverter.java b/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToByteConverter.java index c66722db1..2abe41bea 100644 --- a/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToByteConverter.java +++ b/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToByteConverter.java @@ -15,6 +15,9 @@ import org.apache.avalon.excalibur.i18n.Resources; /** * String to byte converter * + *
Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary + * numbers begin with 0b, all other values are assumed to be decimal.
+ * * @author Peter Donald * @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 ) { diff --git a/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToIntegerConverter.java b/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToIntegerConverter.java index f4d3b75e2..8bb17c516 100644 --- a/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToIntegerConverter.java +++ b/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToIntegerConverter.java @@ -16,6 +16,9 @@ import org.apache.avalon.excalibur.i18n.Resources; /** * String to integer converter. * + *Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary + * numbers begin with 0b, all other values are assumed to be decimal.
+ * * @author Peter Donald * @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 ) { diff --git a/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToLongConverter.java b/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToLongConverter.java index 72d76c85e..4c098e9e5 100644 --- a/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToLongConverter.java +++ b/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToLongConverter.java @@ -15,6 +15,9 @@ import org.apache.avalon.excalibur.i18n.Resources; /** * String to long converter * + *Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary + * numbers begin with 0b, all other values are assumed to be decimal.
+ * * @author Peter Donald * @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 ) { diff --git a/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToShortConverter.java b/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToShortConverter.java index 9b81ecfb9..1a8944cc0 100644 --- a/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToShortConverter.java +++ b/proposal/myrmidon/src/java/org/apache/aut/converter/lib/StringToShortConverter.java @@ -15,6 +15,9 @@ import org.apache.avalon.excalibur.i18n.Resources; /** * String to short converter * + *Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary + * numbers begin with 0b, all other values are assumed to be decimal.
+ * * @author Peter Donald * @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 ) {