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: transliteration_Ignore.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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
34 // prevent internal compiler error with MSVC6SP3
37 #include <transliteration_Ignore.hxx>
39 using namespace com::sun::star::uno
;
42 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
44 inline sal_Int32
Min( sal_Int32 a
, sal_Int32 b
) { return a
> b
? b
: a
; }
47 transliteration_Ignore::equals(const OUString
& str1
, sal_Int32 pos1
, sal_Int32 nCount1
, sal_Int32
& nMatch1
,
48 const OUString
& str2
, sal_Int32 pos2
, sal_Int32 nCount2
, sal_Int32
& nMatch2
) throw(RuntimeException
)
50 Sequence
< sal_Int32
> offset1
;
51 Sequence
< sal_Int32
> offset2
;
53 // The method folding is defined in a sub class.
54 OUString s1
= this->folding( str1
, pos1
, nCount1
, offset1
);
55 OUString s2
= this->folding( str2
, pos2
, nCount2
, offset2
);
57 const sal_Unicode
* p1
= s1
.getStr();
58 const sal_Unicode
* p2
= s2
.getStr();
59 sal_Int32 length
= Min(s1
.getLength(), s2
.getLength());
62 for ( nmatch
= 0; nmatch
< length
; nmatch
++)
67 nMatch1
= offset1
[ nmatch
- 1 ] + 1; // Subtract 1 from nmatch because the index starts from zero.
68 nMatch2
= offset2
[ nmatch
- 1 ] + 1; // And then, add 1 to position because it means the number of character matched.
71 nMatch1
= 0; // No character was matched.
75 return (nmatch
== s1
.getLength()) && (nmatch
== s2
.getLength());
79 Sequence
< OUString
> SAL_CALL
80 transliteration_Ignore::transliterateRange( const OUString
& str1
, const OUString
& str2
) throw(RuntimeException
)
82 if (str1
.getLength() < 1 || str2
.getLength() < 1)
83 throw RuntimeException();
85 Sequence
< OUString
> r(2);
86 r
[0] = str1
.copy(0, 1);
87 r
[1] = str2
.copy(0, 1);
93 transliteration_Ignore::getType() throw(RuntimeException
)
95 // The type is also defined in com/sun/star/util/TransliterationType.hdl
96 return TransliterationType::IGNORE
;
101 transliteration_Ignore::transliterate( const OUString
& inStr
, sal_Int32 startPos
, sal_Int32 nCount
,
102 Sequence
< sal_Int32
>& offset
) throw(RuntimeException
)
104 // The method folding is defined in a sub class.
105 return this->folding( inStr
, startPos
, nCount
, offset
);
108 Sequence
< OUString
> SAL_CALL
109 transliteration_Ignore::transliterateRange( const OUString
& str1
, const OUString
& str2
,
110 XTransliteration
& t1
, XTransliteration
& t2
) throw(RuntimeException
)
112 if (str1
.getLength() < 1 || str2
.getLength() < 1)
113 throw RuntimeException();
115 Sequence
< sal_Int32
> offset
;
116 OUString s11
= t1
.transliterate( str1
, 0, 1, offset
);
117 OUString s12
= t1
.transliterate( str2
, 0, 1, offset
);
118 OUString s21
= t2
.transliterate( str1
, 0, 1, offset
);
119 OUString s22
= t2
.transliterate( str2
, 0, 1, offset
);
121 if ( (s11
== s21
) && (s12
== s22
) ) {
122 Sequence
< OUString
> r(2);
128 Sequence
< OUString
> r(4);
137 transliteration_Ignore::folding( const OUString
& inStr
, sal_Int32 startPos
,
138 sal_Int32 nCount
, Sequence
< sal_Int32
>& offset
)
139 throw(RuntimeException
)
141 // Create a string buffer which can hold nCount + 1 characters.
142 // The reference count is 0 now.
143 rtl_uString
* newStr
= x_rtl_uString_new_WithLength( nCount
); // defined in x_rtl_ustring.h
144 sal_Unicode
* dst
= newStr
->buffer
;
145 const sal_Unicode
* src
= inStr
.getStr() + startPos
;
147 // Allocate nCount length to offset argument.
149 sal_Int32 position
= 0;
151 offset
.realloc( nCount
);
152 p
= offset
.getArray();
157 sal_Unicode previousChar
= *src
++;
158 sal_Unicode currentChar
;
161 while (-- nCount
> 0) {
162 currentChar
= *src
++;
165 for (m
= map
; m
->replaceChar
; m
++) {
166 if (previousChar
== m
->previousChar
&& currentChar
== m
->currentChar
) {
173 *dst
++ = m
->replaceChar
;
175 *dst
++ = currentChar
;
176 previousChar
= *src
++;
182 if (! m
->replaceChar
) {
185 *dst
++ = previousChar
;
186 previousChar
= currentChar
;
193 *dst
++ = previousChar
;
197 while (nCount
-- > 0) {
198 sal_Unicode c
= *src
++;
199 c
= func
? func( c
) : (*table
)[ c
];
209 newStr
->length
= sal_Int32(dst
- newStr
->buffer
);
211 offset
.realloc(newStr
->length
);
212 *dst
= (sal_Unicode
) 0;
214 return OUString( newStr
); // defined in rtl/usrting. The reference count is increased from 0 to 1.
218 transliteration_Ignore::transliterateChar2Char( sal_Unicode inChar
) throw(RuntimeException
, MultipleCharsOutputException
)
220 return func
? func( inChar
) : table
? (*table
)[ inChar
] : inChar
;