1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_i18npool.hxx"
26
27 #include <transliteration_commonclass.hxx>
28 #include <com/sun/star/i18n/CollatorOptions.hpp>
29
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::lang;
32 using namespace ::rtl;
33
34 namespace com { namespace sun { namespace star { namespace i18n {
35
transliteration_commonclass()36 transliteration_commonclass::transliteration_commonclass()
37 {
38 transliterationName = "";
39 implementationName = "";
40 useOffset = sal_True;
41 }
42
getName()43 OUString SAL_CALL transliteration_commonclass::getName()
44 {
45 return OUString::createFromAscii(transliterationName);
46 }
47
loadModule(TransliterationModules,const Locale & rLocale)48 void SAL_CALL transliteration_commonclass::loadModule( TransliterationModules /*modName*/, const Locale& rLocale )
49 {
50 aLocale = rLocale;
51 }
52
53
54 void SAL_CALL
loadModuleNew(const Sequence<TransliterationModulesNew> &,const Locale &)55 transliteration_commonclass::loadModuleNew( const Sequence < TransliterationModulesNew >& /*modName*/, const Locale& /*rLocale*/ )
56 {
57 throw RuntimeException();
58 }
59
60
61 void SAL_CALL
loadModuleByImplName(const OUString &,const Locale &)62 transliteration_commonclass::loadModuleByImplName( const OUString& /*implName*/, const Locale& /*rLocale*/ )
63 {
64 throw RuntimeException();
65 }
66
67 void SAL_CALL
loadModulesByImplNames(const Sequence<OUString> &,const Locale &)68 transliteration_commonclass::loadModulesByImplNames(const Sequence< OUString >& /*modNamelist*/, const Locale& /*rLocale*/)
69 {
70 throw RuntimeException();
71 }
72
73 Sequence< OUString > SAL_CALL
getAvailableModules(const Locale &,sal_Int16)74 transliteration_commonclass::getAvailableModules( const Locale& /*rLocale*/, sal_Int16 /*sType*/ )
75 {
76 throw RuntimeException();
77 }
78
79 sal_Int32 SAL_CALL
compareSubstring(const OUString & str1,sal_Int32 off1,sal_Int32 len1,const OUString & str2,sal_Int32 off2,sal_Int32 len2)80 transliteration_commonclass::compareSubstring(
81 const OUString& str1, sal_Int32 off1, sal_Int32 len1,
82 const OUString& str2, sal_Int32 off2, sal_Int32 len2)
83 {
84 const sal_Unicode* unistr1 = NULL;
85 const sal_Unicode* unistr2 = NULL;
86 sal_uInt32 strlen1;
87 sal_uInt32 strlen2;
88
89 Sequence <sal_Int32> offset1(2*len1);
90 Sequence <sal_Int32> offset2(2*len2);
91
92 OUString in_str1 = this->transliterate(str1, off1, len1, offset1);
93 OUString in_str2 = this->transliterate(str2, off2, len2, offset2);
94 strlen1 = in_str1.getLength();
95 strlen2 = in_str2.getLength();
96 unistr1 = in_str1.getStr();
97 unistr2 = in_str2.getStr();
98
99 while (strlen1 && strlen2)
100 {
101 sal_uInt32 ret = *unistr1 - *unistr2;
102 if (ret)
103 return ret;
104
105 unistr1++;
106 unistr2++;
107 strlen1--;
108 strlen2--;
109 }
110 return strlen1 - strlen2;
111 }
112
113 sal_Int32 SAL_CALL
compareString(const OUString & str1,const OUString & str2)114 transliteration_commonclass::compareString( const OUString& str1, const OUString& str2 )
115 {
116 return( this->compareSubstring(str1, 0, str1.getLength(), str2, 0, str2.getLength()));
117 }
118
119 OUString SAL_CALL
transliterateString2String(const OUString & inStr,sal_Int32 startPos,sal_Int32 nCount)120 transliteration_commonclass::transliterateString2String( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount )
121 {
122 static Sequence < sal_Int32 > dummy_offset;
123 useOffset = sal_False;
124 OUString tmpStr = transliterate(inStr, startPos, nCount, dummy_offset);
125 useOffset = sal_True;
126 return tmpStr;
127 }
128
129 OUString SAL_CALL
transliterateChar2String(sal_Unicode inChar)130 transliteration_commonclass::transliterateChar2String( sal_Unicode inChar )
131 {
132 return transliteration_commonclass::transliterateString2String(OUString(&inChar, 1), 0, 1);
133 }
134
getImplementationName()135 OUString SAL_CALL transliteration_commonclass::getImplementationName()
136 {
137 return OUString::createFromAscii(implementationName);
138 }
139
140 const sal_Char cTrans[] = "com.sun.star.i18n.Transliteration.l10n";
141
supportsService(const OUString & rServiceName)142 sal_Bool SAL_CALL transliteration_commonclass::supportsService(const OUString& rServiceName)
143 {
144 return rServiceName.equalsAscii(cTrans);
145 }
146
getSupportedServiceNames()147 Sequence< OUString > SAL_CALL transliteration_commonclass::getSupportedServiceNames()
148 {
149 Sequence< OUString > aRet(1);
150 aRet[0] = OUString::createFromAscii(cTrans);
151 return aRet;
152 }
153
154 } } } }
155