From 5dbe8773181fd1effbfce27a3e9920d4e5099b72 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 28 May 2016 03:21:04 +0200 Subject: [PATCH] Library: add option to bypass the sanitising in EntryID While in general it is fine to clean-up any entity IDs to be US-ASCII alphanumerics (plus some allowed interpunction), the GenNodes and also keys in object-bindings for diff are considerd internal interfaces, assuming that any passed ID symbol is already sanitised and checked. So the sanitise operation can be skipped. This changeset adds the same option directly to lib::EntryID, allowing to create an EntryID that matches a similar GenNode's (hash) ID. --- src/lib/idi/entry-id.hpp | 13 +++++++++++++ tests/core/proc/asset/entry-id-test.cpp | 11 ++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/lib/idi/entry-id.hpp b/src/lib/idi/entry-id.hpp index 3c237589a..54b5debf4 100644 --- a/src/lib/idi/entry-id.hpp +++ b/src/lib/idi/entry-id.hpp @@ -229,6 +229,19 @@ namespace idi { EntryID (string const& symbolID) : BareEntryID (util::sanitise(symbolID), getTypeHash()) { } + explicit + EntryID (const char* symbolID) + : BareEntryID (util::sanitise(symbolID), getTypeHash()) + { } + + /** case-2b: rely on an internal, already sanitised symbol. + * The symbol string will be passed through as-is, while + * the type information from TY will be hashed in. + */ + explicit + EntryID (Symbol const& internalSymbol) + : BareEntryID (string(internalSymbol), getTypeHash()) + { } /** @return true if the upcast would yield exactly the same diff --git a/tests/core/proc/asset/entry-id-test.cpp b/tests/core/proc/asset/entry-id-test.cpp index 4f6180292..4f58cbb23 100644 --- a/tests/core/proc/asset/entry-id-test.cpp +++ b/tests/core/proc/asset/entry-id-test.cpp @@ -137,10 +137,19 @@ namespace test{ using proc::asset::idi::getAssetIdent; ForkID tID(" test ⚡ ☠ ☭ ⚡ track "); - CHECK (getAssetIdent(tID) == Asset::Ident("test_track", Category(STRUCT,"forks"), "lumi", 0)); + + // Symbol-ID will be "sanitised" + CHECK ("test_track" == tID.getSym()); + CHECK (tID == ForkID("☢ test ☢ track ☢")); + CHECK (tID == ForkID(string{"☢ test ☢ track ☢"})); + + // but: there is a pass-through for internal symbols + CHECK (tID != ForkID(Symbol{"☢ test ☢ track ☢"})); CHECK (tID.getHash() == ForkID("☢ test ☢ track ☢").getHash()); + CHECK (getAssetIdent(tID) == Asset::Ident("test_track", Category(STRUCT,"forks"), "lumi", 0)); + CHECK (tID.getSym() == getAssetIdent(tID).name); CHECK (getAssetIdent(ForkID()).category == Category (STRUCT,"forks")); CHECK (getAssetIdent(ClipID()).category == Category (STRUCT,"clips"));