2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: SubstTable.C /main/1 1996/07/29 17:05:48 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef SubstTable_DEF_INCLUDED
28 #define SubstTable_DEF_INCLUDED 1
31 namespace SP_NAMESPACE {
35 SubstTable<T>::SubstTable()
41 void SubstTable<T>::addSubst(T from, T to)
43 if (table_.size() == 0) {
44 table_.resize(T(-1) + 1);
45 for (int i = 0; i < T(-1) + 1; i++)
48 if (table_[from] != to)
54 String<T> SubstTable<T>::inverse(T ch) const
57 const T *p = table_.data();
58 size_t length = table_.size();
59 for (size_t i = 0; i < length; i++)
61 // FIXME use mutable if available
62 ((SubstTable<T> *)this)->pairs_ += T(i);
63 ((SubstTable<T> *)this)->pairs_ += p[i];
65 ((SubstTable<T> *)this)->pairsValid_ = 1;
67 const T *p = pairs_.data();
69 return String<T>(&ch, 1);
73 for (size_t n = pairs_.size(); n > 0; n -= 2, p += 2)
80 void SubstTable<T>::inverseTable(SubstTable<T> &inv) const
82 if (table_.size() == 0) {
88 if (inv.table_.size() == 0)
89 inv.table_.resize(T(-1) + 1);
91 for (i = 0; i < T(-1) + 1; i++)
95 for (i = 0; i < T(-1) + 1; i++)
97 inv.table_[table_[i]] = i;
102 void SubstTable<T>::subst(String<T> &str) const
104 for (size_t i = 0; i < str.size(); i++)
112 #endif /* not SubstTable_DEF_INCLUDED */