Avoid potential negative array index access to cached text.
[LibreOffice.git] / i18npool / inc / textconversion.hxx
blobebb973de0b3aefc5d2877c126f9146cd27840eb9
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 .
19 #pragma once
21 #include <com/sun/star/lang/XServiceInfo.hpp>
22 #include <com/sun/star/i18n/XExtendedTextConversion.hpp>
23 #include <cppuhelper/implbase.hxx>
24 #include <osl/module.h>
26 namespace com::sun::star::linguistic2 { class XConversionDictionary; }
27 namespace com::sun::star::linguistic2 { class XConversionDictionaryList; }
28 namespace com::sun::star::uno { class XComponentContext; }
30 namespace i18npool {
34 class TextConversionService: public cppu::WeakImplHelper
36 css::i18n::XExtendedTextConversion,
37 css::lang::XServiceInfo
40 public:
41 TextConversionService(const char* pImplName);
42 virtual ~TextConversionService() override;
43 // Methods
44 virtual css::i18n::TextConversionResult SAL_CALL
45 getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
46 const css::lang::Locale& aLocale, sal_Int16 nTextConversionType,
47 sal_Int32 nTextConversionOptions ) override = 0;
48 virtual OUString SAL_CALL
49 getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
50 const css::lang::Locale& aLocale, sal_Int16 nTextConversionType,
51 sal_Int32 nTextConversionOptions ) override = 0;
52 virtual OUString SAL_CALL
53 getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
54 const css::lang::Locale& aLocale, sal_Int16 nTextConversionType,
55 sal_Int32 nTextConversionOptions, css::uno::Sequence< sal_Int32 >& offset ) override = 0;
56 virtual sal_Bool SAL_CALL
57 interactiveConversion(const css::lang::Locale& aLocale,
58 sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions ) override = 0;
60 //XServiceInfo
61 OUString SAL_CALL
62 getImplementationName() override;
63 sal_Bool SAL_CALL
64 supportsService(const OUString& ServiceName) override;
65 css::uno::Sequence< OUString > SAL_CALL
66 getSupportedServiceNames() override;
67 private:
68 const char* implementationName;
69 protected:
70 #ifndef DISABLE_DYNLOADING
71 oslModule hModule;
72 oslGenericFunction getFunctionBySymbol(const char* func);
73 #endif
76 // for Hangul2Hanja conversion
77 typedef struct {
78 sal_Unicode code;
79 sal_Int16 address;
80 sal_Int16 count;
81 } Hangul_Index;
85 class TextConversion_ko final : public TextConversionService
87 public:
88 TextConversion_ko( const css::uno::Reference < css::uno::XComponentContext >& rxContext );
90 // Methods
91 css::i18n::TextConversionResult SAL_CALL
92 getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
93 const css::lang::Locale& aLocale, sal_Int16 nTextConversionType,
94 sal_Int32 nTextConversionOptions ) override;
95 OUString SAL_CALL
96 getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
97 const css::lang::Locale& aLocale, sal_Int16 nTextConversionType,
98 sal_Int32 nTextConversionOptions ) override;
99 OUString SAL_CALL
100 getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
101 const css::lang::Locale& aLocale, sal_Int16 nTextConversionType,
102 sal_Int32 nTextConversionOptions, css::uno::Sequence< sal_Int32 >& offset ) override;
103 sal_Bool SAL_CALL
104 interactiveConversion(const css::lang::Locale& aLocale,
105 sal_Int16 nTextConversionType,
106 sal_Int32 nTextConversionOptions ) override;
108 private:
109 // Hangul/Hanja system dictionary
110 css::uno::Reference < css::linguistic2::XConversionDictionary > xCD;
111 // Hangul/Hanja user defined dictionary list
112 css::uno::Reference < css::linguistic2::XConversionDictionaryList > xCDL;
113 sal_Int32 maxLeftLength;
114 sal_Int32 maxRightLength;
115 css::uno::Sequence< OUString >
116 getCharConversions(const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toHanja);
122 class TextConversion_zh final : public TextConversionService
124 public:
125 TextConversion_zh( const css::uno::Reference < css::uno::XComponentContext >& rxContext );
127 // Methods
128 css::i18n::TextConversionResult SAL_CALL
129 getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
130 const css::lang::Locale& aLocale, sal_Int16 nTextConversionType,
131 sal_Int32 nTextConversionOptions ) override;
132 OUString SAL_CALL
133 getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
134 const css::lang::Locale& aLocale, sal_Int16 nTextConversionType,
135 sal_Int32 nTextConversionOptions ) override;
136 OUString SAL_CALL
137 getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
138 const css::lang::Locale& aLocale, sal_Int16 nTextConversionType,
139 sal_Int32 nTextConversionOptions, css::uno::Sequence< sal_Int32 >& offset ) override;
140 sal_Bool SAL_CALL
141 interactiveConversion(const css::lang::Locale& aLocale,
142 sal_Int16 nTextConversionType,
143 sal_Int32 nTextConversionOptions ) override;
144 private:
145 // user defined dictionary list
146 css::uno::Reference < css::linguistic2::XConversionDictionaryList > xCDL;
147 OUString getWordConversion(const OUString& aText,
148 sal_Int32 nStartPos, sal_Int32 nLength, bool toSChinese, sal_Int32 nConversionOptions, css::uno::Sequence <sal_Int32>& offset);
149 rtl:: OUString getCharConversion(const rtl:: OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toSChinese, sal_Int32 nConversionOptions);
150 css::lang::Locale aLocale;
153 } // i18npool
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */