1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: oneToOneMapping.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <i18nutil/oneToOneMapping.hxx>
33 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
35 oneToOneMapping::oneToOneMapping( OneToOneMappingTable_t
*rpTable
, const size_t rnBytes
, const size_t rnUnitSize
)
37 mnSize( rnBytes
/ rnUnitSize
)
41 oneToOneMapping::~oneToOneMapping()
45 sal_Unicode
oneToOneMapping::find(const sal_Unicode nKey
) const
55 current
= (top
+ bottom
) / 2;
56 if( nKey
< mpTable
[current
].first
)
58 else if( nKey
> mpTable
[current
].first
)
61 return mpTable
[current
].second
;
64 return sal_Unicode( nKey
);
68 return sal_Unicode( nKey
);
71 oneToOneMappingWithFlag::oneToOneMappingWithFlag( UnicodePairWithFlag
*rpTableWF
, const size_t rnSize
, const UnicodePairFlag rnFlag
)
72 : oneToOneMapping( NULL
, rnSize
, sizeof(UnicodePairWithFlag
) ),
73 mpTableWF ( rpTableWF
),
75 mbHasIndex( sal_False
)
79 oneToOneMappingWithFlag::~oneToOneMappingWithFlag()
82 for( int i
= 0; i
< 256; i
++ )
88 void oneToOneMappingWithFlag::makeIndex()
90 if( !mbHasIndex
&& mpTableWF
)
92 int i
, j
, high
, low
, current
= -1;
94 for( i
= 0; i
< 256; i
++ )
97 for( size_t k
= 0; k
< mnSize
; k
++ )
99 high
= (mpTableWF
[k
].first
>> 8) & 0xFF;
100 low
= (mpTableWF
[k
].first
) & 0xFF;
101 if( high
!= current
)
104 mpIndex
[high
] = new UnicodePairWithFlag
*[256];
106 for( j
= 0; j
< 256; j
++ )
107 mpIndex
[high
][j
] = NULL
;
109 mpIndex
[high
][low
] = &mpTableWF
[k
];
112 mbHasIndex
= sal_True
;
116 sal_Unicode
oneToOneMappingWithFlag::find( const sal_Unicode nKey
) const
124 high
= (nKey
>> 8) & 0xFF;
126 if( mpIndex
[high
] != NULL
&&
127 mpIndex
[high
][low
] != NULL
&&
128 mpIndex
[high
][low
]->flag
& mnFlag
)
129 return mpIndex
[high
][low
]->second
;
131 return sal_Unicode( nKey
);
137 int top
= mnSize
- 1;
141 current
= (top
+ bottom
) / 2;
142 if( nKey
< mpTableWF
[current
].first
)
144 else if( nKey
> mpTableWF
[current
].first
)
145 bottom
= current
+ 1;
148 if( mpTableWF
[current
].flag
& mnFlag
)
149 return mpTableWF
[current
].second
;
151 return sal_Unicode( nKey
);
155 return sal_Unicode( nKey
);
160 return sal_Unicode( nKey
);