TIVI-153: Add as dependency for iputils
[profile/ivi/opensp.git] / include / SubstTable.h
1 // Copyright (c) 1994 James Clark, 2000 Matthias Clasen
2 // See the file COPYING for copying permission.
3
4 #ifndef SubstTable_INCLUDED
5 #define SubstTable_INCLUDED
6
7 #include "types.h"
8 #include "StringC.h"
9 #include "Vector.h"
10
11 #ifdef SP_NAMESPACE
12 namespace SP_NAMESPACE {
13 #endif
14
15 class SP_API SubstTable {
16 public:
17   SubstTable();
18   void addSubst(Char from, Char to);
19   void subst(Char &) const;
20   void subst(StringC &) const;
21   Char operator[](Char from) const;
22   void sort() const;
23   Char at(Char from) const;
24   StringC inverse(Char to) const;
25   void inverseTable(SubstTable &) const;
26   struct Pair {
27     Pair() {}
28     Pair(Char f, Char t) : from(f), to(t) {}
29     Char from;
30     Char to;
31   };
32 private:
33   Char lo_[256];
34   mutable Vector<Pair> map_; 
35   mutable bool isSorted_;
36 };
37
38 inline
39 void SubstTable::subst(StringC &str) const
40 {
41   for (size_t i = 0; i < str.size(); i++)
42     subst(str[i]);
43 }
44
45 inline
46 Char SubstTable::operator[](Char t) const
47 {
48   if (t < 256)
49     return lo_[t];
50   else 
51     return at(t);
52 }
53
54 inline 
55 void SubstTable::subst(Char &c) const
56 {
57   c = operator[](c);
58 }
59
60 #ifdef SP_NAMESPACE
61 }
62 #endif
63
64 #endif /* SubstTable_INCLUDED */