bump product version to 4.1.6.2
[LibreOffice.git] / i18npool / source / textconversion / textconversionImpl.cxx
blob2c3a0c9a8cca24bca96e6e703e6bbd72b6b261e3
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 .
21 #include <assert.h>
22 #include <textconversionImpl.hxx>
24 using namespace com::sun::star::lang;
25 using namespace com::sun::star::uno;
28 namespace com { namespace sun { namespace star { namespace i18n {
30 TextConversionResult SAL_CALL
31 TextConversionImpl::getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
32 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
33 throw( RuntimeException, IllegalArgumentException, NoSupportException )
35 getLocaleSpecificTextConversion(rLocale);
37 sal_Int32 len = aText.getLength() - nStartPos;
38 if (nLength > len)
39 nLength = len > 0 ? len : 0;
40 return xTC->getConversions(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
43 OUString SAL_CALL
44 TextConversionImpl::getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
45 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
46 throw( RuntimeException, IllegalArgumentException, NoSupportException )
48 getLocaleSpecificTextConversion(rLocale);
50 sal_Int32 len = aText.getLength() - nStartPos;
51 if (nLength > len)
52 nLength = len > 0 ? len : 0;
53 return xTC->getConversion(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
56 OUString SAL_CALL
57 TextConversionImpl::getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
58 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions, Sequence< sal_Int32>& offset)
59 throw( RuntimeException, IllegalArgumentException, NoSupportException )
61 getLocaleSpecificTextConversion(rLocale);
63 sal_Int32 len = aText.getLength() - nStartPos;
64 if (nLength > len)
65 nLength = len > 0 ? len : 0;
66 return xTC->getConversionWithOffset(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions, offset);
69 sal_Bool SAL_CALL
70 TextConversionImpl::interactiveConversion( const Locale& rLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions )
71 throw( RuntimeException, IllegalArgumentException, NoSupportException )
73 getLocaleSpecificTextConversion(rLocale);
75 return xTC->interactiveConversion(rLocale, nTextConversionType, nTextConversionOptions);
78 static inline sal_Bool operator != (const Locale& l1, const Locale& l2) {
79 return l1.Language != l2.Language || l1.Country != l2.Country || l1.Variant != l2.Variant;
82 void SAL_CALL
83 TextConversionImpl::getLocaleSpecificTextConversion(const Locale& rLocale) throw( NoSupportException )
85 if (rLocale != aLocale) {
86 aLocale = rLocale;
88 Reference < XInterface > xI;
90 xI = m_xContext->getServiceManager()->createInstanceWithContext(
91 OUString("com.sun.star.i18n.TextConversion_") + aLocale.Language, m_xContext);
93 if ( ! xI.is() )
94 xI = m_xContext->getServiceManager()->createInstanceWithContext(
95 OUString("com.sun.star.i18n.TextConversion_") + aLocale.Language +
96 OUString("_") + aLocale.Country, m_xContext);
97 if ( ! xI.is() )
98 xI = m_xContext->getServiceManager()->createInstanceWithContext(
99 OUString("com.sun.star.i18n.TextConversion_") + aLocale.Language +
100 OUString("_") + aLocale.Country +
101 OUString("_") + aLocale.Variant, m_xContext);
103 if (xI.is())
104 xTC.set( xI, UNO_QUERY );
105 else if (xTC.is())
106 xTC.clear();
108 if (! xTC.is())
109 throw NoSupportException(); // aLocale is not supported
112 const sal_Char cTextConversion[] = "com.sun.star.i18n.TextConversion";
114 OUString SAL_CALL
115 TextConversionImpl::getImplementationName() throw( RuntimeException )
117 return OUString::createFromAscii(cTextConversion);
120 sal_Bool SAL_CALL
121 TextConversionImpl::supportsService(const OUString& rServiceName)
122 throw( RuntimeException )
124 return rServiceName.equalsAscii(cTextConversion);
127 Sequence< OUString > SAL_CALL
128 TextConversionImpl::getSupportedServiceNames() throw( RuntimeException )
130 Sequence< OUString > aRet(1);
131 aRet[0] = OUString::createFromAscii(cTextConversion);
132 return aRet;
135 } } } }
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */