Sha256: 82e02fc533c98a4af992eb75f45214db2df0317f83f3cfabbd820d37f9b70b1d

Contents?: true

Size: 1.61 KB

Versions: 16

Compression:

Stored size: 1.61 KB

Contents

#include <internal/nodes/config_node_path.hpp>
#include <hocon/config_exception.hpp>
#include <leatherman/locale/locale.hpp>

// Mark string for translation (alias for leatherman::locale::format)
using leatherman::locale::_;

using namespace std;

namespace hocon {

    config_node_path::config_node_path(path node_path, token_list tokens) :
        _path(move(node_path)), _tokens(move(tokens)) { }

    token_list config_node_path::get_tokens() const {
        return _tokens;
    }

    path config_node_path::get_path() const {
        return _path;
    }

    config_node_path config_node_path::sub_path(int to_remove) {
        int period_count = 0;
        token_list tokens_copy = _tokens;
        for (auto it = tokens_copy.begin(); it != tokens_copy.end(); it++) {
            if ((*it)->get_token_type() == token_type::UNQUOTED_TEXT && (*it)->token_text() == ".") {
                period_count++;
            }

            if (period_count == to_remove) {
                return config_node_path(_path.sub_path(to_remove), token_list { it + 1, tokens_copy.end() });
            }
        }
        throw config_exception(_("Tried to remove too many elements from a path node."));
    }

    config_node_path config_node_path::first() {
        token_list tokens_copy = _tokens;
        for (auto it = tokens_copy.begin(); it != tokens_copy.end(); it++) {
            if ((*it)->get_token_type() == token_type::UNQUOTED_TEXT && (*it)->token_text() == ".") {
                return config_node_path(_path.sub_path(0, 1), token_list { tokens_copy.begin(), it });
            }
        }
        return *this;
    }
}  // namespace hocon

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
facter-3.12.2.cfacter.20181217 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.12.1.cfacter.20181031 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.11.6.cfacter.20181031 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.12.1.cfacter.20181023 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.11.5.cfacter.20181022 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.12.0.cfacter.20181004 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.12.0.cfacter.20181001 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.12.0.cfacter.20180918 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.11.4.cfacter.20180821 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.11.3.cfacter.20180716 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.11.2.cfacter.20180612 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.9.6.cfacter.20180612 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.11.2.cfacter.20180606 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.9.6.cfacter.20180606 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
facter-3.11.0.cfacter.20180319 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc
cfacter-3.11.0.rc.20180314 ext/facter/cpp-hocon/lib/src/nodes/config_node_path.cc