Example #1
0
static void get_options( store::Item_t const &options_object,
                         options_type *options ) {
  ZORBA_ASSERT( options_object->getKind() == store::Item::OBJECT );
  store::Iterator_t i( options_object->getObjectKeys() );
  i->open();
  store::Item_t opt_key;
  while ( i->next( opt_key ) ) {
    zstring const opt_name( opt_key->getStringValue() );
    store::Item_t const opt_value( options_object->getObjectValue( opt_key ) );
    (*options)[ opt_name ] = opt_value->getStringValue();
  }
  i->close();
}
Example #2
0
void json_to_xml( store::Item_t const &json_item, store::Item_t *xml_item ) {
  ZORBA_ASSERT( xml_item );
  switch ( json_item->getKind() ) {
    case store::Item::ARRAY:
      *xml_item = j2x_array( json_item, nullptr );
      break;
    case store::Item::OBJECT:
      throw XQUERY_EXCEPTION(
        zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
        ERROR_PARAMS( ZED( ZJ2X0001_ArrayRequired ) )
      );
    default:
      ZORBA_ASSERT( false );
  }
}
Example #3
0
bool deepEqual(
    const QueryLoc& loc,
    static_context* sctx,
    store::Item_t& item1,
    store::Item_t& item2,
    XQPCollator* collator,
    int timezone,
    bool raiseError)
{
  if (item1->isFunction() || item2->isFunction())
  {
    if (raiseError)
    {
      RAISE_ERROR(err::FOTY0015, loc,
        ERROR_PARAMS((item1->isFunction() ? item1 : item2)->getFunctionName()->getStringValue()));
    }
    else
      return false;
  }

  if (item1->getKind() != item2->getKind())
    return false;

  switch (item1->getKind())
  {
  case store::Item::ATOMIC:
  {
    assert(item2->isAtomic());

    store::SchemaTypeCode type1 = item1->getTypeCode();
    store::SchemaTypeCode type2 = item2->getTypeCode();

    // check if both items are NaN
    if (((type1 == store::XS_FLOAT && item1->getFloatValue().isNaN()) ||
         (type1 == store::XS_DOUBLE && item1->getDoubleValue().isNaN()))
        &&
        ((type2 == store::XS_FLOAT && item2->getFloatValue().isNaN()) ||
         (type2 == store::XS_DOUBLE && item2->getDoubleValue().isNaN())))
    {
      return true;
    }

    if (raiseError)
    {
      try
      {
        TypeManager* tm = sctx->get_typemanager();
        return CompareIterator::valueEqual(loc, item1, item2, tm, timezone, collator, raiseError);
       }
       catch (ZorbaException const& e)
       {
        if (e.diagnostic() == err::XPTY0004)
          return false;
        throw;
       }
    }
    else
    {
      TypeManager* tm = sctx->get_typemanager();
      return CompareIterator::valueEqual(loc, item1, item2, tm, timezone, collator, raiseError);
    }

    break;
  }
  case store::Item::NODE:
  {
    return deepEqualNodes(loc, sctx, item1, item2, collator, timezone, raiseError);
  }
  case store::Item::OBJECT:
  {
    return deepEqualObjects(loc, sctx, item1, item2, collator, timezone, raiseError);
  }
  case store::Item::ARRAY:
  {
    return deepEqualArrays(loc, sctx, item1, item2, collator, timezone, raiseError);
  }
  default:
  {
    ZORBA_ASSERT(false);  // should never reach here
  }
  }

  return false;
}