Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : // prevent internal compiler error with MSVC6SP3
22 : : #include <utility>
23 : :
24 : : #include <chaptercollator.hxx>
25 : : #include <com/sun/star/i18n/KCharacterType.hpp>
26 : : #include <com/sun/star/i18n/ParseResult.hpp>
27 : :
28 : : using namespace ::com::sun::star::lang;
29 : : using namespace ::com::sun::star::uno;
30 : : using namespace ::com::sun::star::i18n;
31 : : using namespace ::rtl;
32 : :
33 : 0 : ChapterCollator::ChapterCollator( const Reference < XMultiServiceFactory >& rxMSF ) : CollatorImpl(rxMSF)
34 : : {
35 [ # # ]: 0 : if ( rxMSF.is()) {
36 : : Reference < XInterface > xI =
37 [ # # ][ # # ]: 0 : rxMSF->createInstance( OUString("com.sun.star.i18n.CharacterClassification"));
38 [ # # ]: 0 : if ( xI.is() )
39 [ # # ][ # # ]: 0 : xI->queryInterface(::getCppuType((const Reference< XCharacterClassification>*)0)) >>= cclass;
[ # # ][ # # ]
40 : : }
41 : 0 : }
42 : :
43 : 0 : ChapterCollator::~ChapterCollator()
44 : : {
45 [ # # ]: 0 : }
46 : :
47 : : sal_Int32 SAL_CALL
48 : 0 : ChapterCollator::compareString( const OUString& s1, const OUString& s2) throw(RuntimeException)
49 : : {
50 : 0 : return compareSubstring(s1, 0, s1.getLength(), s2, 0, s2.getLength());
51 : : }
52 : :
53 : : #define DIGIT KCharacterType::DIGIT
54 : :
55 : : sal_Int32 SAL_CALL
56 : 0 : ChapterCollator::compareSubstring( const OUString& str1, sal_Int32 off1, sal_Int32 len1,
57 : : const OUString& str2, sal_Int32 off2, sal_Int32 len2) throw(RuntimeException)
58 : : {
59 [ # # ][ # # ]: 0 : if( len1 <= 1 || len2 <= 1 || ! cclass.is() )
[ # # ][ # # ]
60 [ # # ]: 0 : return CollatorImpl::compareSubstring( str1, off1, len1, str2, off2, len2 );
61 : :
62 : : sal_Int32 i1, i2;
63 [ # # ][ # # ]: 0 : for (i1 = len1; i1 && (cclass->getCharacterType(str1, off1+i1-1, nLocale) & DIGIT); i1--) ;
[ # # ][ # # ]
[ # # ]
64 [ # # ][ # # ]: 0 : for (i2 = len2; i2 && (cclass->getCharacterType(str2, off2+i2-1, nLocale) & DIGIT); i2--) ;
[ # # ][ # # ]
[ # # ]
65 : :
66 [ # # ]: 0 : sal_Int32 ans = CollatorImpl::compareSubstring(str1, off1, i1, str2, off2, i2);
67 [ # # ]: 0 : if( ans != 0 )
68 : 0 : return ans;
69 : :
70 : 0 : const OUString aAddAllowed("?");
71 : 0 : ParseResult res1, res2;
72 : : // since parseAnyToken does not take length as parameter, we have to copy
73 : : // it to a temp. string.
74 : 0 : OUString s1 = str1.copy(off1+i1, len1-i1), s2 = str2.copy(off2+i2, len2-i2);
75 [ # # ][ # # ]: 0 : res1 = cclass->parseAnyToken( s1, 0, nLocale, DIGIT, aAddAllowed, DIGIT, aAddAllowed );
76 [ # # ][ # # ]: 0 : res2 = cclass->parseAnyToken( s2, 0, nLocale, DIGIT, aAddAllowed, DIGIT, aAddAllowed );
77 : :
78 [ # # ][ # # ]: 0 : return res1.Value == res2.Value ? 0 : res1.Value > res2.Value ? 1 : -1;
79 : : }
80 : :
81 : : const sal_Char *cChapCollator = "com.sun.star.i18n.ChapterCollator";
82 : :
83 : : OUString SAL_CALL
84 : 0 : ChapterCollator::getImplementationName() throw( RuntimeException )
85 : : {
86 : 0 : return OUString::createFromAscii(cChapCollator);
87 : : }
88 : :
89 : : sal_Bool SAL_CALL
90 : 0 : ChapterCollator::supportsService(const rtl::OUString& rServiceName) throw( RuntimeException )
91 : : {
92 : 0 : return !rServiceName.compareToAscii(cChapCollator);
93 : : }
94 : :
95 : : Sequence< OUString > SAL_CALL
96 : 0 : ChapterCollator::getSupportedServiceNames() throw( RuntimeException )
97 : : {
98 : 0 : Sequence< OUString > aRet(1);
99 [ # # ]: 0 : aRet[0] = OUString::createFromAscii(cChapCollator);
100 : 0 : return aRet;
101 : : }
102 : :
103 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|