<commit_before>#include <exotica/Loaders/XMLLoader.h>
#include <tinyxml2/tinyxml2.h>
#include <exotica/Setup.h>

namespace exotica
{

    boost::shared_ptr<XMLLoader> XMLLoader::instance_ = nullptr;

    XMLLoader::XMLLoader()
    {

    }

    bool parseXML(tinyxml2::XMLHandle& tag, Initializer& parent, const std::string& prefix);

    void appendChildXML(Initializer& parent, std::string& name, bool isAttribute, tinyxml2::XMLHandle& tag, const std::string& prefix)
    {
        if(isAttribute)
        {
            // Attributes are always a regular property
            std::string value = tag.ToElement()->Attribute(name.c_str());
            parent.addProperty(Property(name,true,value));
        }
        else
        {
            int count = 0;
            for( tinyxml2::XMLHandle child = tag.FirstChild(); child.ToElement(); child = child.NextSibling() ) count++;
            if(count==0)
            {
                // No child tags = this is a regular property
                std::string value;
                if (!tag.ToElement()->GetText())
                {
                    throw_pretty("Can't get value! ("+name+")");
                }
                value = tag.ToElement()->GetText();
                parent.addProperty(Property(name,true,value));
            }
            else
            {
                // Child tags found = this is an initializer
                // All initializers are treated as a vector
                std::vector<Initializer> ret;
                tinyxml2::XMLHandle child_tag(tag.FirstChildElement());
                while(child_tag.ToElement())
                {
                    ret.push_back(Initializer("New"+name));
                    if(!parseXML(child_tag,ret[ret.size()-1],prefix+"- "))
                    {
                        ret.pop_back();
                    }
                    else
                    {
                        //HIGHLIGHT(prefix<<". Adding parsed vector element "<<name<<" to " << parent.getName());
                    }
                    child_tag = child_tag.NextSiblingElement();
                }
                parent.addProperty(Property(name,true,ret));<commit_msg>Enable zero length initializer vectors in XML<commit_after>#include <exotica/Loaders/XMLLoader.h>
#include <tinyxml2/tinyxml2.h>
#include <exotica/Setup.h>

namespace exotica
{

    boost::shared_ptr<XMLLoader> XMLLoader::instance_ = nullptr;

    XMLLoader::XMLLoader()
    {

    }

    bool parseXML(tinyxml2::XMLHandle& tag, Initializer& parent, const std::string& prefix);

    void appendChildXML(Initializer& parent, std::string& name, bool isAttribute, tinyxml2::XMLHandle& tag, const std::string& prefix)
    {
        if(isAttribute)
        {
            // Attributes are always a regular property
            std::string value = tag.ToElement()->Attribute(name.c_str());
            parent.addProperty(Property(name,true,value));
        }
        else
        {
            int count = 0;
            for( tinyxml2::XMLHandle child = tag.FirstChild(); child.ToElement(); child = child.NextSibling() ) count++;
            if(count==0)
            {

                if (!tag.ToElement()->GetText())
                {
                    // No child tags = this is an empty vector of properties
                    return;
                }
                std::string value = tag.ToElement()->GetText();
                parent.addProperty(Property(name,true,value));
            }
            else
            {
                // Child tags found = this is an initializer
                // All initializers are treated as a vector
                std::vector<Initializer> ret;
                tinyxml2::XMLHandle child_tag(tag.FirstChildElement());
                while(child_tag.ToElement())
                {
                    ret.push_back(Initializer("New"+name));
                    if(!parseXML(child_tag,ret[ret.size()-1],prefix+"- "))
                    {
                        ret.pop_back();
                    }
                    else
                    {
                        //HIGHLIGHT(prefix<<". Adding parsed vector element "<<name<<" to " << parent.getName());
                    }
                    child_tag = child_tag.NextSiblingElement();
                }
                parent.addProperty(Property(name,true,ret));
{'fraction_non_alphanumeric': 0.11730945821854913, 'fraction_numerical': 0.004132231404958678, 'mean_word_length': 1.5842230130486359, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '3202031', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1122, 'n_words': 223}