/***************************************************************************

    source::worx xtree
    Copyright © 2024-2025 c.holzheuer
    christoph.holzheuer@gmail.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/


#include <xqnode.h>
#include <xqitem.h>


//! hilfsfunktion: gibt diesen teilbaum rekursiv aus

void inspect( const XQNodePtr& node, int indent )
{
  qDebug() << std::string(indent * 2, ' ').c_str() << node.use_count() << ": " << node->to_string();
  if (node->has_children())
  {
    for (const auto& child : node->children())
    {
      inspect( child, indent + 1 );
    }
  }

}


//! operator<< für QString und std::ostream

// Overload the operator<< for MyClass and std::ostream
std::ostream& operator<<(std::ostream& os, const QString& obj)
{
  // Simply call the getter and insert the string into the stream
  os << obj.toStdString();
  return os; // Return the stream for chaining
}


//! 'QString' implementation von split

template<>
bool znode::zpayload<QString>::xstr_split_by(const QString& entry, const QString& sep, QString& key, QString& value )
{
  int index = entry.indexOf(sep);
  if(index  < 0)
    return false;
  key = entry.left(index);
  value = entry.mid( index+sep.length() );
  return true;
}


//! 'QString' implementation von substr

template<>
QString znode::zpayload<QString>::xstr_sub_str( const QString& entry, int pos ) const
{
  return entry.mid(pos);
}


//! 'QString' implementation vom test auf 'empty'

template<>
bool znode::zpayload<QString>::xstr_is_empty(const QString& entry ) const
{
  return entry.isEmpty();
}


//! 'QString' varianten der keystrings.

template<>
const QString znode::zpayload<QString>::cTagName  = "TagName";

template<>
const QString znode::zpayload<QString>::cType  = "Type";

template<>
const QString znode::zpayload<QString>::cName  = "Name";

template<>
const QString znode::zpayload<QString>::cValue = "Value";

template<>
const QString znode::zpayload<QString>::cFriendlyName = "FriendlyName";
