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 <com/sun/star/i18n/TransliterationType.hpp>
22 #include <transliteration_Ignore.hxx>
23 #include <i18nutil/oneToOneMapping.hxx>
25 using namespace com::sun::star::i18n
;
26 using namespace com::sun::star::uno
;
31 transliteration_Ignore::equals(const OUString
& str1
, sal_Int32 pos1
, sal_Int32 nCount1
, sal_Int32
& nMatch1
,
32 const OUString
& str2
, sal_Int32 pos2
, sal_Int32 nCount2
, sal_Int32
& nMatch2
)
34 Sequence
< sal_Int32
> offset1
;
35 Sequence
< sal_Int32
> offset2
;
37 // The method folding is defined in a sub class.
38 OUString s1
= folding( str1
, pos1
, nCount1
, offset1
);
39 OUString s2
= folding( str2
, pos2
, nCount2
, offset2
);
41 const sal_Unicode
* p1
= s1
.getStr();
42 const sal_Unicode
* p2
= s2
.getStr();
43 sal_Int32 length
= std::min(s1
.getLength(), s2
.getLength());
46 for ( nmatch
= 0; nmatch
< length
; nmatch
++)
51 nMatch1
= offset1
[ nmatch
- 1 ] + 1; // Subtract 1 from nmatch because the index starts from zero.
52 nMatch2
= offset2
[ nmatch
- 1 ] + 1; // And then, add 1 to position because it means the number of character matched.
55 nMatch1
= 0; // No character was matched.
59 return (nmatch
== s1
.getLength()) && (nmatch
== s2
.getLength());
63 Sequence
< OUString
> SAL_CALL
64 transliteration_Ignore::transliterateRange( const OUString
& str1
, const OUString
& str2
)
66 if (str1
.isEmpty() || str2
.isEmpty())
67 throw RuntimeException();
69 Sequence
< OUString
> r(2);
70 r
[0] = str1
.copy(0, 1);
71 r
[1] = str2
.copy(0, 1);
77 transliteration_Ignore::getType()
79 // The type is also defined in com/sun/star/util/TransliterationType.hdl
80 return TransliterationType::IGNORE
;
85 transliteration_Ignore::transliterateImpl( const OUString
& inStr
, sal_Int32 startPos
, sal_Int32 nCount
,
86 Sequence
< sal_Int32
>& offset
, bool useOffset
)
88 // The method folding is defined in a sub class.
89 return foldingImpl( inStr
, startPos
, nCount
, offset
, useOffset
);
93 transliteration_Ignore::transliterateRange( const OUString
& str1
, const OUString
& str2
,
94 XTransliteration
& t1
, XTransliteration
& t2
)
96 if (str1
.isEmpty() || str2
.isEmpty())
97 throw RuntimeException();
99 Sequence
< sal_Int32
> offset
;
100 OUString s11
= t1
.transliterate( str1
, 0, 1, offset
);
101 OUString s12
= t1
.transliterate( str2
, 0, 1, offset
);
102 OUString s21
= t2
.transliterate( str1
, 0, 1, offset
);
103 OUString s22
= t2
.transliterate( str2
, 0, 1, offset
);
105 if ( (s11
== s21
) && (s12
== s22
) ) {
106 Sequence
< OUString
> r(2);
112 Sequence
< OUString
> r(4);
121 transliteration_Ignore::foldingImpl( const OUString
& inStr
, sal_Int32 startPos
,
122 sal_Int32 nCount
, Sequence
< sal_Int32
>& offset
, bool useOffset
)
124 // Create a string buffer which can hold nCount + 1 characters.
125 // The reference count is 1 now.
126 rtl_uString
* newStr
= rtl_uString_alloc(nCount
);
127 sal_Unicode
* dst
= newStr
->buffer
;
128 const sal_Unicode
* src
= inStr
.getStr() + startPos
;
130 // Allocate nCount length to offset argument.
131 sal_Int32
*p
= nullptr;
132 sal_Int32 position
= 0;
134 offset
.realloc( nCount
);
135 p
= offset
.getArray();
140 sal_Unicode previousChar
= *src
++;
141 sal_Unicode currentChar
;
144 while (-- nCount
> 0) {
145 currentChar
= *src
++;
148 for (m
= map
; m
->replaceChar
; m
++) {
149 if (previousChar
== m
->previousChar
&& currentChar
== m
->currentChar
) {
156 *dst
++ = m
->replaceChar
;
158 *dst
++ = currentChar
;
159 previousChar
= *src
++;
165 if (! m
->replaceChar
) {
168 *dst
++ = previousChar
;
169 previousChar
= currentChar
;
176 *dst
++ = previousChar
;
180 while (nCount
-- > 0) {
181 sal_Unicode c
= *src
++;
182 c
= func
? func( c
) : (*table
)[ c
];
192 newStr
->length
= sal_Int32(dst
- newStr
->buffer
);
194 offset
.realloc(newStr
->length
);
197 return OUString(newStr
, SAL_NO_ACQUIRE
); // take ownership
201 transliteration_Ignore::transliterateChar2Char( sal_Unicode inChar
)
203 return func
? func( inChar
) : table
? (*table
)[ inChar
] : inChar
;
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */