Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion yaml-path/yaml-path-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ namespace YAML
template <typename TBits, typename T>
constexpr uint64_t BitsOf(std::initializer_list<T> values)
{
__int64 bits = 0;
int64_t bits = 0;
for (auto v : values)
bits |= TBits(1) << TBits(v);
return bits;
Expand Down
34 changes: 18 additions & 16 deletions yaml-path/yaml-path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ SOFTWARE.
#include "yaml-path-internals.h"
#include <yaml-cpp/yaml.h>
#include <assert.h>
#include <algorithm>
#include <cstring>
#include <strings.h>

/// namspace shared by yaml-cpp and yaml-path
namespace YAML
Expand Down Expand Up @@ -82,6 +85,15 @@ namespace YAML

namespace YamlPathDetail
{
/// \internal result = target; target = newValue
template <typename T1, typename T2>
T1 Exchange(T1 & target, T2 newValue)
{
T1 result = std::move(target);
target = std::move(newValue);
return std::move(result);
}

/// \internal uses the same mapping as \ref MapValue to create diagnostic for a bit mask (e.g. created by \ref BitsOf)
template <typename T2, typename TBit, typename TMask>
std::string MapBitMask(TMask value, std::initializer_list<std::pair<TBit, T2>> values, T2 sep = ", ")
Expand Down Expand Up @@ -166,15 +178,6 @@ namespace YAML
return undefinedNode;
}

/// \internal result = target; target = newValue
template <typename T1, typename T2>
T1 Exchange(T1 & target, T2 newValue)
{
T1 result = std::move(target);
target = std::move(newValue);
return std::move(result);
}


/** \internal splits path at offset,
returning everything left of [offset], assigning everything right of it to \c path.
Expand Down Expand Up @@ -681,7 +684,7 @@ namespace YAML

// Unicode: some assumptions here don't hold. It's strcoll, stricoll, and I'm not sure how to implement no-case starry matches
size_t cmpLen = std::min(tok.token.length(), snode.length());
int result = tok.noCase ? _strnicmp(&tok.token[0], snode.c_str(), cmpLen) : strncmp(&tok.token[0], snode.c_str(), cmpLen);
int result = tok.noCase ? strncasecmp(&tok.token[0], snode.c_str(), cmpLen) : strncmp(&tok.token[0], snode.c_str(), cmpLen);

return result == 0; // under assumption of above length-based shortcuts
}
Expand Down Expand Up @@ -923,30 +926,29 @@ namespace YAML

namespace YamlPathDetail
{
Node EnsureNodeApplyKeyToMapOrNothing(Node & start, std::string key)
Node EnsureNodeApplyKeyToMapOrNothing(const Node & start, std::string key)
{
Node n = start[key];
if (n)
return n;
start[key] = Node(NodeType::Null);
return start[key];
return Node(NodeType::Null);
}

void EnsureNodeApplyKey(std::vector<Node> & result, Node & start, std::string key, bool recurse)
void EnsureNodeApplyKey(std::vector<Node> & result, const Node & start, std::string key, bool recurse)
{
if (!start || start.IsNull() || start.IsMap())
result.push_back(EnsureNodeApplyKeyToMapOrNothing(start, key));
else if (start.IsSequence() && recurse)
{
for (auto & el : start)
for (auto& el : start)
if (el.IsNull() || el.IsMap())
EnsureNodeApplyKey(result, el, key, false);
}
}

void EnsureNodeApplyKey(std::vector<Node> & result, std::vector<Node> & start, std::string key)
{
for (auto & el : start)
for (auto& el : start)
if (el.IsNull() || el.IsMap())
EnsureNodeApplyKey(result, el, key, true);
}
Expand Down
2 changes: 1 addition & 1 deletion yaml-path/yaml-path.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace YAML
std::size_t ErrorOffset() const { return m_offsTokenScan; } ///< index into the full path where the error occurred
std::optional<size_t> BoundArg() const { return m_fromBoundArg; } ///< if token was taken from a bound argument, this is its index

char const * what() const override { return What().c_str(); } ///< overrides \c std::exception::what, returning the detailed error message from \ref What
char const * what() const noexcept override { return What().c_str(); } ///< overrides \c std::exception::what, returning the detailed error message from \ref What
std::string const & What(bool detailed = true) const;

static std::string GetErrorMessage(EPathError error);
Expand Down