Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / i18npool / source / textconversion / textconversionImpl.cxx
blob2386d44ccb63a7b887b675b29fedd927a98bda1f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <assert.h>
21 #include <cppuhelper/supportsservice.hxx>
22 #include <textconversionImpl.hxx>
23 #include <localedata.hxx>
24 #include <i18nlangtag/languagetag.hxx>
26 using namespace com::sun::star::lang;
27 using namespace com::sun::star::uno;
29 namespace com { namespace sun { namespace star { namespace i18n {
31 TextConversionResult SAL_CALL
32 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 )
36 getLocaleSpecificTextConversion(rLocale);
38 sal_Int32 len = aText.getLength() - nStartPos;
39 if (nLength > len)
40 nLength = len > 0 ? len : 0;
41 return xTC->getConversions(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
44 OUString SAL_CALL
45 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 )
49 getLocaleSpecificTextConversion(rLocale);
51 sal_Int32 len = aText.getLength() - nStartPos;
52 if (nLength > len)
53 nLength = len > 0 ? len : 0;
54 return xTC->getConversion(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
57 OUString SAL_CALL
58 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 )
62 getLocaleSpecificTextConversion(rLocale);
64 sal_Int32 len = aText.getLength() - nStartPos;
65 if (nLength > len)
66 nLength = len > 0 ? len : 0;
67 return xTC->getConversionWithOffset(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions, offset);
70 sal_Bool SAL_CALL
71 TextConversionImpl::interactiveConversion( const Locale& rLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions )
72 throw( RuntimeException, IllegalArgumentException, NoSupportException, std::exception )
74 getLocaleSpecificTextConversion(rLocale);
76 return xTC->interactiveConversion(rLocale, nTextConversionType, nTextConversionOptions);
79 void SAL_CALL
80 TextConversionImpl::getLocaleSpecificTextConversion(const Locale& rLocale) throw( NoSupportException )
82 if (rLocale != aLocale) {
83 aLocale = rLocale;
85 OUString aPrefix("com.sun.star.i18n.TextConversion_");
86 Reference < XInterface > xI;
88 xI = m_xContext->getServiceManager()->createInstanceWithContext(
89 aPrefix + LocaleDataImpl::getFirstLocaleServiceName( aLocale), m_xContext);
90 if (!xI.is())
92 ::std::vector< OUString > aFallbacks( LocaleDataImpl::getFallbackLocaleServiceNames( aLocale));
93 for (::std::vector< OUString >::const_iterator it( aFallbacks.begin()); it != aFallbacks.end(); ++it)
95 xI = m_xContext->getServiceManager()->createInstanceWithContext( aPrefix + *it, m_xContext);
96 if (xI.is())
97 break;
100 if (xI.is())
101 xTC.set( xI, UNO_QUERY );
102 else if (xTC.is())
103 xTC.clear();
105 if (! xTC.is())
106 throw NoSupportException(); // aLocale is not supported
109 OUString SAL_CALL
110 TextConversionImpl::getImplementationName() throw( RuntimeException, std::exception )
112 return OUString("com.sun.star.i18n.TextConversion");
115 sal_Bool SAL_CALL
116 TextConversionImpl::supportsService(const OUString& rServiceName)
117 throw( RuntimeException, std::exception )
119 return cppu::supportsService(this, rServiceName);
122 Sequence< OUString > SAL_CALL
123 TextConversionImpl::getSupportedServiceNames() throw( RuntimeException, std::exception )
125 Sequence< OUString > aRet { "com.sun.star.i18n.TextConversion" };
126 return aRet;
129 } } } }
131 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
132 com_sun_star_i18n_TextConversion_get_implementation(
133 css::uno::XComponentContext *context,
134 css::uno::Sequence<css::uno::Any> const &)
136 return cppu::acquire(new css::i18n::TextConversionImpl(context));
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */