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

Generated by: LCOV version 1.10