LibreOffice Module i18npool (master) 1
textconversionImpl.cxx
Go to the documentation of this file.
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 <com/sun/star/lang/NoSupportException.hpp>
21#include <com/sun/star/uno/XComponentContext.hpp>
24#include <localedata.hxx>
25
26using namespace com::sun::star::lang;
27using namespace ::com::sun::star::i18n;
28using namespace com::sun::star::uno;
29
30namespace i18npool {
31
32TextConversionResult SAL_CALL
33TextConversionImpl::getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
34 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
35{
37
38 sal_Int32 len = aText.getLength() - nStartPos;
39 if (nLength > len)
40 nLength = std::max<sal_Int32>(len, 0);
41 return xTC->getConversions(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
42}
43
44OUString SAL_CALL
45TextConversionImpl::getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
46 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
47{
49
50 sal_Int32 len = aText.getLength() - nStartPos;
51 if (nLength > len)
52 nLength = std::max<sal_Int32>(len, 0);
53 return xTC->getConversion(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
54}
55
56OUString SAL_CALL
57TextConversionImpl::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{
61
62 sal_Int32 len = aText.getLength() - nStartPos;
63 if (nLength > len)
64 nLength = std::max<sal_Int32>(len, 0);
65 return xTC->getConversionWithOffset(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions, offset);
66}
67
68sal_Bool SAL_CALL
69TextConversionImpl::interactiveConversion( const Locale& rLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions )
70{
72
73 return xTC->interactiveConversion(rLocale, nTextConversionType, nTextConversionOptions);
74}
75
76void
78{
79 if (rLocale != aLocale) {
80 aLocale = rLocale;
81
82 OUString aPrefix("com.sun.star.i18n.TextConversion_");
83 Reference < XInterface > xI = m_xContext->getServiceManager()->createInstanceWithContext(
85 if (!xI.is())
86 {
87 ::std::vector< OUString > aFallbacks( LocaleDataImpl::getFallbackLocaleServiceNames( aLocale));
88 for (auto const& fallback : aFallbacks)
89 {
90 xI = m_xContext->getServiceManager()->createInstanceWithContext( aPrefix + fallback, m_xContext);
91 if (xI.is())
92 break;
93 }
94 }
95 if (xI.is())
96 xTC.set( xI, UNO_QUERY );
97 else if (xTC.is())
98 xTC.clear();
99 }
100 if (! xTC.is())
101 throw NoSupportException(); // aLocale is not supported
102}
103
104OUString SAL_CALL
106{
107 return "com.sun.star.i18n.TextConversion";
108}
109
110sal_Bool SAL_CALL
111TextConversionImpl::supportsService(const OUString& rServiceName)
112{
113 return cppu::supportsService(this, rServiceName);
114}
115
118{
119 return { "com.sun.star.i18n.TextConversion" };
120}
121
122}
123
124extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
126 css::uno::XComponentContext *context,
127 css::uno::Sequence<css::uno::Any> const &)
128{
129 return cppu::acquire(new i18npool::TextConversionImpl(context));
130}
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static ::std::vector< OUString > getFallbackLocaleServiceNames(const css::lang::Locale &rLocale)
Generates fallback strings suitable as parts of service names, excluding the one obtained via getFirs...
static OUString getFirstLocaleServiceName(const css::lang::Locale &rLocale)
Generates a <Language>_<Country> or <Variant> (if Language=="qlt") string suitable as part of service...
sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
css::i18n::TextConversionResult SAL_CALL getConversions(const OUString &aText, sal_Int32 nStartPos, sal_Int32 nLength, const css::lang::Locale &aLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions) override
void getLocaleSpecificTextConversion(const css::lang::Locale &rLocale)
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
OUString SAL_CALL getImplementationName() override
OUString SAL_CALL getConversion(const OUString &aText, sal_Int32 nStartPos, sal_Int32 nLength, const css::lang::Locale &aLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions) override
css::uno::Reference< css::i18n::XExtendedTextConversion > xTC
sal_Bool SAL_CALL interactiveConversion(const css::lang::Locale &aLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions) override
OUString SAL_CALL getConversionWithOffset(const OUString &aText, sal_Int32 nStartPos, sal_Int32 nLength, const css::lang::Locale &aLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions, css::uno::Sequence< sal_Int32 > &offset) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Constant values shared between i18npool and, for example, the number formatter.
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_i18n_TextConversion_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
unsigned char sal_Bool
sal_Int32 nLength