<commit_before>/**
 * Copyright FLWOR Foundation
 *
 * Author: <NAME> (<EMAIL>)
 */

#include <string>
#include <fstream>
#include <vector>
#include <sstream>

#include "runtime/sequences/SequencesImpl.h"
#include "runtime/booleans/BooleanImpl.h"
#include "runtime/numerics/NumericsImpl.h"
#include "runtime/api/runtimecb.h"
#include "runtime/core/arithmetic_impl.h"
#include "runtime/util/iterator_impl.h"

#include "system/globalenv.h"

#include "types/casting.h"
#include "types/typeops.h"
#include "store/api/store.h"
#include "store/api/iterator.h"
#include "store/api/item_factory.h"

#include "context/static_context.h"
#include "context/collation_cache.h"

#include "errors/error_manager.h"

#include "zorbatypes/zorbatypesError.h"
#include "errors/error_messages.h"

#include "util/web/web.h"
#include "store/util/handle_hashset_node.h"

#include "runtime/booleans/compare_types.h"
#include "runtime/util/handle_hashset_item_value.h"

using namespace std;
namespace zorba {
  

/*______________________________________________________________________
|  
| 15.1 General Functions and Operators on Sequences
|_______________________________________________________________________*/

static XQPCollator*
getCollator(RuntimeCB* aRuntimeCB, const QueryLoc& loc, PlanState& planState, const PlanIterator* iter)
{
  store::Item_t lCollationItem = PlanIterator::consumeNext(iter, planState);

  if (lCollationItem == NULL)
      ZORBA_ERROR_LOC_DESC(ZorbaError::XPTY0004, loc, "An empty-sequence is not allowed as collation parameter");

  if (PlanIterator::consumeNext(iter, planState) != NULL)
      ZORBA_ERROR_LOC_DESC(ZorbaError::XPTY0004, loc, "A sequence of more then one item is not allowed as collation parameter");
    
  xqtref_t lCollationItemType = planState.theCompilerCB->m_sctx->get_typemanager()->item_type (lCollationItem);

  // TODO resolve uri (base-uri)

  return planState.theRuntimeCB->theCollationCache->getCollator(lCollationItem->getStringValue());
}


//15.1.2 op:concatenate 
//---------------------
void
FnConcatIteratorState::init(PlanState& planState) 
{
  PlanIteratorState::init(planState);
  theCurIter = 0;
}

void
FnConcatIteratorState::reset(PlanState& planState) 
{
  PlanIteratorState::reset(planState);
  theCurIter = 0;
}


bool
FnConcatIterator::isUpdateIterator() const
{
  return theChildren[0]->isUpdateIterator();
}


store::Item_t
FnConcatIterator::nextImpl(PlanState& planState) const 
{
  store::Item_t item;
  
  FnConcatIteratorState* state;
  DEFAULT_STACK_INIT(FnConcatIteratorState, state, planState);
  
  for (; state->theCurIter < theChildren.size(); ++state->theCurIter) 
  {
    item = consumeNext(theChildren[state->theCurIter].getp(), planState);
    while (item != NULL) 
    {
      STACK_PUSH (item, state);
      item = consumeNext(theChildren[state->theCurIter].getp(), planState);
    }
  }
  <commit_msg>handling of updating flwor expressions<commit_after>/**
 * Copyright FLWOR Foundation
 *
 * Author: <NAME> (<EMAIL>)
 */

#include <string>
#include <fstream>
#include <vector>
#include <sstream>

#include "runtime/sequences/SequencesImpl.h"
#include "runtime/booleans/BooleanImpl.h"
#include "runtime/numerics/NumericsImpl.h"
#include "runtime/api/runtimecb.h"
#include "runtime/core/arithmetic_impl.h"
#include "runtime/util/iterator_impl.h"

#include "system/globalenv.h"

#include "types/casting.h"
#include "types/typeops.h"
#include "store/api/store.h"
#include "store/api/iterator.h"
#include "store/api/item_factory.h"

#include "context/static_context.h"
#include "context/collation_cache.h"

#include "errors/error_manager.h"

#include "zorbatypes/zorbatypesError.h"
#include "errors/error_messages.h"

#include "util/web/web.h"
#include "store/util/handle_hashset_node.h"

#include "runtime/booleans/compare_types.h"
#include "runtime/util/handle_hashset_item_value.h"

using namespace std;
namespace zorba {
  

/*______________________________________________________________________
|  
| 15.1 General Functions and Operators on Sequences
|_______________________________________________________________________*/

static XQPCollator*
getCollator(RuntimeCB* aRuntimeCB, const QueryLoc& loc, PlanState& planState, const PlanIterator* iter)
{
  store::Item_t lCollationItem = PlanIterator::consumeNext(iter, planState);

  if (lCollationItem == NULL)
      ZORBA_ERROR_LOC_DESC(ZorbaError::XPTY0004, loc, "An empty-sequence is not allowed as collation parameter");

  if (PlanIterator::consumeNext(iter, planState) != NULL)
      ZORBA_ERROR_LOC_DESC(ZorbaError::XPTY0004, loc, "A sequence of more then one item is not allowed as collation parameter");
    
  xqtref_t lCollationItemType = planState.theCompilerCB->m_sctx->get_typemanager()->item_type (lCollationItem);

  // TODO resolve uri (base-uri)

  return planState.theRuntimeCB->theCollationCache->getCollator(lCollationItem->getStringValue());
}


//15.1.2 op:concatenate 
//---------------------
void
FnConcatIteratorState::init(PlanState& planState) 
{
  PlanIteratorState::init(planState);
  theCurIter = 0;
}

void
FnConcatIteratorState::reset(PlanState& planState) 
{
  PlanIteratorState::reset(planState);
  theCurIter = 0;
}


bool
FnConcatIterator::isUpdateIterator() const
{
  return (!theChildren.empty() && theChildren[0]->isUpdateIterator());
}


store::Item_t
FnConcatIterator::nextImpl(PlanState& planState) const 
{
  store::Item_t item;
  
  FnConcatIteratorState* state;
  DEFAULT_STACK_INIT(FnConcatIteratorState, state, planState);
  
  for (; state->theCurIter < theChildren.size(); ++state->theCurIter) 
  {
    item = consumeNext(theChildren[state->theCurIter].getp(), planState);
    while (item != NULL) 
    {
      STACK_PUSH (item, state);
      item = consumeNext(theChildren[state->theCurIter].getp(), planState);
    }
  }
  
{'fraction_non_alphanumeric': 0.13165603997932104, 'fraction_numerical': 0.006203687747716698, 'mean_word_length': 5.536036036036036, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7645940', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1898, 'n_words': 351}