1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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
;
30 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
32 TextConversionResult SAL_CALL
33 TextConversionImpl::getConversions( const OUString
& aText
, sal_Int32 nStartPos
, sal_Int32 nLength
,
34 const Locale
& rLocale
, sal_Int16 nConversionType
, sal_Int32 nConversionOptions
)
35 throw( RuntimeException
, IllegalArgumentException
, NoSupportException
)
37 getLocaleSpecificTextConversion(rLocale
);
39 sal_Int32 len
= aText
.getLength() - nStartPos
;
41 nLength
= len
> 0 ? len
: 0;
42 return xTC
->getConversions(aText
, nStartPos
, nLength
, rLocale
, nConversionType
, nConversionOptions
);
46 TextConversionImpl::getConversion( const OUString
& aText
, sal_Int32 nStartPos
, sal_Int32 nLength
,
47 const Locale
& rLocale
, sal_Int16 nConversionType
, sal_Int32 nConversionOptions
)
48 throw( RuntimeException
, IllegalArgumentException
, NoSupportException
)
50 getLocaleSpecificTextConversion(rLocale
);
52 sal_Int32 len
= aText
.getLength() - nStartPos
;
54 nLength
= len
> 0 ? len
: 0;
55 return xTC
->getConversion(aText
, nStartPos
, nLength
, rLocale
, nConversionType
, nConversionOptions
);
59 TextConversionImpl::getConversionWithOffset( const OUString
& aText
, sal_Int32 nStartPos
, sal_Int32 nLength
,
60 const Locale
& rLocale
, sal_Int16 nConversionType
, sal_Int32 nConversionOptions
, Sequence
< sal_Int32
>& offset
)
61 throw( RuntimeException
, IllegalArgumentException
, NoSupportException
)
63 getLocaleSpecificTextConversion(rLocale
);
65 sal_Int32 len
= aText
.getLength() - nStartPos
;
67 nLength
= len
> 0 ? len
: 0;
68 return xTC
->getConversionWithOffset(aText
, nStartPos
, nLength
, rLocale
, nConversionType
, nConversionOptions
, offset
);
72 TextConversionImpl::interactiveConversion( const Locale
& rLocale
, sal_Int16 nTextConversionType
, sal_Int32 nTextConversionOptions
)
73 throw( RuntimeException
, IllegalArgumentException
, NoSupportException
)
75 getLocaleSpecificTextConversion(rLocale
);
77 return xTC
->interactiveConversion(rLocale
, nTextConversionType
, nTextConversionOptions
);
80 static inline sal_Bool
operator != (const Locale
& l1
, const Locale
& l2
) {
81 return l1
.Language
!= l2
.Language
|| l1
.Country
!= l2
.Country
|| l1
.Variant
!= l2
.Variant
;
85 TextConversionImpl::getLocaleSpecificTextConversion(const Locale
& rLocale
) throw( NoSupportException
)
87 if (rLocale
!= aLocale
) {
90 OUString
aPrefix("com.sun.star.i18n.TextConversion_");
91 Reference
< XInterface
> xI
;
93 xI
= m_xContext
->getServiceManager()->createInstanceWithContext(
94 aPrefix
+ LocaleDataImpl::getFirstLocaleServiceName( aLocale
), m_xContext
);
97 ::std::vector
< OUString
> aFallbacks( LocaleDataImpl::getFallbackLocaleServiceNames( aLocale
));
98 for (::std::vector
< OUString
>::const_iterator
it( aFallbacks
.begin()); it
!= aFallbacks
.end(); ++it
)
100 xI
= m_xContext
->getServiceManager()->createInstanceWithContext( aPrefix
+ *it
, m_xContext
);
106 xTC
.set( xI
, UNO_QUERY
);
111 throw NoSupportException(); // aLocale is not supported
114 const sal_Char cTextConversion
[] = "com.sun.star.i18n.TextConversion";
117 TextConversionImpl::getImplementationName() throw( RuntimeException
)
119 return OUString::createFromAscii(cTextConversion
);
123 TextConversionImpl::supportsService(const OUString
& rServiceName
)
124 throw( RuntimeException
)
126 return rServiceName
.equalsAscii(cTextConversion
);
129 Sequence
< OUString
> SAL_CALL
130 TextConversionImpl::getSupportedServiceNames() throw( RuntimeException
)
132 Sequence
< OUString
> aRet(1);
133 aRet
[0] = OUString::createFromAscii(cTextConversion
);
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */