activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r560833 - in /activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang: Integer.cpp Integer.h
Date Sun, 29 Jul 2007 23:41:55 GMT
Author: tabish
Date: Sun Jul 29 16:41:51 2007
New Revision: 560833

URL: http://svn.apache.org/viewvc?view=rev&rev=560833
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103

Adding in more Types wrappers

Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.h

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.cpp?view=diff&rev=560833&r1=560832&r2=560833
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.cpp Sun Jul 29 16:41:51
2007
@@ -59,6 +59,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 std::string Integer::toString( int value )
 {
+    //TODO
     std::ostringstream ostream;
     ostream << value;
     return ostream.str();
@@ -68,11 +69,103 @@
 int Integer::parseInt( const std::string& value )
     throw ( exceptions::NumberFormatException ) {
 
-    int ret = 0;
-    std::istringstream istream(value);
-    istream.clear();
-    istream >> ret;
-    return ret;
+    return Integer::parseInt( value, 10 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Integer::parseInt( const std::string& value, int radix )
+    throw ( exceptions::NumberFormatException ) {
+
+    if( radix < Character::MIN_RADIX ||
+        radix > Character::MAX_RADIX ) {
+        throw NumberFormatException(
+            __FILE__, __LINE__,
+            "Integer:decode - Invalid radix" );
+    }
+
+    int length = value.length(), i = 0;
+    if( length == 0 ) {
+        throw NumberFormatException(
+            __FILE__, __LINE__,
+            "Integer:decode - Invalid: zero length string");
+    }
+
+    bool negative = value[i] == '-';
+    if( negative && ++i == length ) {
+        throw NumberFormatException(
+            __FILE__, __LINE__,
+            "Integer:decode - Invalid only a minus sign given");
+    }
+
+    return Integer::parse( value, i, radix, negative );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Integer Integer::valueOf( const std::string& value )
+    throw ( exceptions::NumberFormatException ) {
+
+    return Integer( Integer::parseInt( value ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Integer Integer::valueOf( const std::string& value, int radix )
+    throw ( exceptions::NumberFormatException ) {
+
+    return Integer( Integer::parseInt( value, radix ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Integer Integer::decode( const std::string& value )
+    throw ( exceptions::NumberFormatException ) {
+
+    int length = value.length(), i = 0;
+    if( length == 0 ) {
+        throw NumberFormatException(
+            __FILE__, __LINE__,
+            "Integer:decode - Invalid zero size string");
+    }
+
+    char firstDigit = value[i];
+    bool negative = firstDigit == '-';
+    if( negative ) {
+        if( length == 1 ) {
+            throw NumberFormatException(
+                __FILE__, __LINE__,
+                "Integer:decode - Invalid zero string, minus only");
+        }
+
+        firstDigit = value[++i];
+    }
+
+    int base = 10;
+    if( firstDigit == '0' ) {
+        if( ++i == length ) {
+            return valueOf( 0 );
+        }
+
+        if( ( firstDigit = value[i] ) == 'x' || firstDigit == 'X' ) {
+            if( i == length ) {
+                throw NumberFormatException(
+                    __FILE__, __LINE__,
+                    "Integer:decode - Invalid zero string, minus only");
+            }
+            i++;
+            base = 16;
+        } else {
+            base = 8;
+        }
+    } else if( firstDigit == '#' ) {
+        if( i == length ) {
+            throw NumberFormatException(
+                __FILE__, __LINE__,
+                "Integer:decode - Invalid zero string, minus only");
+        }
+        i++;
+        base = 16;
+    }
+
+    int result = parse( value, i, base, negative );
+    return valueOf( result );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -84,7 +177,6 @@
     int result = 0, length = value.size();
 
     while( offset < length ) {
-        //TODO
         int digit = Character::digit( value[offset++], radix );
         if( digit == -1 ) {
             throw NumberFormatException(

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.h?view=diff&rev=560833&r1=560832&r2=560833
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Integer.h Sun Jul 29 16:41:51
2007
@@ -203,14 +203,16 @@
          * @param value - the int to wrap
          * @return the new Integer object wrapping value.
          */
-        static Integer valueOf( int value );
+        static Integer valueOf( int value ) {
+            return Integer( value );
+        }
 
         /**
-         * Returns a Integer object holding the value given by the specified std::string.
-         * The argument is interpreted as representing a signed decimal int,
-         * exactly as if the argument were given to the parseInteger( std::string )
-         * method. The result is a Integer object that represents the int value
-         * specified by the string.
+         * Returns a Integer object holding the value given by the specified
+         * std::string.  The argument is interpreted as representing a signed
+         * decimal int, exactly as if the argument were given to the
+         * parseInt( std::string ) method. The result is a Integer object that
+         * represents the int value specified by the string.
          * @param value - std::string to parse as base 10
          * @return new Integer Object wrapping the primitive
          * @throws NumberFormatException if the string is not a decimal int.
@@ -223,7 +225,7 @@
          * std::string when parsed with the radix given by the second argument.
          * The first argument is interpreted as representing a signed int in the
          * radix specified by the second argument, exactly as if the argument were
-         * given to the parseInteger( std::string, int ) method. The result is a
+         * given to the parseInt( std::string, int ) method. The result is a
          * Integer object that represents the int value specified by the string.
          * @param value - std::string to parse as base ( radix )
          * @param radix - base of the string to parse.



Mime
View raw message