Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / i18npool / source / textconversion / textconversionImpl.cxx
blob213c70217a415daa0ebb406c7bc783855ff5eb46
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;
27 using ::rtl::OUString;
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 )
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 )
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 )
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 )
74 getLocaleSpecificTextConversion(rLocale);
76 return xTC->interactiveConversion(rLocale, nTextConversionType, nTextConversionOptions);
79 static inline sal_Bool operator != (const Locale& l1, const Locale& l2) {
80 return l1.Language != l2.Language || l1.Country != l2.Country || l1.Variant != l2.Variant;
83 void SAL_CALL
84 TextConversionImpl::getLocaleSpecificTextConversion(const Locale& rLocale) throw( NoSupportException )
86 if (xMSF.is() && rLocale != aLocale) {
87 aLocale = rLocale;
89 Reference < XInterface > xI;
91 xI = xMSF->createInstance(
92 OUString("com.sun.star.i18n.TextConversion_") + aLocale.Language);
94 if ( ! xI.is() )
95 xI = xMSF->createInstance(
96 OUString("com.sun.star.i18n.TextConversion_") + aLocale.Language +
97 OUString("_") + aLocale.Country);
98 if ( ! xI.is() )
99 xI = xMSF->createInstance(
100 OUString("com.sun.star.i18n.TextConversion_") + aLocale.Language +
101 OUString("_") + aLocale.Country +
102 OUString("_") + aLocale.Variant);
104 if (xI.is())
105 xI->queryInterface( getCppuType((const Reference< XTextConversion>*)0) ) >>= xTC;
106 else if (xTC.is())
107 xTC.clear();
109 if (! xTC.is())
110 throw NoSupportException(); // aLocale is not supported
113 const sal_Char cTextConversion[] = "com.sun.star.i18n.TextConversion";
115 OUString SAL_CALL
116 TextConversionImpl::getImplementationName() throw( RuntimeException )
118 return OUString::createFromAscii(cTextConversion);
121 sal_Bool SAL_CALL
122 TextConversionImpl::supportsService(const OUString& rServiceName)
123 throw( RuntimeException )
125 return rServiceName.equalsAscii(cTextConversion);
128 Sequence< OUString > SAL_CALL
129 TextConversionImpl::getSupportedServiceNames() throw( RuntimeException )
131 Sequence< OUString > aRet(1);
132 aRet[0] = OUString::createFromAscii(cTextConversion);
133 return aRet;
136 } } } }
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */