LCOV - code coverage report
Current view: top level - i18npool/source/textconversion - textconversionImpl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 39 54 72.2 %
Date: 2015-06-13 12:38:46 Functions: 7 10 70.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 <assert.h>
      21             : #include <cppuhelper/supportsservice.hxx>
      22             : #include <textconversionImpl.hxx>
      23             : #include <localedata.hxx>
      24             : #include <i18nlangtag/languagetag.hxx>
      25             : 
      26             : using namespace com::sun::star::lang;
      27             : using namespace com::sun::star::uno;
      28             : 
      29             : namespace com { namespace sun { namespace star { namespace i18n {
      30             : 
      31             : TextConversionResult SAL_CALL
      32           2 : TextConversionImpl::getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
      33             :     const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
      34             :     throw(  RuntimeException, IllegalArgumentException, NoSupportException, std::exception )
      35             : {
      36           2 :     getLocaleSpecificTextConversion(rLocale);
      37             : 
      38           2 :     sal_Int32 len = aText.getLength() - nStartPos;
      39           2 :     if (nLength > len)
      40           0 :         nLength = len > 0 ? len : 0;
      41           2 :     return xTC->getConversions(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
      42             : }
      43             : 
      44             : OUString SAL_CALL
      45           0 : TextConversionImpl::getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
      46             :     const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
      47             :     throw(  RuntimeException, IllegalArgumentException, NoSupportException, std::exception )
      48             : {
      49           0 :     getLocaleSpecificTextConversion(rLocale);
      50             : 
      51           0 :     sal_Int32 len = aText.getLength() - nStartPos;
      52           0 :     if (nLength > len)
      53           0 :         nLength = len > 0 ? len : 0;
      54           0 :     return xTC->getConversion(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
      55             : }
      56             : 
      57             : OUString SAL_CALL
      58           2 : TextConversionImpl::getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
      59             :     const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions, Sequence< sal_Int32>& offset)
      60             :     throw(  RuntimeException, IllegalArgumentException, NoSupportException, std::exception )
      61             : {
      62           2 :     getLocaleSpecificTextConversion(rLocale);
      63             : 
      64           2 :     sal_Int32 len = aText.getLength() - nStartPos;
      65           2 :     if (nLength > len)
      66           0 :         nLength = len > 0 ? len : 0;
      67           2 :     return xTC->getConversionWithOffset(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions, offset);
      68             : }
      69             : 
      70             : sal_Bool SAL_CALL
      71           0 : TextConversionImpl::interactiveConversion( const Locale& rLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions )
      72             :     throw(  RuntimeException, IllegalArgumentException, NoSupportException, std::exception )
      73             : {
      74           0 :     getLocaleSpecificTextConversion(rLocale);
      75             : 
      76           0 :     return xTC->interactiveConversion(rLocale, nTextConversionType, nTextConversionOptions);
      77             : }
      78             : 
      79           4 : static inline bool operator != (const Locale& l1, const Locale& l2) {
      80           4 :     return l1.Language != l2.Language || l1.Country != l2.Country || l1.Variant != l2.Variant;
      81             : }
      82             : 
      83             : void SAL_CALL
      84           4 : TextConversionImpl::getLocaleSpecificTextConversion(const Locale& rLocale) throw( NoSupportException )
      85             : {
      86           4 :     if (rLocale != aLocale) {
      87           2 :         aLocale = rLocale;
      88             : 
      89           2 :         OUString aPrefix("com.sun.star.i18n.TextConversion_");
      90           4 :         Reference < XInterface > xI;
      91             : 
      92          10 :         xI = m_xContext->getServiceManager()->createInstanceWithContext(
      93           8 :                 aPrefix + LocaleDataImpl::getFirstLocaleServiceName( aLocale), m_xContext);
      94           2 :         if (!xI.is())
      95             :         {
      96           2 :             ::std::vector< OUString > aFallbacks( LocaleDataImpl::getFallbackLocaleServiceNames( aLocale));
      97           2 :             for (::std::vector< OUString >::const_iterator it( aFallbacks.begin()); it != aFallbacks.end(); ++it)
      98             :             {
      99           2 :                 xI = m_xContext->getServiceManager()->createInstanceWithContext( aPrefix + *it, m_xContext);
     100           2 :                 if (xI.is())
     101           2 :                     break;
     102           2 :             }
     103             :         }
     104           2 :         if (xI.is())
     105           2 :             xTC.set( xI, UNO_QUERY );
     106           0 :         else if (xTC.is())
     107           2 :             xTC.clear();
     108             :     }
     109           4 :     if (! xTC.is())
     110           0 :         throw NoSupportException(); // aLocale is not supported
     111           4 : }
     112             : 
     113             : OUString SAL_CALL
     114           1 : TextConversionImpl::getImplementationName() throw( RuntimeException, std::exception )
     115             : {
     116           1 :     return OUString("com.sun.star.i18n.TextConversion");
     117             : }
     118             : 
     119             : sal_Bool SAL_CALL
     120           0 : TextConversionImpl::supportsService(const OUString& rServiceName)
     121             :                 throw( RuntimeException, std::exception )
     122             : {
     123           0 :     return cppu::supportsService(this, rServiceName);
     124             : }
     125             : 
     126             : Sequence< OUString > SAL_CALL
     127           1 : TextConversionImpl::getSupportedServiceNames() throw( RuntimeException, std::exception )
     128             : {
     129           1 :     Sequence< OUString > aRet(1);
     130           1 :     aRet[0] = "com.sun.star.i18n.TextConversion";
     131           1 :     return aRet;
     132             : }
     133             : 
     134             : } } } }
     135             : 
     136             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     137           5 : com_sun_star_i18n_TextConversion_get_implementation(
     138             :     css::uno::XComponentContext *context,
     139             :     css::uno::Sequence<css::uno::Any> const &)
     140             : {
     141           5 :     return cppu::acquire(new css::i18n::TextConversionImpl(context));
     142             : }
     143             : 
     144             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11