My favorites | Sign in
Project Home Downloads Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
Copyright (c) 2008 Romain Gaucher <r@rgaucher.info>
-- http://rgaucher.info

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

--

The STree's are an implementation of a fast replacements algorithm
based on a dictionnary.

Using the stree is simple:

map<string, string> replacements;
// fill the map with the pair (to_find, to_replace_with)
// and of course, the key is unique (ie. no multi-replacements)

string my_text;
stree_c my_tree(replacements);
string replaced_text = my_tree.replace(my_text);

*/
#ifndef __STREE_H
#define __STREE_H

#include <map>
#include <string>
#include <iostream>
#include "tree.hh"

class stree {
public:
typedef tree<char> c_tree;

protected:
c_tree t;
c_tree::iterator root;
std::map<std::string, std::string> m;

protected:
stree() {}
stree(const stree&) {}
stree& operator=(const stree&) {return *this;}

void init();
void insert(const std::string&);
c_tree::sibling_iterator child_exists(const c_tree::iterator& root, const char c);

public:
stree(const std::map<std::string, std::string>& _m)
: m(_m)
{
init();
}

std::string replace(const std::string& in);
void print(const c_tree::iterator& root, std::string padding = "");

~stree() {}
};



// to use later the template stree<char>
typedef stree stree_c;

#endif

Change log

r16 by romain.gaucher on Jul 31, 2008   Diff
added a simple converter (based on the
stree: stree/stree.h)
added the output file... will work on the
html output later... (next step)
Go to: 
Sign in to write a code review

Older revisions

r14 by romain.gaucher on Jul 28, 2008   Diff
Added the STree structure to do
massive replacement
All revisions of this file

File info

Size: 1879 bytes, 78 lines
Powered by Google Project Hosting