LCOV - code coverage report
Current view: top level - i18npool/source/transliteration - transliteration_caseignore.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 29 56 51.8 %
Date: 2014-11-03 Functions: 6 9 66.7 %
Legend: Lines: hit not hit

          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             : #include <com/sun/star/uno/XComponentContext.hpp>
      21             : 
      22             : #include <i18nutil/oneToOneMapping.hxx>
      23             : #include <i18nutil/casefolding.hxx>
      24             : 
      25             : #include "transliteration_caseignore.hxx"
      26             : 
      27             : using namespace ::com::sun::star::uno;
      28             : using namespace ::com::sun::star::lang;
      29             : 
      30             : namespace com { namespace sun { namespace star { namespace i18n {
      31             : 
      32         240 : Transliteration_caseignore::Transliteration_caseignore()
      33             : {
      34         240 :     nMappingType = MappingTypeFullFolding;
      35         240 :     moduleLoaded = (TransliterationModules)0;
      36         240 :     transliterationName = "case ignore (generic)";
      37         240 :     implementationName = "com.sun.star.i18n.Transliteration.Transliteration_caseignore";
      38         240 : }
      39             : 
      40             : void SAL_CALL
      41        3580 : Transliteration_caseignore::loadModule( TransliterationModules modName, const Locale& rLocale )
      42             :     throw(RuntimeException, std::exception)
      43             : {
      44        3580 :     moduleLoaded = (TransliterationModules) (moduleLoaded|modName);
      45        3580 :     aLocale = rLocale;
      46        3580 : }
      47             : 
      48           0 : sal_Int16 SAL_CALL Transliteration_caseignore::getType() throw(RuntimeException, std::exception)
      49             : {
      50             :     // It's NOT TransliterationType::ONE_TO_ONE because it's using casefolding
      51           0 :     return TransliterationType::IGNORE;
      52             : }
      53             : 
      54             : 
      55             : Sequence< OUString > SAL_CALL
      56           0 : Transliteration_caseignore::transliterateRange( const OUString& str1, const OUString& str2 )
      57             :     throw( RuntimeException, std::exception)
      58             : {
      59           0 :     if (str1.getLength() != 1 || str2.getLength() != 1)
      60           0 :         throw RuntimeException();
      61             : 
      62           0 :     static Transliteration_u2l u2l;
      63           0 :     static Transliteration_l2u l2u;
      64             : 
      65           0 :     u2l.loadModule((TransliterationModules)0, aLocale);
      66           0 :     l2u.loadModule((TransliterationModules)0, aLocale);
      67             : 
      68           0 :     OUString l1 = u2l.transliterateString2String(str1, 0, str1.getLength());
      69           0 :     OUString u1 = l2u.transliterateString2String(str1, 0, str1.getLength());
      70           0 :     OUString l2 = u2l.transliterateString2String(str2, 0, str2.getLength());
      71           0 :     OUString u2 = l2u.transliterateString2String(str2, 0, str2.getLength());
      72             : 
      73           0 :     if ((l1 == u1) && (l2 == u2)) {
      74           0 :         Sequence< OUString > r(2);
      75           0 :         r[0] = l1;
      76           0 :         r[1] = l2;
      77           0 :         return r;
      78             :     } else {
      79           0 :         Sequence< OUString > r(4);
      80           0 :         r[0] = l1;
      81           0 :         r[1] = l2;
      82           0 :         r[2] = u1;
      83           0 :         r[3] = u2;
      84           0 :         return r;
      85           0 :     }
      86             : }
      87             : 
      88             : sal_Bool SAL_CALL
      89       46072 : Transliteration_caseignore::equals(
      90             :     const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
      91             :     const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
      92             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
      93             : {
      94       46072 :     return (compare(str1, pos1, nCount1, nMatch1, str2, pos2, nCount2, nMatch2) == 0);
      95             : }
      96             : 
      97             : sal_Int32 SAL_CALL
      98           0 : Transliteration_caseignore::compareSubstring(
      99             :     const OUString& str1, sal_Int32 off1, sal_Int32 len1,
     100             :     const OUString& str2, sal_Int32 off2, sal_Int32 len2)
     101             :     throw(RuntimeException, std::exception)
     102             : {
     103             :     sal_Int32 nMatch1, nMatch2;
     104           0 :     return compare(str1, off1, len1, nMatch1, str2, off2, len2, nMatch2);
     105             : }
     106             : 
     107             : 
     108             : sal_Int32 SAL_CALL
     109         162 : Transliteration_caseignore::compareString(
     110             :     const OUString& str1,
     111             :     const OUString& str2)
     112             :     throw(RuntimeException, std::exception)
     113             : {
     114             :     sal_Int32 nMatch1, nMatch2;
     115         162 :     return compare(str1, 0, str1.getLength(), nMatch1, str2, 0, str2.getLength(), nMatch2);
     116             : }
     117             : 
     118             : sal_Int32 SAL_CALL
     119       46234 : Transliteration_caseignore::compare(
     120             :     const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
     121             :     const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
     122             :     throw(RuntimeException)
     123             : {
     124       46234 :     const sal_Unicode *unistr1 = (sal_Unicode*) str1.getStr() + pos1;
     125       46234 :     const sal_Unicode *unistr2 = (sal_Unicode*) str2.getStr() + pos2;
     126             :     sal_Unicode c1, c2;
     127       46234 :     MappingElement e1, e2;
     128       46234 :     nMatch1 = nMatch2 = 0;
     129             : 
     130             : #define NOT_END_OF_STR1 (nMatch1 < nCount1 || e1.current < e1.element.nmap)
     131             : #define NOT_END_OF_STR2 (nMatch2 < nCount2 || e2.current < e2.element.nmap)
     132             : 
     133      140916 :     while (NOT_END_OF_STR1 && NOT_END_OF_STR2) {
     134       88642 :         c1 = casefolding::getNextChar(unistr1, nMatch1, nCount1, e1, aLocale, nMappingType, moduleLoaded);
     135       88642 :         c2 = casefolding::getNextChar(unistr2, nMatch2, nCount2, e2, aLocale, nMappingType, moduleLoaded);
     136       88642 :         if (c1 != c2) {
     137       40194 :         nMatch1--; nMatch2--;
     138       40194 :         return c1 > c2 ? 1 : -1;
     139             :         }
     140             :     }
     141             : 
     142       11916 :     return (!NOT_END_OF_STR1 && !NOT_END_OF_STR2) ? 0
     143        8226 :                 : (NOT_END_OF_STR1 ? 1 : -1);
     144             : }
     145             : 
     146             : } } } }
     147             : 
     148             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     149         240 : com_sun_star_i18n_Transliteration_IGNORE_CASE_get_implementation(
     150             :     css::uno::XComponentContext *,
     151             :     css::uno::Sequence<css::uno::Any> const &)
     152             : {
     153         240 :     return cppu::acquire(new css::i18n::Transliteration_caseignore());
     154             : }
     155             : 
     156             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10