<commit_before>//-- Copyright 2015 Intrig
//-- See https://github.com/intrig/xenon for license.
#include <iostream>
#include <vector>
#include <ict/xenon.h>

using std::cout;
using std::cerr;
using ict::message;

struct nv_pairs {
    nv_pairs(const std::string & name, int64_t value) : name(name), value(value) {}
    std::string name;
    int64_t value;
};

int main(int, char**) {
    try {
        auto fields = std::vector<nv_pairs>();

        cout << "loading\n";
        ict::spec_server doc("icd.xddl");
        cout << "assigning\n";
        auto msg = ict::parse(doc, "0101046B102C000114E03003603800203801C03801E03801F030037030002030"
              "00903000603000E0300120300130380000300110300030380080300200300210"
              "3001903001603000F03000703000403000C03000503000D1A03C9E16C18070DE"
              "2C7CFF3C7CC1001E00E01C000389");

        cout << "putting fields and their values into a vector: " << ict::to_text(msg);
        for (auto c = ict::linear_begin(msg.root()); c != msg.end(); ++c) {
            if (c->consumes()) fields.emplace_back(c->name(), c->value());
        }
        cout << "done, processed " << fields.size() << " fields\n\n";

        fields.clear();
        cout << "again, using recurse algorithm\n";
        ict::recurse(msg.root(), [&](message::cursor c, message::cursor) {
            if (c->consumes()) fields.emplace_back(c->name(), c->value());
        });
        cout << "done, processed " << fields.size() << " fields\n\n";

        cout << "now find a field: DATA/MSG_TYPE\n";
        auto c = ict::find(msg.root(), "DATA/MSG_TYPE");

        if (c != msg.end()) cout << "found it! " << ict::description(c) << "\n\n";

        cout << "now find using a non-anchored path: //RLP_CAP_INFO_BLOCK/MAX_MS_NAK_ROUNDS_FWD\n";
        c = ict::find(msg.root(), "//RLP_CAP_INFO_BLOCK/MAX_MS_NAK_ROUNDS_FWD");
        if (c != msg.end()) cout << "found it! " << c->value() << "\n\n";
        

    } catch (ict::exception & e) { cerr << e.what() << '\n';
        return 1;
    }
}<commit_msg>updated examples<commit_after>//-- Copyright 2015 Intrig
//-- See https://github.com/intrig/xenon for license.
#include <iostream>
#include <vector>
#include <ict/xenon.h>

using std::cout;
using std::cerr;
using ict::message;

struct nv_pairs {
    nv_pairs(const std::string & name, int64_t value) : name(name), value(value) {}
    std::string name;
    int64_t value;
};

int main(int, char**) {
    try {
        auto fields = std::vector<nv_pairs>();

        cout << "loading\n";
        ict::spec_server doc("icd.xddl");
        cout << "assigning\n";
        auto msg = ict::parse(doc, "0101046B102C000114E03003603800203801C03801E03801F030037030002030"
              "00903000603000E0300120300130380000300110300030380080300200300210"
              "3001903001603000F03000703000403000C03000503000D1A03C9E16C18070DE"
              "2C7CFF3C7CC1001E00E01C000389");

        cout << "iterating over top level nodes only\n";
        for (auto c = msg.begin(); c != msg.end(); ++c) {
            // and now we can process each node
            cout << c->name() << '\n';
        }

        // using a linear cursor, we can iterate through the entire message in a depth first way
        cout << "putting fields and their values into a vector: " << ict::to_text(msg);
        for (auto c = ict::linear_begin(msg.root()); c != msg.end(); ++c) {
            if (c->consumes()) fields.emplace_back(c->name(), c->value());
        }
        cout << "done, processed " << fields.size() << " fields\n\n";
        fields.clear();

        // We an also do the same thing using the ict::recurse() algorithm that takes a root node and
        // a lambda expression.  This is currently more efficient and recommonded over the linear_cursor 
        // method above.
        cout << "again, using recurse algorithm\n";
        ict::recurse(msg.root(), [&](message::cursor c, message::cursor) {
            if (c->consumes()) fields.emplace_back(c->name(), c->value());
        });
        cout << "done, processed " << fields.size() << " fields\n\n";

        cout << "now find a field: DATA/MSG_TYPE\n";
        auto c = ict::find(msg.root(), "DATA/MSG_TYPE");

        if (c != msg.end()) cout << "found it! " << ict::description(c) << "\n\n";

        cout << "now find using a non-anchored path: //RLP_CAP_INFO_BLOCK/MAX_MS_NAK_ROUNDS_FWD\n";
        c = ict::find(msg.root(), "//RLP_CAP_INFO_BLOCK/MAX_MS_NAK_ROUNDS_FWD");
        if (c != msg.end()) cout << "found it! " << c->value() << "\n\n";
        

    } catch (ict::exception & e) { cerr << e.what() << '\n';
        return 1;
    }
}
{'fraction_non_alphanumeric': 0.16839378238341968, 'fraction_numerical': 0.08765112262521589, 'mean_word_length': 2.7064, 'pattern_counts': {'":': 0, '<': 101, '<?xml version=': 0, '>': 26, 'https://': 2, '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': '7189935', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1595, 'n_words': 359}