LCOV - code coverage report
Current view: top level - i18npool/source/transliteration - transliteration_Ignore.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 27 100 27.0 %
Date: 2014-11-03 Functions: 2 8 25.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             : #include <transliteration_Ignore.hxx>
      21             : 
      22             : using namespace com::sun::star::uno;
      23             : 
      24             : namespace com { namespace sun { namespace star { namespace i18n {
      25             : 
      26           0 : inline sal_Int32 Min( sal_Int32 a, sal_Int32 b ) { return a > b ? b : a; }
      27             : 
      28             : sal_Bool SAL_CALL
      29           0 : transliteration_Ignore::equals(const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
      30             :         const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2 ) throw(RuntimeException, std::exception)
      31             : {
      32           0 :     Sequence< sal_Int32 > offset1;
      33           0 :     Sequence< sal_Int32 > offset2;
      34             : 
      35             :     // The method folding is defined in a sub class.
      36           0 :     OUString s1 = this->folding( str1, pos1, nCount1, offset1);
      37           0 :     OUString s2 = this->folding( str2, pos2, nCount2, offset2);
      38             : 
      39           0 :     const sal_Unicode * p1 = s1.getStr();
      40           0 :     const sal_Unicode * p2 = s2.getStr();
      41           0 :     sal_Int32 length = Min(s1.getLength(), s2.getLength());
      42             :     sal_Int32 nmatch;
      43             : 
      44           0 :     for ( nmatch = 0; nmatch < length; nmatch++)
      45           0 :         if (*p1++ != *p2++)
      46           0 :             break;
      47             : 
      48           0 :     if (nmatch > 0) {
      49           0 :         nMatch1 = offset1[ nmatch - 1 ] + 1; // Subtract 1 from nmatch because the index starts from zero.
      50           0 :         nMatch2 = offset2[ nmatch - 1 ] + 1; // And then, add 1 to position because it means the number of character matched.
      51             :     }
      52             :     else {
      53           0 :         nMatch1 = 0;  // No character was matched.
      54           0 :         nMatch2 = 0;
      55             :     }
      56             : 
      57           0 :     return (nmatch == s1.getLength()) && (nmatch == s2.getLength());
      58             : }
      59             : 
      60             : 
      61             : Sequence< OUString > SAL_CALL
      62           0 : transliteration_Ignore::transliterateRange( const OUString& str1, const OUString& str2 ) throw(RuntimeException, std::exception)
      63             : {
      64           0 :     if (str1.isEmpty() || str2.isEmpty())
      65           0 :         throw RuntimeException();
      66             : 
      67           0 :     Sequence< OUString > r(2);
      68           0 :     r[0] = str1.copy(0, 1);
      69           0 :     r[1] = str2.copy(0, 1);
      70           0 :     return r;
      71             : }
      72             : 
      73             : 
      74             : sal_Int16 SAL_CALL
      75           0 : transliteration_Ignore::getType() throw(RuntimeException, std::exception)
      76             : {
      77             :     // The type is also defined in com/sun/star/util/TransliterationType.hdl
      78           0 :     return TransliterationType::IGNORE;
      79             : }
      80             : 
      81             : 
      82             : OUString SAL_CALL
      83          38 : transliteration_Ignore::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
      84             :         Sequence< sal_Int32 >& offset  ) throw(RuntimeException, std::exception)
      85             : {
      86             :     // The method folding is defined in a sub class.
      87          38 :     return this->folding( inStr, startPos, nCount, offset);
      88             : }
      89             : 
      90             : Sequence< OUString > SAL_CALL
      91           0 : transliteration_Ignore::transliterateRange( const OUString& str1, const OUString& str2,
      92             :         XTransliteration& t1, XTransliteration& t2 ) throw(RuntimeException)
      93             : {
      94           0 :     if (str1.isEmpty() || str2.isEmpty())
      95           0 :         throw RuntimeException();
      96             : 
      97           0 :     Sequence< sal_Int32 > offset;
      98           0 :     OUString s11 = t1.transliterate( str1, 0, 1, offset );
      99           0 :     OUString s12 = t1.transliterate( str2, 0, 1, offset );
     100           0 :     OUString s21 = t2.transliterate( str1, 0, 1, offset );
     101           0 :     OUString s22 = t2.transliterate( str2, 0, 1, offset );
     102             : 
     103           0 :     if ( (s11 == s21) && (s12 == s22) ) {
     104           0 :         Sequence< OUString > r(2);
     105           0 :         r[0] = s11;
     106           0 :         r[1] = s12;
     107           0 :         return r;
     108             :     }
     109             : 
     110           0 :     Sequence< OUString > r(4);
     111           0 :     r[0] = s11;
     112           0 :     r[1] = s12;
     113           0 :     r[2] = s21;
     114           0 :     r[3] = s22;
     115           0 :     return r;
     116             : }
     117             : 
     118             : OUString SAL_CALL
     119          16 : transliteration_Ignore::folding( const OUString& inStr, sal_Int32 startPos,
     120             :     sal_Int32 nCount, Sequence< sal_Int32 >& offset)
     121             :     throw(RuntimeException, std::exception)
     122             : {
     123             :     // Create a string buffer which can hold nCount + 1 characters.
     124             :     // The reference count is 1 now.
     125          16 :     rtl_uString * newStr = rtl_uString_alloc(nCount);
     126          16 :     sal_Unicode * dst = newStr->buffer;
     127          16 :     const sal_Unicode * src = inStr.getStr() + startPos;
     128             : 
     129             :     // Allocate nCount length to offset argument.
     130          16 :     sal_Int32 *p = 0;
     131          16 :     sal_Int32 position = 0;
     132          16 :     if (useOffset) {
     133           8 :         offset.realloc( nCount );
     134           8 :         p = offset.getArray();
     135           8 :         position = startPos;
     136             :     }
     137             : 
     138          16 :     if (map) {
     139           0 :         sal_Unicode previousChar = *src ++;
     140             :         sal_Unicode currentChar;
     141             : 
     142             :         // Translation
     143           0 :         while (-- nCount > 0) {
     144           0 :             currentChar = *src ++;
     145             : 
     146             :             const Mapping *m;
     147           0 :             for (m = map; m->replaceChar; m++) {
     148           0 :                 if (previousChar == m->previousChar &&  currentChar == m->currentChar ) {
     149           0 :                     if (useOffset) {
     150           0 :                         if (! m->two2one)
     151           0 :                             *p++ = position;
     152           0 :                         position++;
     153           0 :                         *p++ = position++;
     154             :                     }
     155           0 :                     *dst++ = m->replaceChar;
     156           0 :                     if (!m->two2one)
     157           0 :                         *dst++ = currentChar;
     158           0 :                     previousChar = *src++;
     159           0 :                     nCount--;
     160           0 :                     break;
     161             :                 }
     162             :             }
     163             : 
     164           0 :             if (! m->replaceChar) {
     165           0 :                 if (useOffset)
     166           0 :                     *p ++ = position ++;
     167           0 :                 *dst ++ = previousChar;
     168           0 :                 previousChar = currentChar;
     169             :             }
     170             :         }
     171             : 
     172           0 :         if (nCount == 0) {
     173           0 :             if (useOffset)
     174           0 :                 *p = position;
     175           0 :             *dst ++ = previousChar;
     176             :         }
     177             :     } else {
     178             :         // Translation
     179         580 :         while (nCount -- > 0) {
     180         548 :             sal_Unicode c = *src++;
     181         548 :             c = func ? func( c) : (*table)[ c ];
     182         548 :             if (c != 0xffff)
     183         548 :                 *dst ++ = c;
     184         548 :             if (useOffset) {
     185         520 :                 if (c != 0xffff)
     186         520 :                     *p ++ = position;
     187         520 :                 position++;
     188             :             }
     189             :         }
     190             :     }
     191          16 :     newStr->length = sal_Int32(dst - newStr->buffer);
     192          16 :     if (useOffset)
     193           8 :       offset.realloc(newStr->length);
     194          16 :     *dst = (sal_Unicode) 0;
     195             : 
     196          16 :     return OUString(newStr, SAL_NO_ACQUIRE); // take ownership
     197             : }
     198             : 
     199             : sal_Unicode SAL_CALL
     200           0 : transliteration_Ignore::transliterateChar2Char( sal_Unicode inChar) throw(RuntimeException, MultipleCharsOutputException, std::exception)
     201             : {
     202           0 :     return func ? func( inChar) : table ? (*table)[ inChar ] : inChar;
     203             : }
     204             : 
     205             : } } } }
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10