diff options
Diffstat (limited to 'src/uscxml/util')
-rw-r--r-- | src/uscxml/util/Trie.cpp | 14 | ||||
-rw-r--r-- | src/uscxml/util/Trie.h | 6 |
2 files changed, 15 insertions, 5 deletions
diff --git a/src/uscxml/util/Trie.cpp b/src/uscxml/util/Trie.cpp index ebcc3ef..8934c73 100644 --- a/src/uscxml/util/Trie.cpp +++ b/src/uscxml/util/Trie.cpp @@ -19,17 +19,18 @@ #include "Trie.h" #include <iostream> +#include <boost/algorithm/string.hpp> namespace uscxml { Trie::Trie() { root = new TrieNode(); - lastIdentifier = 0; + lastIndex = 0; } Trie::Trie(const std::string& seperator) : seperator(seperator) { root = new TrieNode(); - lastIdentifier = 0; + lastIndex = 0; } Trie::~Trie() { @@ -67,6 +68,12 @@ size_t Trie::getNextToken(const std::string& word, size_t offset, std::string& t return offset + 1; } +std::string Trie::escapeWord(const std::string& word) { + std::string identifier = word; + boost::replace_all(identifier, ".", "_"); + return identifier; +} + void Trie::addWord(const std::string& word) { TrieNode* currNode = root; @@ -86,8 +93,9 @@ void Trie::addWord(const std::string& word) { break; } if (!currNode->hasWord) { - currNode->identifier = lastIdentifier++; + currNode->index = lastIndex++; currNode->value = word; + currNode->identifier = escapeWord(word); currNode->hasWord = true; } } diff --git a/src/uscxml/util/Trie.h b/src/uscxml/util/Trie.h index 1f8b201..73d75e7 100644 --- a/src/uscxml/util/Trie.h +++ b/src/uscxml/util/Trie.h @@ -32,7 +32,8 @@ struct USCXML_API TrieNode { virtual ~TrieNode(); bool hasWord; - int identifier; + int index; + std::string identifier; std::string value; std::map<std::string, TrieNode*> childs; void dump(int indent = 0); @@ -45,6 +46,7 @@ struct USCXML_API Trie { void addWord(const std::string& word); size_t getNextToken(const std::string& word, size_t offset, std::string& token); + std::string escapeWord(const std::string& word); TrieNode* getNodeWithPrefix(const std::string& prefix); std::list<TrieNode*> getWordsWithPrefix(const std::string& prefix); @@ -53,7 +55,7 @@ struct USCXML_API Trie { TrieNode* root; std::string seperator; - int lastIdentifier; + int lastIndex; }; } |