xref: /trunk/main/linguistic/source/hyphdta.cxx (revision b63233d8)
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_linguistic.hxx"
26 
27 #include "linguistic/hyphdta.hxx"
28 #include "linguistic/lngprops.hxx"
29 #include "linguistic/misc.hxx"
30 #include <osl/mutex.hxx>
31 
32 
33 #include <rtl/ustrbuf.hxx>
34 #include <tools/debug.hxx>
35 #include <svl/lngmisc.hxx>
36 #include <unotools/localedatawrapper.hxx>
37 
38 //using namespace utl;
39 using namespace osl;
40 using namespace rtl;
41 using namespace com::sun::star;
42 //using namespace com::sun::star::beans;
43 using namespace com::sun::star::lang;
44 using namespace com::sun::star::uno;
45 using namespace com::sun::star::linguistic2;
46 
47 namespace linguistic
48 {
49 ///////////////////////////////////////////////////////////////////////////
50 
51 
HyphenatedWord(const OUString & rWord,sal_Int16 nLang,sal_Int16 nHPos,const OUString & rHyphWord,sal_Int16 nPos)52 HyphenatedWord::HyphenatedWord(const OUString &rWord, sal_Int16 nLang, sal_Int16 nHPos,
53 							   const OUString &rHyphWord, sal_Int16 nPos ) :
54 	aWord			(rWord),
55     aHyphenatedWord (rHyphWord),
56     nHyphPos        (nPos),
57     nHyphenationPos (nHPos),
58     nLanguage       (nLang)
59 {
60     String aSingleQuote( GetLocaleDataWrapper( nLanguage ).getQuotationMarkEnd() );
61     DBG_ASSERT( 1 == aSingleQuote.Len(), "unexpectend length of quotation mark" );
62     if (aSingleQuote.Len())
63     {
64         // ignore typographical apostrophes (which got replaced in original
65         // word when being checked for hyphenation) in results.
66         OUString aTmpWord( rWord );
67         OUString aTmpHyphWord( rHyphWord );
68         aTmpWord        = aTmpWord    .replace( aSingleQuote.GetChar(0), '\'' );
69         aTmpHyphWord    = aTmpHyphWord.replace( aSingleQuote.GetChar(0), '\'' );
70         bIsAltSpelling  = aTmpWord != aTmpHyphWord;
71     }
72     else
73         bIsAltSpelling = rWord != rHyphWord;
74 }
75 
76 
~HyphenatedWord()77 HyphenatedWord::~HyphenatedWord()
78 {
79 }
80 
81 
getWord()82 OUString SAL_CALL HyphenatedWord::getWord()
83 		throw(RuntimeException)
84 {
85 	MutexGuard	aGuard( GetLinguMutex() );
86 	return aWord;
87 }
88 
89 
getLocale()90 Locale SAL_CALL HyphenatedWord::getLocale()
91 		throw(RuntimeException)
92 {
93 	MutexGuard	aGuard( GetLinguMutex() );
94 
95 	Locale aRes;
96 	return LanguageToLocale( aRes, nLanguage );
97 }
98 
99 
getHyphenationPos()100 sal_Int16 SAL_CALL HyphenatedWord::getHyphenationPos()
101 		throw(RuntimeException)
102 {
103 	MutexGuard	aGuard( GetLinguMutex() );
104 	return nHyphenationPos;
105 }
106 
107 
getHyphenatedWord()108 OUString SAL_CALL HyphenatedWord::getHyphenatedWord()
109 		throw(RuntimeException)
110 {
111 	MutexGuard	aGuard( GetLinguMutex() );
112 	return aHyphenatedWord;
113 }
114 
115 
getHyphenPos()116 sal_Int16 SAL_CALL HyphenatedWord::getHyphenPos()
117 		throw(RuntimeException)
118 {
119 	MutexGuard	aGuard( GetLinguMutex() );
120 	return nHyphPos;
121 }
122 
123 
isAlternativeSpelling()124 sal_Bool SAL_CALL HyphenatedWord::isAlternativeSpelling()
125 		throw(RuntimeException)
126 {
127 	MutexGuard	aGuard( GetLinguMutex() );
128 	return bIsAltSpelling;
129 }
130 
131 
132 ///////////////////////////////////////////////////////////////////////////
133 
134 
PossibleHyphens(const OUString & rWord,sal_Int16 nLang,const OUString & rHyphWord,const Sequence<sal_Int16> & rPositions)135 PossibleHyphens::PossibleHyphens(const OUString &rWord, sal_Int16 nLang,
136 			const OUString &rHyphWord,
137 			const Sequence< sal_Int16 > &rPositions) :
138 	aWord			(rWord),
139 	aWordWithHyphens(rHyphWord),
140 	aOrigHyphenPos	(rPositions),
141 	nLanguage		(nLang)
142 {
143 }
144 
145 
~PossibleHyphens()146 PossibleHyphens::~PossibleHyphens()
147 {
148 }
149 
150 
getWord()151 OUString SAL_CALL PossibleHyphens::getWord()
152 		throw(RuntimeException)
153 {
154 	MutexGuard	aGuard( GetLinguMutex() );
155 	return aWord;
156 }
157 
158 
getLocale()159 Locale SAL_CALL PossibleHyphens::getLocale()
160 		throw(RuntimeException)
161 {
162 	MutexGuard	aGuard( GetLinguMutex() );
163 	return CreateLocale( nLanguage );
164 }
165 
166 
getPossibleHyphens()167 OUString SAL_CALL PossibleHyphens::getPossibleHyphens()
168 		throw(RuntimeException)
169 {
170 	MutexGuard	aGuard( GetLinguMutex() );
171 	return aWordWithHyphens;
172 }
173 
174 
getHyphenationPositions()175 Sequence< sal_Int16 > SAL_CALL PossibleHyphens::getHyphenationPositions()
176 		throw(RuntimeException)
177 {
178 	MutexGuard	aGuard( GetLinguMutex() );
179 	return aOrigHyphenPos;
180 }
181 
CreateHyphenatedWord(const::rtl::OUString & rWord,sal_Int16 nLang,sal_Int16 nHyphenationPos,const::rtl::OUString & rHyphenatedWord,sal_Int16 nHyphenPos)182 com::sun::star::uno::Reference <com::sun::star::linguistic2::XHyphenatedWord> HyphenatedWord::CreateHyphenatedWord(
183 		const ::rtl::OUString &rWord, sal_Int16 nLang, sal_Int16 nHyphenationPos,
184 		const ::rtl::OUString &rHyphenatedWord, sal_Int16 nHyphenPos )
185 {
186 	return new HyphenatedWord( rWord, nLang, nHyphenationPos, rHyphenatedWord, nHyphenPos );
187 }
188 
CreatePossibleHyphens(const::rtl::OUString & rWord,sal_Int16 nLang,const::rtl::OUString & rHyphWord,const::com::sun::star::uno::Sequence<sal_Int16> & rPositions)189 com::sun::star::uno::Reference < com::sun::star::linguistic2::XPossibleHyphens > PossibleHyphens::CreatePossibleHyphens
190 		(const ::rtl::OUString &rWord, sal_Int16 nLang,
191 		 const ::rtl::OUString &rHyphWord,
192 		 const ::com::sun::star::uno::Sequence< sal_Int16 > &rPositions)
193 {
194 	return new PossibleHyphens( rWord, nLang, rHyphWord, rPositions );
195 }
196 
197 
198 ///////////////////////////////////////////////////////////////////////////
199 
200 }	// namespace linguistic
201 
202