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() throw(RuntimeException)
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 throw(RuntimeException)
50 {
51 aLocale = rLocale;
52 }
53
54
55 void SAL_CALL
loadModuleNew(const Sequence<TransliterationModulesNew> &,const Locale &)56 transliteration_commonclass::loadModuleNew( const Sequence < TransliterationModulesNew >& /*modName*/, const Locale& /*rLocale*/ )
57 throw(RuntimeException)
58 {
59 throw RuntimeException();
60 }
61
62
63 void SAL_CALL
loadModuleByImplName(const OUString &,const Locale &)64 transliteration_commonclass::loadModuleByImplName( const OUString& /*implName*/, const Locale& /*rLocale*/ )
65 throw(RuntimeException)
66 {
67 throw RuntimeException();
68 }
69
70 void SAL_CALL
loadModulesByImplNames(const Sequence<OUString> &,const Locale &)71 transliteration_commonclass::loadModulesByImplNames(const Sequence< OUString >& /*modNamelist*/, const Locale& /*rLocale*/)
72 throw(RuntimeException)
73 {
74 throw RuntimeException();
75 }
76
77 Sequence< OUString > SAL_CALL
getAvailableModules(const Locale &,sal_Int16)78 transliteration_commonclass::getAvailableModules( const Locale& /*rLocale*/, sal_Int16 /*sType*/ )
79 throw(RuntimeException)
80 {
81 throw RuntimeException();
82 }
83
84 sal_Int32 SAL_CALL
compareSubstring(const OUString & str1,sal_Int32 off1,sal_Int32 len1,const OUString & str2,sal_Int32 off2,sal_Int32 len2)85 transliteration_commonclass::compareSubstring(
86 const OUString& str1, sal_Int32 off1, sal_Int32 len1,
87 const OUString& str2, sal_Int32 off2, sal_Int32 len2)
88 throw(RuntimeException)
89 {
90 const sal_Unicode* unistr1 = NULL;
91 const sal_Unicode* unistr2 = NULL;
92 sal_uInt32 strlen1;
93 sal_uInt32 strlen2;
94
95 Sequence <sal_Int32> offset1(2*len1);
96 Sequence <sal_Int32> offset2(2*len2);
97
98 OUString in_str1 = this->transliterate(str1, off1, len1, offset1);
99 OUString in_str2 = this->transliterate(str2, off2, len2, offset2);
100 strlen1 = in_str1.getLength();
101 strlen2 = in_str2.getLength();
102 unistr1 = in_str1.getStr();
103 unistr2 = in_str2.getStr();
104
105 while (strlen1 && strlen2)
106 {
107 sal_uInt32 ret = *unistr1 - *unistr2;
108 if (ret)
109 return ret;
110
111 unistr1++;
112 unistr2++;
113 strlen1--;
114 strlen2--;
115 }
116 return strlen1 - strlen2;
117 }
118
119 sal_Int32 SAL_CALL
compareString(const OUString & str1,const OUString & str2)120 transliteration_commonclass::compareString( const OUString& str1, const OUString& str2 ) throw ( RuntimeException)
121 {
122 return( this->compareSubstring(str1, 0, str1.getLength(), str2, 0, str2.getLength()));
123 }
124
125 OUString SAL_CALL
transliterateString2String(const OUString & inStr,sal_Int32 startPos,sal_Int32 nCount)126 transliteration_commonclass::transliterateString2String( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount ) throw(RuntimeException)
127 {
128 static Sequence < sal_Int32 > dummy_offset;
129 useOffset = sal_False;
130 OUString tmpStr = transliterate(inStr, startPos, nCount, dummy_offset);
131 useOffset = sal_True;
132 return tmpStr;
133 }
134
135 OUString SAL_CALL
transliterateChar2String(sal_Unicode inChar)136 transliteration_commonclass::transliterateChar2String( sal_Unicode inChar ) throw(RuntimeException)
137 {
138 return transliteration_commonclass::transliterateString2String(OUString(&inChar, 1), 0, 1);
139 }
140
getImplementationName()141 OUString SAL_CALL transliteration_commonclass::getImplementationName() throw( RuntimeException )
142 {
143 return OUString::createFromAscii(implementationName);
144 }
145
146 const sal_Char cTrans[] = "com.sun.star.i18n.Transliteration.l10n";
147
supportsService(const OUString & rServiceName)148 sal_Bool SAL_CALL transliteration_commonclass::supportsService(const OUString& rServiceName) throw( RuntimeException )
149 {
150 return rServiceName.equalsAscii(cTrans);
151 }
152
getSupportedServiceNames()153 Sequence< OUString > SAL_CALL transliteration_commonclass::getSupportedServiceNames() throw( RuntimeException )
154 {
155 Sequence< OUString > aRet(1);
156 aRet[0] = OUString::createFromAscii(cTrans);
157 return aRet;
158 }
159
160 } } } }
161