Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.

Commit message:
* Added numeric_type to json::token.
* Removed createJSONNumber().
* Added constructors and assignment operators to Integer, Decimal, and Float 
that take a string type.
* Clean-up of now unnecessary use of c_str().

Requested reviews:
  Paul J. Lucas (paul-lucas)

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/170225

* Added numeric_type to json::token.
* Removed createJSONNumber().
* Added constructors and assignment operators to Integer, Decimal, and Float 
that take a string type.
* Clean-up of now unnecessary use of c_str().
-- 
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/170225
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'doc/cxx/examples/jsoniq.cpp'
--- doc/cxx/examples/jsoniq.cpp	2013-02-07 17:24:36 +0000
+++ doc/cxx/examples/jsoniq.cpp	2013-06-19 00:06:30 +0000
@@ -201,7 +201,7 @@
 bool
 example_7(Zorba* aZorba)
 {
-  Item lNum = aZorba->getItemFactory()->createJSONNumber(String("12345"));
+  Item lNum = aZorba->getItemFactory()->createInteger(String("12345"));
   if (lNum.getType().getLocalName().compare("integer") != 0) {
     std::cout << "Didn't create an xs:integer!";
     return false;
@@ -210,7 +210,7 @@
     return false;
   }
 
-  lNum = aZorba->getItemFactory()->createJSONNumber(String("123.345"));
+  lNum = aZorba->getItemFactory()->createDecimal(String("123.345"));
   if (lNum.getType().getLocalName().compare("decimal") != 0) {
     std::cout << "Didn't create an xs:decimal!";
     return false;
@@ -219,7 +219,7 @@
     return false;
   }
 
-  lNum = aZorba->getItemFactory()->createJSONNumber(String("12.34e5"));
+  lNum = aZorba->getItemFactory()->createDouble(String("12.34e5"));
   if (lNum.getType().getLocalName().compare("double") != 0) {
     std::cout << "Didn't create an xs:double!";
     return false;
@@ -236,7 +236,7 @@
  */
 bool example_8(Zorba* aZorba)
 {
-  Item lValue = aZorba->getItemFactory()->createJSONNumber("1234");
+  Item lValue = aZorba->getItemFactory()->createInteger(1234);
   Item lName = aZorba->getItemFactory()->createString("name");
   std::vector<std::pair<Item, Item> > pairs;
   pairs.push_back(std::pair<Item, Item>(lName, lValue));

=== modified file 'include/zorba/item_factory.h'
--- include/zorba/item_factory.h	2013-06-15 02:57:08 +0000
+++ include/zorba/item_factory.h	2013-06-19 00:06:30 +0000
@@ -769,15 +769,6 @@
       virtual Item createJSONNull() = 0;
 
       /**
-       * Create a JSON Number item from a string. This will actually be
-       * an xs:integer, xs:double, or xs:decimal, depending on the content
-       * of the string.
-       *
-       * @param aString The input string.
-       */
-      virtual Item createJSONNumber(String aString) = 0;
-
-      /**
        * Create a JSON Object containing the specified JSON Pairs.
        *
        * @param aNames A vector containing the name and value of each pair.

=== modified file 'src/api/dynamiccontextimpl.cpp'
--- src/api/dynamiccontextimpl.cpp	2013-05-08 20:14:47 +0000
+++ src/api/dynamiccontextimpl.cpp	2013-06-19 00:06:30 +0000
@@ -730,7 +730,7 @@
 {
   ZORBA_DCTX_TRY
   {
-    std::string lName = aName.c_str();
+    std::string lName( aName.c_str() );
     return theCtx->addExternalFunctionParam(lName, aValue);
   }
   ZORBA_DCTX_CATCH
@@ -747,7 +747,7 @@
 {
   ZORBA_DCTX_TRY
   {
-    std::string lName = aName.c_str();
+    std::string lName( aName.c_str() );
     return theCtx->getExternalFunctionParam(lName, aValue);
   }
   ZORBA_DCTX_CATCH
@@ -765,7 +765,7 @@
 {
   ZORBA_DCTX_TRY
   {
-    std::string lName = aName.c_str();
+    std::string lName( aName.c_str() );
     return theCtx->addExternalFunctionParameter(lName, aValue);
   }
   ZORBA_DCTX_CATCH
@@ -781,7 +781,7 @@
 {
   ZORBA_DCTX_TRY
   {
-    std::string lName = aName.c_str();
+    std::string lName( aName.c_str() );
     return theCtx->getExternalFunctionParameter(lName);
   }
   ZORBA_DCTX_CATCH

=== modified file 'src/api/itemfactoryimpl.cpp'
--- src/api/itemfactoryimpl.cpp	2013-06-15 02:57:08 +0000
+++ src/api/itemfactoryimpl.cpp	2013-06-19 00:06:30 +0000
@@ -298,7 +298,7 @@
 Item ItemFactoryImpl::createDecimalFromLong (unsigned long aValue)
 {
   store::Item_t lItem;
-  Decimal const lDecimal(aValue);
+  xs_decimal const lDecimal(aValue);
   theItemFactory->createDecimal(lItem, lDecimal);
   return &*lItem;
 }
@@ -308,7 +308,7 @@
 {
   store::Item_t lItem;
   try {
-    Decimal const lDecimal(aValue);
+    xs_decimal const lDecimal(aValue);
     theItemFactory->createDecimal(lItem, lDecimal);
   }
   catch ( std::invalid_argument const& ) {
@@ -323,7 +323,7 @@
   store::Item_t lItem;
   zstring lString = Unmarshaller::getInternalString(aValue);
   try {
-    Decimal const lDecimal(lString.c_str());
+    xs_decimal const lDecimal(lString);
     theItemFactory->createDecimal(lItem, lDecimal);
   }
   catch ( std::exception const& ) {
@@ -349,7 +349,7 @@
   zstring const &lString = Unmarshaller::getInternalString( aInteger );
   store::Item_t lItem;
   try {
-    xs_integer const lInteger( lString.c_str() );
+    xs_integer const lInteger( lString );
     theItemFactory->createInteger(lItem, lInteger);
   }
   catch ( std::exception const& ) {
@@ -475,7 +475,7 @@
 
   store::Item_t lItem;
   try {
-    xs_double const lDouble(lString.c_str());
+    xs_double const lDouble(lString);
     theItemFactory->createDouble(lItem, lDouble);
   }
   catch ( std::exception const& ) {
@@ -549,7 +549,7 @@
   zstring const &lString = Unmarshaller::getInternalString( aValue );
   store::Item_t lItem;
   try {
-    xs_float const lFloat(lString.c_str());
+    xs_float const lFloat(lString);
     theItemFactory->createFloat(lItem, lFloat);
   } 
   catch ( std::exception const& ) {
@@ -960,15 +960,6 @@
   return &*lItem;
 }
 
-zorba::Item ItemFactoryImpl::createJSONNumber(String aString)
-{
-  store::Item_t lItem;
-  zstring &lString = Unmarshaller::getInternalString(aString);
-  theItemFactory->createJSONNumber(lItem, lString);
-  return &*lItem;
-}
-
-
 zorba::Item ItemFactoryImpl::createJSONObject(
     std::vector<std::pair<Item, Item> >& aPairs)
 {

=== modified file 'src/api/itemfactoryimpl.h'
--- src/api/itemfactoryimpl.h	2013-06-15 02:57:08 +0000
+++ src/api/itemfactoryimpl.h	2013-06-19 00:06:30 +0000
@@ -292,9 +292,6 @@
       createJSONNull();
 
       virtual Item
-      createJSONNumber(String aString);
-
-      virtual Item
       createJSONObject(std::vector<std::pair<Item, Item> >& aPairs);
 
       virtual Item

=== modified file 'src/capi/csequence.cpp'
--- src/capi/csequence.cpp	2013-05-15 23:22:01 +0000
+++ src/capi/csequence.cpp	2013-06-19 00:06:30 +0000
@@ -351,8 +351,8 @@
     me->theStrings.push_back(lUri);
     zorba::String lLocal = lItem.getLocalName();
     me->theStrings.push_back(lLocal);
-    (*uri) = lUri.c_str();
-    (*name) = lLocal.c_str();
+    *uri = lUri.c_str();
+    *name = lLocal.c_str();
   }
   SEQ_CATCH;
 }
@@ -367,7 +367,7 @@
     }
     zorba::String lString = me->theItem.getStringValue();
     me->theStrings.push_back(lString);
-    (*value) = lString.c_str();
+    *value = lString.c_str();
   }
   SEQ_CATCH;
 }
@@ -439,8 +439,8 @@
         // de-allocated memory.
         try {
           String const lStringValue = me->theItem.getStringValue();
-          xs_double const doublevalue( lStringValue.c_str() );
-          (*value) = static_cast<double> (doublevalue.getNumber());
+          xs_double const doublevalue( lStringValue );
+          *value = static_cast<double> (doublevalue.getNumber());
         }
         catch ( std::exception const& ) {
           return XQC_TYPE_ERROR;
@@ -474,8 +474,8 @@
     me->theStrings.push_back(lUri);
     zorba::String lName = lNodeName->getLocalName();
     me->theStrings.push_back(lName);
-    (*uri) = lUri.c_str();
-    (*name) = lName.c_str();
+    *uri = lUri.c_str();
+    *name = lName.c_str();
   }
   SEQ_CATCH;
 }

=== modified file 'src/capi/cstatic_context.cpp'
--- src/capi/cstatic_context.cpp	2013-02-07 17:24:36 +0000
+++ src/capi/cstatic_context.cpp	2013-06-19 00:06:30 +0000
@@ -164,7 +164,7 @@
         getNamespaceURIByPrefix(prefix);
       me->theStrings.push_back(lNS);
 
-      (*result_ns) = lNS.c_str();
+      *result_ns = lNS.c_str();
     }
     SC_CATCH;
   }
@@ -187,7 +187,7 @@
       zorba::String lURI = me->theContext.get()->
         getDefaultElementAndTypeNamespace();
       me->theStrings.push_back(lURI);
-      (*uri) = lURI.c_str();
+      *uri = lURI.c_str();
     }
     SC_CATCH;
   }
@@ -209,7 +209,7 @@
     SC_TRY {
       zorba::String lURI = me->theContext.get()->getDefaultFunctionNamespace();
       me->theStrings.push_back(lURI);
-      (*uri) = lURI.c_str();
+      *uri = lURI.c_str();
     }
     SC_CATCH;
   }
@@ -241,7 +241,7 @@
     SC_TRY {
       zorba::String lURI = me->theContext.get()->getDefaultCollation();
       me->theStrings.push_back(lURI);
-      (*uri) = lURI.c_str();
+      *uri = lURI.c_str();
     }
     SC_CATCH;
   }
@@ -597,7 +597,7 @@
     SC_TRY {
       zorba::String lBaseURI = me->theContext.get()->getBaseURI();
       me->theStrings.push_back(lBaseURI);
-      (*base_uri) = lBaseURI.c_str();
+      *base_uri = lBaseURI.c_str();
     }
     SC_CATCH;
   }

=== modified file 'src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp'
--- src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp	2013-06-07 13:46:26 +0000
+++ src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp	2013-06-19 00:06:30 +0000
@@ -181,7 +181,7 @@
           }
         }
       }
-      zstring lTmp = lAttrValue.str().c_str();
+      zstring lTmp( lAttrValue.str() );
       store::Item_t lAttrValueItem;
       theFactory->createString(lAttrValueItem, lTmp);
 

=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp	2013-06-15 02:57:08 +0000
+++ src/context/static_context.cpp	2013-06-19 00:06:30 +0000
@@ -3430,7 +3430,7 @@
   if (theDefaultCollation != NULL || !is_known_collation(uri))
     throw XQUERY_EXCEPTION(err::XQST0038, ERROR_LOC(loc));
 
-  zstring resolvedUri = resolve_relative_uri(uri);
+  zstring const resolvedUri( resolve_relative_uri(uri) );
 
   theDefaultCollation = new std::string(resolvedUri.c_str());
 }

=== modified file 'src/runtime/json/json_loader.cpp'
--- src/runtime/json/json_loader.cpp	2013-06-15 02:57:08 +0000
+++ src/runtime/json/json_loader.cpp	2013-06-19 00:06:30 +0000
@@ -26,6 +26,9 @@
 #include "diagnostics/xquery_diagnostics.h"
 #include "store/api/item_factory.h"
 #include "system/globalenv.h"
+#include "zorbatypes/decimal.h"
+#include "zorbatypes/float.h"
+#include "zorbatypes/integer.h"
 #include "zorbatypes/zstring.h"
 
 // local
@@ -179,7 +182,19 @@
           continue;
         case token::number:
           s = t.get_value();
-          GENV_ITEMFACTORY->createJSONNumber( item, s );
+          switch ( t.get_numeric_type() ) {
+            case token::integer:
+              GENV_ITEMFACTORY->createInteger( item, xs_integer( s ) );
+              break;
+            case token::decimal:
+              GENV_ITEMFACTORY->createDecimal( item, xs_decimal( s ) );
+              break;
+            case token::floating_point:
+              GENV_ITEMFACTORY->createDouble( item, xs_double( s ) );
+              break;
+            default:
+              assert( false );
+          }
           break;
         case token::string:
           s = t.get_value();

=== modified file 'src/store/api/item_factory.h'
--- src/store/api/item_factory.h	2013-06-15 02:57:08 +0000
+++ src/store/api/item_factory.h	2013-06-19 00:06:30 +0000
@@ -797,10 +797,6 @@
 
   virtual bool createJSONNull(Item_t& result) = 0;
 
-  virtual bool createJSONNumber(Item_t& result, Item_t& string) = 0;
-
-  virtual bool createJSONNumber(Item_t& result, zstring& string) = 0;
-
   /**
    *
    */

=== modified file 'src/store/naive/atomic_items.cpp'
--- src/store/naive/atomic_items.cpp	2013-05-28 17:08:27 +0000
+++ src/store/naive/atomic_items.cpp	2013-06-19 00:06:30 +0000
@@ -495,7 +495,7 @@
 {
   try 
   {
-    xs_double const doubleValue(theValue.c_str());
+    xs_double const doubleValue(theValue);
     return GET_FACTORY().createDouble(result, doubleValue);
   }
   catch ( std::exception const& ) 
@@ -510,7 +510,7 @@
 {
   try
   {
-    xs_decimal const decValue(theValue.c_str());
+    xs_decimal const decValue(theValue);
     return GET_FACTORY().createDecimal(result, decValue);
   }
   catch ( std::exception const& )
@@ -525,7 +525,7 @@
 {
   try
   {
-    xs_integer const intValue(theValue.c_str());
+    xs_integer const intValue(theValue);
     return GET_FACTORY().createInteger(result, intValue);
   }
   catch ( std::exception const& )

=== modified file 'src/store/naive/simple_item_factory.cpp'
--- src/store/naive/simple_item_factory.cpp	2013-06-15 02:57:08 +0000
+++ src/store/naive/simple_item_factory.cpp	2013-06-19 00:06:30 +0000
@@ -2231,58 +2231,6 @@
 /*******************************************************************************
 
 ********************************************************************************/
-bool BasicItemFactory::createJSONNumber(
-    store::Item_t& result,
-    store::Item_t& string)
-{
-  zstring s = string->getStringValue();
-  return createJSONNumber(result, s);
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-bool BasicItemFactory::createJSONNumber(
-    store::Item_t& result,
-    zstring& string)
-{
-  try
-  {
-    bool dot = (strchr(string.c_str(), 46) != NULL);
-    bool e   = (strpbrk(string.c_str(), "eE") != NULL);
-    if (!e)
-    {
-      if (!dot)
-      {
-        // xs:integer
-        xs_integer i = Integer(string.c_str());
-        return createInteger(result, i);
-      }
-      else
-      {
-        // xs:decimal
-        xs_decimal d = Decimal(string.c_str());
-        return createDecimal(result, d);
-      }
-    }
-    else
-    {
-      // xs:double
-      xs_double d = FloatImpl<double>(string.c_str());
-      return createDouble(result, d);
-    }
-  }
-  catch (std::exception const&)
-  {
-    return false;
-  }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
 bool BasicItemFactory::createJSONArray(
     store::Item_t& result,
     const std::vector<store::Iterator_t>& sources,

=== modified file 'src/store/naive/simple_item_factory.h'
--- src/store/naive/simple_item_factory.h	2013-06-15 02:57:08 +0000
+++ src/store/naive/simple_item_factory.h	2013-06-19 00:06:30 +0000
@@ -414,14 +414,6 @@
 
   bool createJSONNull(store::Item_t& result);
 
-  bool createJSONNumber(
-      store::Item_t& result,
-      store::Item_t& string);
-
-  bool createJSONNumber(
-      store::Item_t& result,
-      zstring& string);
-
   bool createJSONArray(
       store::Item_t& result,
       const std::vector<store::Iterator_t>& sources,

=== modified file 'src/types/casting.cpp'
--- src/types/casting.cpp	2013-06-18 09:10:28 +0000
+++ src/types/casting.cpp	2013-06-19 00:06:30 +0000
@@ -346,7 +346,7 @@
 {
   try 
   {
-    xs_float const n(strval.c_str());
+    xs_float const n(strval);
     aFactory->createFloat(result, n);
   }
   catch (std::invalid_argument const&) 
@@ -364,7 +364,7 @@
 {
   try 
   {
-    xs_double const n(strval.c_str());
+    xs_double const n(strval);
     aFactory->createDouble(result, n);
   }
   catch (std::invalid_argument const& ) 
@@ -382,7 +382,7 @@
 {
   try 
   {
-    xs_decimal const n(strval.c_str());
+    xs_decimal const n(strval);
     aFactory->createDecimal(result, n);
   }
   catch (const std::invalid_argument& ) 
@@ -400,7 +400,7 @@
 {
   try 
   {
-    xs_integer const n(strval.c_str());
+    xs_integer const n(strval);
     aFactory->createInteger(result, n);
   }
   catch (const std::invalid_argument& ) 
@@ -418,7 +418,7 @@
 {
   try 
   {
-    xs_nonNegativeInteger const n(strval.c_str());
+    xs_nonNegativeInteger const n(strval);
     aFactory->createNonNegativeInteger(result, n);
   }
   catch ( std::invalid_argument const& )

=== modified file 'src/types/schema/XercesParseUtils.cpp'
--- src/types/schema/XercesParseUtils.cpp	2013-05-15 23:22:01 +0000
+++ src/types/schema/XercesParseUtils.cpp	2013-06-19 00:06:30 +0000
@@ -466,7 +466,7 @@
     utf8::normalize_space(textValue, &textValue2);
     try
     {
-      xs_float const n(textValue2.c_str());
+      xs_float const n(textValue2);
       return GENV_ITEMFACTORY->createFloat(result, n);
     }
     catch ( std::exception const& ) {
@@ -504,7 +504,7 @@
     utf8::normalize_space(textValue, &textValue2);
     store::ItemFactory* factory = GENV_ITEMFACTORY;
     try {
-      xs_double const n(textValue2.c_str());
+      xs_double const n(textValue2);
       return factory->createDouble(result, n);
     }
     catch ( std::exception const& ) {

=== modified file 'src/util/json_parser.cpp'
--- src/util/json_parser.cpp	2013-02-07 17:24:36 +0000
+++ src/util/json_parser.cpp	2013-06-19 00:06:30 +0000
@@ -156,7 +156,7 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-token::token() : type_( none ) {
+token::token() : type_( none ), numeric_type_( non_numeric ) {
 }
 
 ostream& operator<<( ostream &o, token::type tt ) {
@@ -340,7 +340,8 @@
   return tt;
 }
 
-void lexer::parse_number( char first_c, token::value_type *value ) {
+token::numeric_type lexer::parse_number( char first_c,
+                                         token::value_type *value ) {
   value->clear();
 
   // <number> ::= [-] <int> [<frac>] [<exp>]
@@ -355,13 +356,14 @@
   if ( !ascii::is_digit( c ) )
     throw illegal_number( cur_loc_ );
   *value += c;
+  token::numeric_type numeric_type = token::integer;
   if ( c == '0' ) {
     if ( !get_char( &c ) )
-      return;
+      goto done;
   } else {
     while ( true ) {
       if ( !get_char( &c ) )
-        return;
+        goto done;
       if ( !ascii::is_digit( c ) )
         break;
       *value += c;
@@ -374,9 +376,10 @@
     if ( !get_char( &c ) || !ascii::is_digit( c ) )
       throw illegal_number( cur_loc_ );
     *value += c;
+    numeric_type = token::decimal;
     while ( true ) {
       if ( !get_char( &c ) )
-        return;
+        goto done;
       if ( !ascii::is_digit( c ) )
         break;
       *value += c;
@@ -398,9 +401,10 @@
     if ( !ascii::is_digit( c ) )
       throw illegal_number( cur_loc_ );
     *value += c;
+    numeric_type = token::floating_point;
     while ( true ) {
       if ( !get_char( &c ) )
-        return;
+        goto done;
       if ( !ascii::is_digit( c ) )
         break;
       *value += c;
@@ -408,6 +412,8 @@
   }
 
   in_->putback( c );
+done:
+  return numeric_type;
 }
 
 void lexer::parse_string( token::value_type *value ) {

=== modified file 'src/util/json_parser.h'
--- src/util/json_parser.h	2013-06-01 00:30:39 +0000
+++ src/util/json_parser.h	2013-06-19 00:06:30 +0000
@@ -94,6 +94,17 @@
   };
 
   /**
+   * The numeric types of \c number tokens in JSON.  Note that this is an
+   * extension since JSON does not distinguish between numeric types.
+   */
+  enum numeric_type {
+    non_numeric,
+    integer         = 'i',
+    decimal         = 'd',
+    floating_point  = 'f',
+  };
+
+  /**
    * Default constructor.
    */
   token();
@@ -103,6 +114,7 @@
    */
   void clear() {
     type_ = none;
+    numeric_type_ = non_numeric;
     value_.clear();
   }
 
@@ -125,6 +137,15 @@
   }
 
   /**
+   * Gets the numeric type of this %token if it's type is \c number.
+   *
+   * @return Returns said type or \c non_numeric if the type is not \c number.
+   */
+  numeric_type get_numeric_type() const {
+    return numeric_type_;
+  }
+
+  /**
    * Gets the value of this %token, if any.  Only %token types string, number,
    * false, null, and true have a value.
    *
@@ -146,6 +167,7 @@
 private:
   location loc_;
   type type_;
+  numeric_type numeric_type_;
   value_type value_;
 
   friend class lexer;
@@ -476,7 +498,7 @@
   bool peek_char( char* );
   unicode::code_point parse_codepoint();
   token::type parse_literal( char, token::value_type* );
-  void parse_number( char, token::value_type* );
+  token::numeric_type parse_number( char, token::value_type* );
   void parse_string( token::value_type* );
 
   std::istream *in_;

=== modified file 'src/zorbaserialization/serialize_basic_types.cpp'
--- src/zorbaserialization/serialize_basic_types.cpp	2013-05-15 23:22:01 +0000
+++ src/zorbaserialization/serialize_basic_types.cpp	2013-06-19 00:06:30 +0000
@@ -397,7 +397,7 @@
 
     ar.read_next_simple_temp_field(TYPE_ZSTRING, &float_str);
 
-    FloatImpl<float> zorba_float(float_str.c_str());
+    FloatImpl<float> zorba_float(float_str);
     obj = zorba_float.getNumber();
   }
 }
@@ -428,7 +428,7 @@
 
     ar.read_next_simple_temp_field(TYPE_ZSTRING, &double_str);
 
-    FloatImpl<double> zorba_double(double_str.c_str());
+    FloatImpl<double> zorba_double(double_str);
     obj = zorba_double.getNumber();
   }
 }

=== modified file 'src/zorbatypes/decimal.h'
--- src/zorbatypes/decimal.h	2013-06-07 21:22:39 +0000
+++ src/zorbatypes/decimal.h	2013-06-19 00:06:30 +0000
@@ -75,6 +75,17 @@
   explicit Decimal( char const *s );
 
   /**
+   * Constructs a %Decimal from a string.
+   *
+   * @tparam StringType The string type.
+   * @param s The string to parse.  Leading and trailing whitespace is ignored.
+   * @throw std::invalid_argument if \a s does not contain a valid decimal.
+   */
+  template<class StringType>
+  explicit Decimal( StringType const &s,
+    typename std::enable_if<ZORBA_HAS_C_STR(StringType)>::type* = nullptr );
+
+  /**
    * Constructs a %Decimal from a Double.
    *
    * @param n The Double.
@@ -120,6 +131,11 @@
   Decimal& operator=( unsigned long long n );
 
   Decimal& operator=( char const *s );
+
+  template<class StringType>
+  typename std::enable_if<ZORBA_HAS_C_STR(StringType),Decimal&>::type
+  operator=( StringType const &s );
+
   Decimal& operator=( Double const &d );
   Decimal& operator=( Float const &f );
 
@@ -276,6 +292,13 @@
   parse( s, &value_ );
 }
 
+template<class StringType>
+inline Decimal::Decimal( StringType const &s,
+  typename std::enable_if<ZORBA_HAS_C_STR(StringType)>::type* )
+{
+  parse( s.c_str(), &value_ );
+}
+
 inline Decimal::Decimal( Decimal const &d ) : value_( d.value_ )
 {
 }
@@ -309,6 +332,12 @@
   return *this;
 }
 
+template<class StringType> inline
+typename std::enable_if<ZORBA_HAS_C_STR(StringType),Decimal&>::type
+Decimal::operator=( StringType const &s ) {
+  return operator=( s.c_str() );
+}
+
 ////////// arithmetic operators ///////////////////////////////////////////////
 
 #define ZORBA_DECIMAL_OP(OP)                                            \

=== modified file 'src/zorbatypes/float.h'
--- src/zorbatypes/float.h	2013-05-18 14:36:06 +0000
+++ src/zorbatypes/float.h	2013-06-19 00:06:30 +0000
@@ -79,6 +79,20 @@
   explicit FloatImpl( char const *s );
 
   /**
+   * Constructs a %FloatImpl from a string.
+   *
+   * @tparam StringType The string type.
+   * @param s The string to parse.  Leading and trailing whitespace is ignored.
+   * @throw std::invalid_argument if \a s does not contain a valid floating
+   * point number.
+   * @throw std::range_error if \a s contains a number that either underflows
+   * or overflows the smallest or largest representable floating point number.
+   */
+  template<class StringType>
+  explicit FloatImpl( StringType const &s,
+    typename std::enable_if<ZORBA_HAS_C_STR(StringType)>::type* = nullptr );
+
+  /**
    * Constructs from another %FloatImpl even if its \c FloatType is different.
    * (This subsumes the conventional copy constructor.)
    *
@@ -116,6 +130,11 @@
   FloatImpl& operator=( double n );
 
   FloatImpl& operator=( char const *s );
+
+  template<class StringType>
+  typename std::enable_if<ZORBA_HAS_C_STR(StringType),FloatImpl&>::type
+  operator=( StringType const &s );
+
   FloatImpl& operator=( Decimal const &d );
 
   template<class T>
@@ -399,6 +418,14 @@
 }
 
 template<typename F>
+template<class StringType>
+inline FloatImpl<F>::FloatImpl( StringType const &s,
+  typename std::enable_if<ZORBA_HAS_C_STR(StringType)>::type* )
+{
+  parse( s.c_str() );
+}
+
+template<typename F>
 template<typename G>
 inline FloatImpl<F>::FloatImpl( FloatImpl<G> const &f ) :
   value_( static_cast<F>( f.value_ ) ), precision_( max_precision() )
@@ -442,6 +469,13 @@
   return *this;
 }
 
+template<typename F>
+template<class StringType> inline
+typename std::enable_if<ZORBA_HAS_C_STR(StringType),FloatImpl<F>&>::type
+FloatImpl<F>::operator=( StringType const &s ) {
+  return operator=( s.c_str() );
+}
+
 ////////// arithmetic operators ///////////////////////////////////////////////
 
 #define ZORBA_FLOAT_OP(OP,T)                                      \

=== modified file 'src/zorbatypes/integer.h'
--- src/zorbatypes/integer.h	2013-06-07 21:22:39 +0000
+++ src/zorbatypes/integer.h	2013-06-19 00:06:30 +0000
@@ -175,6 +175,19 @@
   explicit IntegerImpl( char const *s );
 
   /**
+   * Constructs an %IntegerImpl from a string.
+   *
+   * @tparam StringType The string type.
+   * @param s The string to parse.  Leading and trailing whitespace is ignored.
+   * @throw std::invalid_argument if \a s does not contain a valid integer.
+   * @throw std::range_error if \a s contains an integer that either underflows
+   * or overflows the smallest or largest representable/legal integer.
+   */
+  template<class StringType>
+  explicit IntegerImpl( StringType const &s,
+    typename std::enable_if<ZORBA_HAS_C_STR(StringType)>::type* = nullptr );
+
+  /**
    * Constructs an %IntegerImpl from a Double.
    *
    * @param d The Double.
@@ -232,6 +245,11 @@
   IntegerImpl& operator=( double n );
 
   IntegerImpl& operator=( char const *s );
+
+  template<class StringType>
+  typename std::enable_if<ZORBA_HAS_C_STR(StringType),IntegerImpl&>::type
+  operator=( StringType const &s );
+
   IntegerImpl& operator=( Decimal const &d );
   IntegerImpl& operator=( Double const &d );
   IntegerImpl& operator=( Float const &f );
@@ -721,6 +739,14 @@
 }
 
 template<class T>
+template<class StringType>
+inline IntegerImpl<T>::IntegerImpl( StringType const &s,
+  typename std::enable_if<ZORBA_HAS_C_STR(StringType)>::type* )
+{
+  parse( s.c_str() );
+}
+
+template<class T>
 template<class U>
 inline IntegerImpl<T>::IntegerImpl( IntegerImpl<U> const &i ) :
   value_( T::check_value( i.value_ ) )
@@ -760,6 +786,13 @@
 }
 
 template<class T>
+template<class StringType> inline
+typename std::enable_if<ZORBA_HAS_C_STR(StringType),IntegerImpl<T>&>::type
+IntegerImpl<T>::operator=( StringType const &s ) {
+  return operator=( s.c_str() );
+}
+
+template<class T>
 template<class U>
 inline IntegerImpl<T>& IntegerImpl<T>::operator=( IntegerImpl<U> const &i ) {
   T::check_value( value_ = i.value_ );

=== modified file 'swig/ItemFactory.h'
--- swig/ItemFactory.h	2013-04-17 17:49:23 +0000
+++ swig/ItemFactory.h	2013-06-19 00:06:30 +0000
@@ -606,16 +606,6 @@
     Item createJSONNull();
 
     /**
-     * \brief Create a JSON Number item from a string. 
-     * This will actually be
-     * an xs:integer, xs:double, or xs:decimal, depending on the content
-     * of the string.
-     *
-     * @param aString The input string.
-     */
-    Item createJSONNumber(std::string aString);
-
-    /**
      * \brief Create a JSON Object containing the specified JSON Pairs.
      *
      * @param aNames A vector containing the name and value of each pair.
@@ -675,4 +665,4 @@
     
 }; // class ItemFactory
 
-#endif
\ No newline at end of file
+#endif

=== modified file 'swig/ItemFactory.i'
--- swig/ItemFactory.i	2013-04-17 17:49:23 +0000
+++ swig/ItemFactory.i	2013-06-19 00:06:30 +0000
@@ -224,10 +224,6 @@
     return Item( theItemFactory->createJSONNull() );
   }
 
-  Item ItemFactory::createJSONNumber(std::string aString) {
-    return Item( theItemFactory->createJSONNumber(aString));
-  }
-
   Item ItemFactory::createJSONObject(std::vector<std::pair<Item, Item> >& aNames) {
     std::vector< std::pair< zorba::Item, zorba::Item > > names;
     names.reserve(aNames.size());

=== modified file 'swig/csharp/tests/test10.cs'
--- swig/csharp/tests/test10.cs	2013-03-26 01:56:30 +0000
+++ swig/csharp/tests/test10.cs	2013-06-19 00:06:30 +0000
@@ -40,7 +40,7 @@
             System.Console.WriteLine( "Creating JSON Item null:  " +  iNull.serialize());
             iNull.Dispose();
             
-            Item iNumber = itemFactory.createJSONNumber("5");
+            Item iNumber = itemFactory.createInteger(5);
             System.Console.WriteLine( "Creating JSON Item number:  " + iNumber.serialize() );
             iNumber.Dispose();
             

=== modified file 'swig/php/tests/test11.php'
--- swig/php/tests/test11.php	2013-03-26 01:56:30 +0000
+++ swig/php/tests/test11.php	2013-06-19 00:06:30 +0000
@@ -29,7 +29,7 @@
   try {
     $itemFactory = $aZorba->getItemFactory();
     print "Creating JSON Item null:  ". $itemFactory->createJSONNull()->serialize() . "\n";
-    print "Creating JSON Item number:  ". $itemFactory->createJSONNumber("5")->serialize() . "\n";
+    print "Creating JSON Item number:  ". $itemFactory->createInteger(5)->serialize() . "\n";
     $sv = new StringVector(4);
     $sv->set(0, "Hello");
     $sv->set(1, "Zorba");

=== modified file 'swig/python/tests/test13.py'
--- swig/python/tests/test13.py	2013-03-22 23:40:03 +0000
+++ swig/python/tests/test13.py	2013-06-19 00:06:30 +0000
@@ -20,7 +20,7 @@
   try:
     itemFactory = zorba.getItemFactory()
     print "Creating JSON Item null:  ", itemFactory.createJSONNull().serialize()
-    print "Creating JSON Item null:  ", itemFactory.createJSONNumber("5").serialize()
+    print "Creating JSON Item null:  ", itemFactory.createInteger(5).serialize()
     sv = zorba_api.StringVector(4)
     sv[0]="Hello"
     sv[1]="Zorba"

=== modified file 'swig/ruby/tests/test13.rb'
--- swig/ruby/tests/test13.rb	2013-03-26 01:56:30 +0000
+++ swig/ruby/tests/test13.rb	2013-06-19 00:06:30 +0000
@@ -18,7 +18,7 @@
   begin
     itemFactory = zorba.getItemFactory()
     print "Creating JSON Item null:  ", itemFactory.createJSONNull().serialize()
-    print "Creating JSON Item number:  ", itemFactory.createJSONNumber("5").serialize()
+    print "Creating JSON Item number:  ", itemFactory.createInteger(5).serialize()
     sv = Zorba_api.StringVector(4)
     sv[0]="Hello"
     sv[1]="Zorba"
@@ -38,4 +38,4 @@
 test(zorba)
 
 zorba.shutdown()
-Zorba_api::InMemoryStore.shutdown(store)
\ No newline at end of file
+Zorba_api::InMemoryStore.shutdown(store)

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to