xref: /trunk/main/linguistic/source/hyphdta.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
13b8558fdSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
33b8558fdSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
43b8558fdSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
53b8558fdSAndrew Rist  * distributed with this work for additional information
63b8558fdSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
73b8558fdSAndrew Rist  * to you under the Apache License, Version 2.0 (the
83b8558fdSAndrew Rist  * "License"); you may not use this file except in compliance
93b8558fdSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
113b8558fdSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
133b8558fdSAndrew Rist  * Unless required by applicable law or agreed to in writing,
143b8558fdSAndrew Rist  * software distributed under the License is distributed on an
153b8558fdSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
163b8558fdSAndrew Rist  * KIND, either express or implied.  See the License for the
173b8558fdSAndrew Rist  * specific language governing permissions and limitations
183b8558fdSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
203b8558fdSAndrew Rist  *************************************************************/
213b8558fdSAndrew Rist 
223b8558fdSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_linguistic.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "linguistic/hyphdta.hxx"
28cdf0e10cSrcweir #include "linguistic/lngprops.hxx"
29cdf0e10cSrcweir #include "linguistic/misc.hxx"
30cdf0e10cSrcweir #include <osl/mutex.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
34cdf0e10cSrcweir #include <tools/debug.hxx>
35cdf0e10cSrcweir #include <svl/lngmisc.hxx>
36cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //using namespace utl;
39cdf0e10cSrcweir using namespace osl;
40cdf0e10cSrcweir using namespace rtl;
41cdf0e10cSrcweir using namespace com::sun::star;
42cdf0e10cSrcweir //using namespace com::sun::star::beans;
43cdf0e10cSrcweir using namespace com::sun::star::lang;
44cdf0e10cSrcweir using namespace com::sun::star::uno;
45cdf0e10cSrcweir using namespace com::sun::star::linguistic2;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace linguistic
48cdf0e10cSrcweir {
49cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
HyphenatedWord(const OUString & rWord,sal_Int16 nLang,sal_Int16 nHPos,const OUString & rHyphWord,sal_Int16 nPos)52cdf0e10cSrcweir HyphenatedWord::HyphenatedWord(const OUString &rWord, sal_Int16 nLang, sal_Int16 nHPos,
53cdf0e10cSrcweir                                const OUString &rHyphWord, sal_Int16 nPos ) :
54cdf0e10cSrcweir     aWord           (rWord),
55cdf0e10cSrcweir     aHyphenatedWord (rHyphWord),
56cdf0e10cSrcweir     nHyphPos        (nPos),
57cdf0e10cSrcweir     nHyphenationPos (nHPos),
58cdf0e10cSrcweir     nLanguage       (nLang)
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     String aSingleQuote( GetLocaleDataWrapper( nLanguage ).getQuotationMarkEnd() );
61*2814ae3cSJohn Bampton     DBG_ASSERT( 1 == aSingleQuote.Len(), "unexpected length of quotation mark" );
62cdf0e10cSrcweir     if (aSingleQuote.Len())
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         // ignore typographical apostrophes (which got replaced in original
65cdf0e10cSrcweir         // word when being checked for hyphenation) in results.
66cdf0e10cSrcweir         OUString aTmpWord( rWord );
67cdf0e10cSrcweir         OUString aTmpHyphWord( rHyphWord );
68cdf0e10cSrcweir         aTmpWord        = aTmpWord    .replace( aSingleQuote.GetChar(0), '\'' );
69cdf0e10cSrcweir         aTmpHyphWord    = aTmpHyphWord.replace( aSingleQuote.GetChar(0), '\'' );
70cdf0e10cSrcweir         bIsAltSpelling  = aTmpWord != aTmpHyphWord;
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir     else
73cdf0e10cSrcweir         bIsAltSpelling = rWord != rHyphWord;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
~HyphenatedWord()77cdf0e10cSrcweir HyphenatedWord::~HyphenatedWord()
78cdf0e10cSrcweir {
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 
getWord()82cdf0e10cSrcweir OUString SAL_CALL HyphenatedWord::getWord()
83cdf0e10cSrcweir         throw(RuntimeException)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
86cdf0e10cSrcweir     return aWord;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
getLocale()90cdf0e10cSrcweir Locale SAL_CALL HyphenatedWord::getLocale()
91cdf0e10cSrcweir         throw(RuntimeException)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     Locale aRes;
96cdf0e10cSrcweir     return LanguageToLocale( aRes, nLanguage );
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 
getHyphenationPos()100cdf0e10cSrcweir sal_Int16 SAL_CALL HyphenatedWord::getHyphenationPos()
101cdf0e10cSrcweir         throw(RuntimeException)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
104cdf0e10cSrcweir     return nHyphenationPos;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 
getHyphenatedWord()108cdf0e10cSrcweir OUString SAL_CALL HyphenatedWord::getHyphenatedWord()
109cdf0e10cSrcweir         throw(RuntimeException)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
112cdf0e10cSrcweir     return aHyphenatedWord;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 
getHyphenPos()116cdf0e10cSrcweir sal_Int16 SAL_CALL HyphenatedWord::getHyphenPos()
117cdf0e10cSrcweir         throw(RuntimeException)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
120cdf0e10cSrcweir     return nHyphPos;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 
isAlternativeSpelling()124cdf0e10cSrcweir sal_Bool SAL_CALL HyphenatedWord::isAlternativeSpelling()
125cdf0e10cSrcweir         throw(RuntimeException)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
128cdf0e10cSrcweir     return bIsAltSpelling;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 
132cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
PossibleHyphens(const OUString & rWord,sal_Int16 nLang,const OUString & rHyphWord,const Sequence<sal_Int16> & rPositions)135cdf0e10cSrcweir PossibleHyphens::PossibleHyphens(const OUString &rWord, sal_Int16 nLang,
136cdf0e10cSrcweir             const OUString &rHyphWord,
137cdf0e10cSrcweir             const Sequence< sal_Int16 > &rPositions) :
138cdf0e10cSrcweir     aWord           (rWord),
139cdf0e10cSrcweir     aWordWithHyphens(rHyphWord),
140cdf0e10cSrcweir     aOrigHyphenPos  (rPositions),
141cdf0e10cSrcweir     nLanguage       (nLang)
142cdf0e10cSrcweir {
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
~PossibleHyphens()146cdf0e10cSrcweir PossibleHyphens::~PossibleHyphens()
147cdf0e10cSrcweir {
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 
getWord()151cdf0e10cSrcweir OUString SAL_CALL PossibleHyphens::getWord()
152cdf0e10cSrcweir         throw(RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
155cdf0e10cSrcweir     return aWord;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 
getLocale()159cdf0e10cSrcweir Locale SAL_CALL PossibleHyphens::getLocale()
160cdf0e10cSrcweir         throw(RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
163cdf0e10cSrcweir     return CreateLocale( nLanguage );
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 
getPossibleHyphens()167cdf0e10cSrcweir OUString SAL_CALL PossibleHyphens::getPossibleHyphens()
168cdf0e10cSrcweir         throw(RuntimeException)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
171cdf0e10cSrcweir     return aWordWithHyphens;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 
getHyphenationPositions()175cdf0e10cSrcweir Sequence< sal_Int16 > SAL_CALL PossibleHyphens::getHyphenationPositions()
176cdf0e10cSrcweir         throw(RuntimeException)
177cdf0e10cSrcweir {
178cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
179cdf0e10cSrcweir     return aOrigHyphenPos;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
CreateHyphenatedWord(const::rtl::OUString & rWord,sal_Int16 nLang,sal_Int16 nHyphenationPos,const::rtl::OUString & rHyphenatedWord,sal_Int16 nHyphenPos)182b63233d8Sdamjan com::sun::star::uno::Reference <com::sun::star::linguistic2::XHyphenatedWord> HyphenatedWord::CreateHyphenatedWord(
183b63233d8Sdamjan         const ::rtl::OUString &rWord, sal_Int16 nLang, sal_Int16 nHyphenationPos,
184b63233d8Sdamjan         const ::rtl::OUString &rHyphenatedWord, sal_Int16 nHyphenPos )
185b63233d8Sdamjan {
186b63233d8Sdamjan     return new HyphenatedWord( rWord, nLang, nHyphenationPos, rHyphenatedWord, nHyphenPos );
187b63233d8Sdamjan }
188b63233d8Sdamjan 
CreatePossibleHyphens(const::rtl::OUString & rWord,sal_Int16 nLang,const::rtl::OUString & rHyphWord,const::com::sun::star::uno::Sequence<sal_Int16> & rPositions)189b63233d8Sdamjan com::sun::star::uno::Reference < com::sun::star::linguistic2::XPossibleHyphens > PossibleHyphens::CreatePossibleHyphens
190b63233d8Sdamjan         (const ::rtl::OUString &rWord, sal_Int16 nLang,
191b63233d8Sdamjan          const ::rtl::OUString &rHyphWord,
192b63233d8Sdamjan          const ::com::sun::star::uno::Sequence< sal_Int16 > &rPositions)
193b63233d8Sdamjan {
194b63233d8Sdamjan     return new PossibleHyphens( rWord, nLang, rHyphWord, rPositions );
195b63233d8Sdamjan }
196b63233d8Sdamjan 
197b63233d8Sdamjan 
198cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
199cdf0e10cSrcweir 
200cdf0e10cSrcweir }   // namespace linguistic
201