<commit_before>#include <cassert>
#include <fstream>
#include <iostream>

#include <zorba/store_manager.h>
#include <zorba/zorba.h>
#include <zorba/xquery.h>
#include <zorba/xquery_exception.h>
#include <zorba/serializer.h>
#include <zorba/item_sequence.h>
#include <zorba/singleton_item_sequence.h>

using namespace zorba;

bool
invoke1(zorba::Zorba* z)
{
  try
  {
    StaticContext_t lSctx = z->createStaticContext();
    ItemFactory* lFac = z->getItemFactory();
    Item lQName = lFac->createQName(
        "http://www.w3.org/2005/xpath-functions",
        "current-dateTime");
    std::vector<ItemSequence_t> lArgs;

    ItemSequence_t lRes = lSctx->invoke(lQName, lArgs);

    Zorba_SerializerOptions_t lOpt;
    Serializer_t lSer = Serializer::createSerializer(lOpt);;
    lSer->serialize(lRes, std::cout);
    std::cout << std::endl;
  }
  catch (zorba::XQueryException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return false;
  }
  catch (zorba::ZorbaException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return false;
  }
  return true;
}

bool
invoke2(zorba::Zorba* z)
{
  try
  {
    // test QName not found
    StaticContext_t lSctx = z->createStaticContext();
    ItemFactory* lFac = z->getItemFactory();
    Item lQName = lFac->createQName(
        "http://www.w3.org/2005/xpath-functions",
        "foo");
    std::vector<ItemSequence_t> lArgs;

    ItemSequence_t lRes = lSctx->invoke(lQName, lArgs);

  }
  catch (zorba::XQueryException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return true;
  }
  catch (zorba::ZorbaException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return false;
  }
  return false;
}

bool
invoke3(zorba::Zorba* z)
{
  try
  {
    // test function with wrong given number of params
    StaticContext_t lSctx = z->createStaticContext();
    ItemFactory* lFac = z->getItemFactory();
    Item lQName = lFac->createQName(
        "http://www.w3.org/2005/xpath-functions",
        "round"); // round needs at least one param
    std::vector<ItemSequence_t> lArgs;

    ItemSequence_t lRes = lSctx->invoke(lQName, lArgs);

  }
  catch (zorba::XQueryException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return true;
  }
  catch (zorba::ZorbaException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return false;
  }
  return false;
}

bool
invoke4(zorba::Zorba* z)
{
  try
  {
    // test function with one param
    StaticContext_t lSctx = z->createStaticContext();
    ItemFactory* lFac = z->getItemFactory();
    Item lQName = lFac->createQName(
        "http://www.w3.org/2005/xpath-functions",
        "round"); // round needs at least one param

    std::vector<ItemSequence_t> lArgs;
    ItemSequence_t lSeq1 = new SingletonItemSequence(
        lFac->createDecimal("12678967.543233"));
    lArgs.push_back(lSeq1);

    ItemSequence_t lRes = lSctx->invoke(lQName, lArgs);
    Zorba_SerializerOptions_t lOpt;
    Serializer_t lSer = Serializer::createSerializer(lOpt);;
    lSer->serialize(lRes, std::cout);
    std::cout << std::endl;

  }
  catch (zorba::XQueryException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return false;
  }
  catch (zorba::ZorbaException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return false;
  }
  return true;
}

bool
invoke5(zorba::Zorba* z)
{
  try
  {
    StaticContext_t lSctx = z->createStaticContext();
    Zorba_CompilerHints_t lHints;

    std::ostringstream lProlog;
    lProlog
      << "import module namespace r = 'http://www.zorba-xquery.com/modules/random';";
    lSctx->loadProlog(lProlog.str(), lHints);

    ItemFactory* lFac = z->getItemFactory();
    Item lQName = lFac->createQName(
        "http://www.zorba-xquery.com/modules/random",
        "r",
        "random"); // round needs at least one param

    std::vector<ItemSequence_t> lArgs;

    ItemSequence_t lRes = lSctx->invoke(lQName, lArgs);

    Zorba_SerializerOptions_t lOpt;
    Serializer_t lSer = Serializer::createSerializer(lOpt);;
    lSer->serialize(lRes, std::cout);<commit_msg>For C++ invoke, creating a QName without prefix is sufficient since Nicolae's latest changes to the XQuery invoke (i.e. using EQNames)<commit_after>#include <cassert>
#include <fstream>
#include <iostream>

#include <zorba/store_manager.h>
#include <zorba/zorba.h>
#include <zorba/xquery.h>
#include <zorba/xquery_exception.h>
#include <zorba/serializer.h>
#include <zorba/item_sequence.h>
#include <zorba/singleton_item_sequence.h>

using namespace zorba;

bool
invoke1(zorba::Zorba* z)
{
  try
  {
    StaticContext_t lSctx = z->createStaticContext();
    ItemFactory* lFac = z->getItemFactory();
    Item lQName = lFac->createQName(
        "http://www.w3.org/2005/xpath-functions",
        "current-dateTime");
    std::vector<ItemSequence_t> lArgs;

    ItemSequence_t lRes = lSctx->invoke(lQName, lArgs);

    Zorba_SerializerOptions_t lOpt;
    Serializer_t lSer = Serializer::createSerializer(lOpt);;
    lSer->serialize(lRes, std::cout);
    std::cout << std::endl;
  }
  catch (zorba::XQueryException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return false;
  }
  catch (zorba::ZorbaException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return false;
  }
  return true;
}

bool
invoke2(zorba::Zorba* z)
{
  try
  {
    // test QName not found
    StaticContext_t lSctx = z->createStaticContext();
    ItemFactory* lFac = z->getItemFactory();
    Item lQName = lFac->createQName(
        "http://www.w3.org/2005/xpath-functions",
        "foo");
    std::vector<ItemSequence_t> lArgs;

    ItemSequence_t lRes = lSctx->invoke(lQName, lArgs);

  }
  catch (zorba::XQueryException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return true;
  }
  catch (zorba::ZorbaException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return false;
  }
  return false;
}

bool
invoke3(zorba::Zorba* z)
{
  try
  {
    // test function with wrong given number of params
    StaticContext_t lSctx = z->createStaticContext();
    ItemFactory* lFac = z->getItemFactory();
    Item lQName = lFac->createQName(
        "http://www.w3.org/2005/xpath-functions",
        "round"); // round needs at least one param
    std::vector<ItemSequence_t> lArgs;

    ItemSequence_t lRes = lSctx->invoke(lQName, lArgs);

  }
  catch (zorba::XQueryException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return true;
  }
  catch (zorba::ZorbaException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return false;
  }
  return false;
}

bool
invoke4(zorba::Zorba* z)
{
  try
  {
    // test function with one param
    StaticContext_t lSctx = z->createStaticContext();
    ItemFactory* lFac = z->getItemFactory();
    Item lQName = lFac->createQName(
        "http://www.w3.org/2005/xpath-functions",
        "round"); // round needs at least one param

    std::vector<ItemSequence_t> lArgs;
    ItemSequence_t lSeq1 = new SingletonItemSequence(
        lFac->createDecimal("12678967.543233"));
    lArgs.push_back(lSeq1);

    ItemSequence_t lRes = lSctx->invoke(lQName, lArgs);
    Zorba_SerializerOptions_t lOpt;
    Serializer_t lSer = Serializer::createSerializer(lOpt);;
    lSer->serialize(lRes, std::cout);
    std::cout << std::endl;

  }
  catch (zorba::XQueryException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return false;
  }
  catch (zorba::ZorbaException &e)
  {
    std::cerr << "Error: " << e << std::endl;
    return false;
  }
  return true;
}

bool
invoke5(zorba::Zorba* z)
{
  try
  {
    StaticContext_t lSctx = z->createStaticContext();
    Zorba_CompilerHints_t lHints;

    std::ostringstream lProlog;
    lProlog
      << "import module namespace r = 'http://www.zorba-xquery.com/modules/random';";
    lSctx->loadProlog(lProlog.str(), lHints);

    ItemFactory* lFac = z->getItemFactory();
    Item lQName = lFac->createQName(
        "http://www.zorba-xquery.com/modules/random",
        "random"); 

    std::vector<ItemSequence_t> lArgs;

    ItemSequence_t lRes = lSctx->invoke(lQName, lArgs);

    Zorba_SerializerOptions_t lOpt;
    Serializer_t lSer = Serializer::createSerializer(lOpt);;
    lSer->serialize(lRes, std::cout);
{'fraction_non_alphanumeric': 0.15047060261581713, 'fraction_numerical': 0.01002322454467669, 'mean_word_length': 3.366061899679829, 'pattern_counts': {'":': 0, '<': 141, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5897479', 'n_tokens_mistral': 3111, 'n_tokens_neox': 3031, 'n_words': 586}