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>
24 oneToOneMapping::oneToOneMapping( OneToOneMappingTable_t
const *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
43 const int current
= (top
+ bottom
) / 2;
44 if( nKey
< mpTable
[current
].first
)
46 else if( nKey
> mpTable
[current
].first
)
49 return mpTable
[current
].second
;
59 oneToOneMappingWithFlag::oneToOneMappingWithFlag( UnicodePairWithFlag
const *rpTableWF
, const size_t rnSize
, const UnicodePairFlag rnFlag
)
60 : oneToOneMapping( nullptr, rnSize
, sizeof(UnicodePairWithFlag
) ),
61 mpTableWF ( rpTableWF
),
67 oneToOneMappingWithFlag::~oneToOneMappingWithFlag()
71 void oneToOneMappingWithFlag::makeIndex()
73 if( mbHasIndex
|| !mpTableWF
)
78 for( size_t k
= 0; k
< mnSize
; k
++ )
80 const int high
= (mpTableWF
[k
].first
>> 8) & 0xFF;
81 const int low
= (mpTableWF
[k
].first
) & 0xFF;
85 mpIndex
[high
].reset(new UnicodePairWithFlag
const *[256]);
87 for (int j
= 0; j
< 256; ++j
)
88 mpIndex
[high
][j
] = nullptr;
90 mpIndex
[high
][low
] = &mpTableWF
[k
];
96 sal_Unicode
oneToOneMappingWithFlag::find( const sal_Unicode nKey
) const
104 high
= (nKey
>> 8) & 0xFF;
106 if( mpIndex
[high
] != nullptr &&
107 mpIndex
[high
][low
] != nullptr &&
108 mpIndex
[high
][low
]->flag
& mnFlag
)
109 return mpIndex
[high
][low
]->second
;
117 int top
= mnSize
- 1;
120 const int current
= (top
+ bottom
) / 2;
121 if( nKey
< mpTableWF
[current
].first
)
123 else if( nKey
> mpTableWF
[current
].first
)
124 bottom
= current
+ 1;
127 if( mpTableWF
[current
].flag
& mnFlag
)
128 return mpTableWF
[current
].second
;
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */