diff --git a/core/logic/smn_adt_trie.cpp b/core/logic/smn_adt_trie.cpp index 1b0e7b41..8d1f7d6f 100644 --- a/core/logic/smn_adt_trie.cpp +++ b/core/logic/smn_adt_trie.cpp @@ -350,6 +350,27 @@ static cell_t SetTrieString(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t ContainsKeyInTrie(IPluginContext *pContext, const cell_t *params) +{ + CellTrie *pTrie; + HandleError err; + HandleSecurity sec = HandleSecurity(pContext->GetIdentity(), g_pCoreIdent); + + Handle_t hndl = params[1]; + + if ((err = handlesys->ReadHandle(hndl, htCellTrie, &sec, (void **)&pTrie)) != HandleError_None) + { + return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); + } + + char *key; + pContext->LocalToString(params[2], &key); + + StringHashMap::Result r = pTrie->map.find(key); + + return r.found() ? 1 : 0; +} + static cell_t RemoveFromTrie(IPluginContext *pContext, const cell_t *params) { CellTrie *pTrie; @@ -710,6 +731,7 @@ REGISTER_NATIVES(trieNatives) {"StringMap.GetArray", GetTrieArray}, {"StringMap.GetString", GetTrieString}, {"StringMap.GetValue", GetTrieValue}, + {"StringMap.ContainsKey", ContainsKeyInTrie}, {"StringMap.Remove", RemoveFromTrie}, {"StringMap.SetArray", SetTrieArray}, {"StringMap.SetString", SetTrieString}, diff --git a/plugins/include/adt_trie.inc b/plugins/include/adt_trie.inc index 9de455d8..c934990a 100644 --- a/plugins/include/adt_trie.inc +++ b/plugins/include/adt_trie.inc @@ -114,6 +114,12 @@ methodmap StringMap < Handle // as a value or array (not a string). public native bool GetString(const char[] key, char[] value, int max_size, int &size=0); + // Checks whether a key is present in a Map. + // + // @param key Key string. + // @return True if the key has been found, else false. + public native bool ContainsKey(const char[] key); + // Removes a key entry from a Map. // // @param key Key string.