1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef INCLUDED_I18NUTIL_TRANSLITERATION_ONETOONEMAPPING_HXX
24 #define INCLUDED_I18NUTIL_TRANSLITERATION_ONETOONEMAPPING_HXX
25 
26 #include <utility>
27 #include <rtl/ustring.hxx>
28 
29 namespace com { namespace sun { namespace star { namespace i18n {
30 
31 class widthfolding;
32 
33 typedef std::pair< sal_Unicode, sal_Unicode > OneToOneMappingTable_t;
34 
35 #define MAKE_PAIR(item1,item2) std::make_pair< sal_Unicode, sal_Unicode >((sal_Unicode)item1,(sal_Unicode)item2)
36 
37 typedef sal_Int8 UnicodePairFlag;
38 typedef struct _UnicodePairWithFlag
39 {
40     sal_Unicode     first;
41     sal_Unicode     second;
42     UnicodePairFlag flag;
43 } UnicodePairWithFlag;
44 
45 class oneToOneMapping
46 {
47 private:
48     // no copy, no substitution
49     oneToOneMapping( const oneToOneMapping& );
50     oneToOneMapping& operator=( const oneToOneMapping& );
51 public:
52     oneToOneMapping( OneToOneMappingTable_t *rpTable, const size_t rnSize, const size_t rnUnitSize = sizeof(OneToOneMappingTable_t) );
53     virtual ~oneToOneMapping();
54 
55     // make index for fast search
56     // bluedawrf: not used
57 //        void makeIndex();
58 
59     // binary search
60     virtual sal_Unicode find( const sal_Unicode nKey ) const;
61 
62     // translator
operator [](const sal_Unicode nKey) const63     sal_Unicode operator[] ( const sal_Unicode nKey ) const { return find( nKey ); };
64 
65 protected:
66     OneToOneMappingTable_t *mpTable;
67     size_t                  mnSize;
68 };
69 
70 class oneToOneMappingWithFlag : public oneToOneMapping
71 {
72     friend class widthfolding;
73 
74 private:
75     // no copy, no substitution
76     oneToOneMappingWithFlag( const oneToOneMappingWithFlag& );
77     oneToOneMappingWithFlag& operator=( const oneToOneMappingWithFlag& );
78 public:
79     oneToOneMappingWithFlag( UnicodePairWithFlag *rpTableWF, const size_t rnSize, const UnicodePairFlag rnFlag );
80     virtual ~oneToOneMappingWithFlag();
81 
82     // make index for fast search
83     void makeIndex();
84 
85     // index search
86     virtual sal_Unicode find( const sal_Unicode nKey ) const;
87 protected:
88     UnicodePairWithFlag  *mpTableWF;
89     UnicodePairFlag       mnFlag;
90     UnicodePairWithFlag **mpIndex[256];
91     sal_Bool              mbHasIndex;
92 };
93 
94 } } } }
95 
96 #endif // _I18N_TRANSLITERATION_ONETOONEMAPPING_HXX_
97