1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <i18nutil/oneToOneMapping.hxx>
22 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
24 oneToOneMapping::oneToOneMapping( OneToOneMappingTable_t
*rpTable
, const size_t rnBytes
, const size_t rnUnitSize
)
26 mnSize( rnBytes
/ rnUnitSize
)
30 oneToOneMapping::~oneToOneMapping()
34 sal_Unicode
oneToOneMapping::find(const sal_Unicode nKey
) const
44 current
= (top
+ bottom
) / 2;
45 if( nKey
< mpTable
[current
].first
)
47 else if( nKey
> mpTable
[current
].first
)
50 return mpTable
[current
].second
;
53 return sal_Unicode( nKey
);
57 return sal_Unicode( nKey
);
60 oneToOneMappingWithFlag::oneToOneMappingWithFlag( UnicodePairWithFlag
*rpTableWF
, const size_t rnSize
, const UnicodePairFlag rnFlag
)
61 : oneToOneMapping( NULL
, rnSize
, sizeof(UnicodePairWithFlag
) ),
62 mpTableWF ( rpTableWF
),
68 oneToOneMappingWithFlag::~oneToOneMappingWithFlag()
71 for( int i
= 0; i
< 256; i
++ )
77 void oneToOneMappingWithFlag::makeIndex()
79 if( !mbHasIndex
&& mpTableWF
)
81 int i
, j
, high
, low
, current
= -1;
83 for( i
= 0; i
< 256; i
++ )
86 for( size_t k
= 0; k
< mnSize
; k
++ )
88 high
= (mpTableWF
[k
].first
>> 8) & 0xFF;
89 low
= (mpTableWF
[k
].first
) & 0xFF;
93 mpIndex
[high
] = new UnicodePairWithFlag
*[256];
95 for( j
= 0; j
< 256; j
++ )
96 mpIndex
[high
][j
] = NULL
;
98 mpIndex
[high
][low
] = &mpTableWF
[k
];
105 sal_Unicode
oneToOneMappingWithFlag::find( const sal_Unicode nKey
) const
113 high
= (nKey
>> 8) & 0xFF;
115 if( mpIndex
[high
] != NULL
&&
116 mpIndex
[high
][low
] != NULL
&&
117 mpIndex
[high
][low
]->flag
& mnFlag
)
118 return mpIndex
[high
][low
]->second
;
120 return sal_Unicode( nKey
);
126 int top
= mnSize
- 1;
130 current
= (top
+ bottom
) / 2;
131 if( nKey
< mpTableWF
[current
].first
)
133 else if( nKey
> mpTableWF
[current
].first
)
134 bottom
= current
+ 1;
137 if( mpTableWF
[current
].flag
& mnFlag
)
138 return mpTableWF
[current
].second
;
140 return sal_Unicode( nKey
);
144 return sal_Unicode( nKey
);
149 return sal_Unicode( nKey
);
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */