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: chaptercollator.cxx,v $
10 * $Revision: 1.11.22.1 $
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 <chaptercollator.hxx>
38 #include <com/sun/star/i18n/KCharacterType.hpp>
39 #include <com/sun/star/i18n/ParseResult.hpp>
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::i18n
;
44 using namespace ::rtl
;
46 ChapterCollator::ChapterCollator( const Reference
< XMultiServiceFactory
>& rxMSF
) : CollatorImpl(rxMSF
)
49 Reference
< XInterface
> xI
=
50 rxMSF
->createInstance( OUString::createFromAscii("com.sun.star.i18n.CharacterClassification"));
52 xI
->queryInterface(::getCppuType((const Reference
< XCharacterClassification
>*)0)) >>= cclass
;
56 ChapterCollator::~ChapterCollator()
61 ChapterCollator::compareString( const OUString
& s1
, const OUString
& s2
) throw(RuntimeException
)
63 return compareSubstring(s1
, 0, s1
.getLength(), s2
, 0, s2
.getLength());
66 #define DIGIT KCharacterType::DIGIT
69 ChapterCollator::compareSubstring( const OUString
& str1
, sal_Int32 off1
, sal_Int32 len1
,
70 const OUString
& str2
, sal_Int32 off2
, sal_Int32 len2
) throw(RuntimeException
)
72 if( len1
<= 1 || len2
<= 1 || ! cclass
.is() )
73 return CollatorImpl::compareSubstring( str1
, off1
, len1
, str2
, off2
, len2
);
76 for (i1
= len1
; i1
&& (cclass
->getCharacterType(str1
, off1
+i1
-1, nLocale
) & DIGIT
); i1
--) ;
77 for (i2
= len2
; i2
&& (cclass
->getCharacterType(str2
, off2
+i2
-1, nLocale
) & DIGIT
); i2
--) ;
79 sal_Int32 ans
= CollatorImpl::compareSubstring(str1
, off1
, i1
, str2
, off2
, i2
);
83 const OUString
&aAddAllowed
= OUString::createFromAscii("?");
84 ParseResult res1
, res2
;
85 // Bug #100323#, since parseAnyToken does not take length as parameter, we have to copy
86 // it to a temp. string.
87 OUString s1
= str1
.copy(off1
+i1
, len1
-i1
), s2
= str2
.copy(off2
+i2
, len2
-i2
);
88 res1
= cclass
->parseAnyToken( s1
, 0, nLocale
, DIGIT
, aAddAllowed
, DIGIT
, aAddAllowed
);
89 res2
= cclass
->parseAnyToken( s2
, 0, nLocale
, DIGIT
, aAddAllowed
, DIGIT
, aAddAllowed
);
91 return res1
.Value
== res2
.Value
? 0 : res1
.Value
> res2
.Value
? 1 : -1;
94 const sal_Char
*cChapCollator
= "com.sun.star.i18n.ChapterCollator";
97 ChapterCollator::getImplementationName() throw( RuntimeException
)
99 return OUString::createFromAscii(cChapCollator
);
103 ChapterCollator::supportsService(const rtl::OUString
& rServiceName
) throw( RuntimeException
)
105 return !rServiceName
.compareToAscii(cChapCollator
);
108 Sequence
< OUString
> SAL_CALL
109 ChapterCollator::getSupportedServiceNames() throw( RuntimeException
)
111 Sequence
< OUString
> aRet(1);
112 aRet
[0] = OUString::createFromAscii(cChapCollator
);