summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editeng/source/lookuptree/Trie.cxx61
-rw-r--r--include/editeng/Trie.hxx23
2 files changed, 42 insertions, 42 deletions
diff --git a/editeng/source/lookuptree/Trie.cxx b/editeng/source/lookuptree/Trie.cxx
index 1b8eeb7c84a5..4fbc19430bdb 100644
--- a/editeng/source/lookuptree/Trie.cxx
+++ b/editeng/source/lookuptree/Trie.cxx
@@ -16,6 +16,27 @@ using namespace std;
/* TrieNode */
+struct TrieNode
+{
+ static const int LATIN_ARRAY_SIZE = 26;
+
+ sal_Unicode mCharacter;
+ bool mMarker;
+ std::vector<TrieNode*> mChildren;
+ TrieNode* mLatinArray[LATIN_ARRAY_SIZE];
+
+
+ TrieNode(sal_Unicode aCharacter = '\0');
+ virtual ~TrieNode();
+
+ void markWord();
+ TrieNode* findChild(sal_Unicode aCharacter);
+ TrieNode* traversePath(OUString sPath);
+ void addNewChild(TrieNode* pChild);
+ void collectSuggestions(OUString sPath, std::vector<OUString>& rSuggestionList);
+ void collectSuggestionsForCurrentNode(TrieNode* pCurrent, OUString sPath, vector<OUString>& rSuggestionList);
+};
+
TrieNode::TrieNode(sal_Unicode aCharacter) :
mCharacter(aCharacter),
mMarker(false)
@@ -85,13 +106,7 @@ void TrieNode::collectSuggestions(OUString sPath, vector<OUString>& rSuggestionL
{
TrieNode* pCurrent = mLatinArray[i];
if (pCurrent != NULL)
- {
- OUString aStringPath = sPath + OUString(pCurrent->mCharacter);
- if(pCurrent->mMarker)
- rSuggestionList.push_back(aStringPath);
- // recursivly traverse tree
- pCurrent->collectSuggestions(aStringPath, rSuggestionList);
- }
+ collectSuggestionsForCurrentNode(pCurrent, sPath, rSuggestionList);
}
// traverse nodes for other characters
@@ -100,16 +115,21 @@ void TrieNode::collectSuggestions(OUString sPath, vector<OUString>& rSuggestionL
{
TrieNode* pCurrent = *iNode;
if (pCurrent != NULL)
- {
- OUString aStringPath = sPath + OUString(pCurrent->mCharacter);
- if(pCurrent->mMarker)
- rSuggestionList.push_back(aStringPath);
- // recursivly traverse tree
- pCurrent->collectSuggestions(aStringPath, rSuggestionList);
- }
+ collectSuggestionsForCurrentNode(pCurrent, sPath, rSuggestionList);
}
}
+void TrieNode::collectSuggestionsForCurrentNode(TrieNode* pCurrent, OUString sPath, vector<OUString>& rSuggestionList)
+{
+ OUString aStringPath = sPath + OUString(pCurrent->mCharacter);
+ if(pCurrent->mMarker)
+ {
+ rSuggestionList.push_back(aStringPath);
+ }
+ // recursivly descend tree
+ pCurrent->collectSuggestions(aStringPath, rSuggestionList);
+}
+
TrieNode* TrieNode::traversePath(OUString sPath)
{
TrieNode* pCurrent = this;
@@ -127,15 +147,12 @@ TrieNode* TrieNode::traversePath(OUString sPath)
/* TRIE */
-Trie::Trie()
-{
- mRoot = new TrieNode();
-}
+Trie::Trie() :
+ mRoot(new TrieNode())
+{}
Trie::~Trie()
-{
- delete mRoot;
-}
+{}
void Trie::insert(OUString sInputString) const
{
@@ -147,7 +164,7 @@ void Trie::insert(OUString sInputString) const
// traverse the input string and modify the tree with new nodes / characters
- TrieNode* pCurrent = mRoot;
+ TrieNode* pCurrent = mRoot.get();
sal_Unicode aCurrentChar;
for ( sal_Int32 i = 0; i < sInputString.getLength(); i++ )
diff --git a/include/editeng/Trie.hxx b/include/editeng/Trie.hxx
index 2ac76aee380c..3ade079b3a91 100644
--- a/include/editeng/Trie.hxx
+++ b/include/editeng/Trie.hxx
@@ -14,34 +14,17 @@
#include <rtl/ustring.hxx>
#include <vector>
#include <editeng/editengdllapi.h>
+#include <boost/scoped_ptr.hpp>
namespace editeng
{
-struct TrieNode
-{
- static const int LATIN_ARRAY_SIZE = 26;
-
- sal_Unicode mCharacter;
- bool mMarker;
- std::vector<TrieNode*> mChildren;
- TrieNode* mLatinArray[LATIN_ARRAY_SIZE];
-
-
- TrieNode(sal_Unicode aCharacter = '\0');
- virtual ~TrieNode();
-
- void markWord();
- TrieNode* findChild(sal_Unicode aCharacter);
- TrieNode* traversePath(OUString sPath);
- void addNewChild(TrieNode* pChild);
- void collectSuggestions(OUString sPath, std::vector<OUString>& rSuggestionList);
-};
+struct TrieNode;
class EDITENG_DLLPUBLIC Trie
{
private:
- TrieNode* mRoot;
+ boost::scoped_ptr<TrieNode> mRoot;
public:
Trie();