1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hyphdta.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_linguistic.hxx"
34 #include "hyphdta.hxx"
35 #include "lngprops.hxx"
37 #include <osl/mutex.hxx>
40 #include <rtl/ustrbuf.hxx>
41 #include <tools/debug.hxx>
42 #include <svtools/lngmisc.hxx>
43 #include <unotools/localedatawrapper.hxx>
45 //using namespace utl;
48 using namespace com::sun::star
;
49 //using namespace com::sun::star::beans;
50 using namespace com::sun::star::lang
;
51 using namespace com::sun::star::uno
;
52 using namespace com::sun::star::linguistic2
;
56 ///////////////////////////////////////////////////////////////////////////
59 HyphenatedWord::HyphenatedWord(const OUString
&rWord
, INT16 nLang
, INT16 nHPos
,
60 const OUString
&rHyphWord
, INT16 nPos
) :
62 aHyphenatedWord (rHyphWord
),
64 nHyphenationPos (nHPos
),
67 String
aSingleQuote( GetLocaleDataWrapper( nLanguage
).getQuotationMarkEnd() );
68 DBG_ASSERT( 1 == aSingleQuote
.Len(), "unexpectend length of quotation mark" );
69 if (aSingleQuote
.Len())
71 // ignore typographical apostrophes (which got replaced in original
72 // word when being checked for hyphenation) in results.
73 OUString
aTmpWord( rWord
);
74 OUString
aTmpHyphWord( rHyphWord
);
75 aTmpWord
= aTmpWord
.replace( aSingleQuote
.GetChar(0), '\'' );
76 aTmpHyphWord
= aTmpHyphWord
.replace( aSingleQuote
.GetChar(0), '\'' );
77 bIsAltSpelling
= aTmpWord
!= aTmpHyphWord
;
80 bIsAltSpelling
= rWord
!= rHyphWord
;
84 HyphenatedWord::~HyphenatedWord()
89 OUString SAL_CALL
HyphenatedWord::getWord()
90 throw(RuntimeException
)
92 MutexGuard
aGuard( GetLinguMutex() );
97 Locale SAL_CALL
HyphenatedWord::getLocale()
98 throw(RuntimeException
)
100 MutexGuard
aGuard( GetLinguMutex() );
103 return LanguageToLocale( aRes
, nLanguage
);
107 sal_Int16 SAL_CALL
HyphenatedWord::getHyphenationPos()
108 throw(RuntimeException
)
110 MutexGuard
aGuard( GetLinguMutex() );
111 return nHyphenationPos
;
115 OUString SAL_CALL
HyphenatedWord::getHyphenatedWord()
116 throw(RuntimeException
)
118 MutexGuard
aGuard( GetLinguMutex() );
119 return aHyphenatedWord
;
123 sal_Int16 SAL_CALL
HyphenatedWord::getHyphenPos()
124 throw(RuntimeException
)
126 MutexGuard
aGuard( GetLinguMutex() );
131 sal_Bool SAL_CALL
HyphenatedWord::isAlternativeSpelling()
132 throw(RuntimeException
)
134 MutexGuard
aGuard( GetLinguMutex() );
135 return bIsAltSpelling
;
139 ///////////////////////////////////////////////////////////////////////////
142 PossibleHyphens::PossibleHyphens(const OUString
&rWord
, INT16 nLang
,
143 const OUString
&rHyphWord
,
144 const Sequence
< INT16
> &rPositions
) :
146 aWordWithHyphens(rHyphWord
),
147 aOrigHyphenPos (rPositions
),
153 PossibleHyphens::~PossibleHyphens()
158 OUString SAL_CALL
PossibleHyphens::getWord()
159 throw(RuntimeException
)
161 MutexGuard
aGuard( GetLinguMutex() );
166 Locale SAL_CALL
PossibleHyphens::getLocale()
167 throw(RuntimeException
)
169 MutexGuard
aGuard( GetLinguMutex() );
170 return CreateLocale( nLanguage
);
174 OUString SAL_CALL
PossibleHyphens::getPossibleHyphens()
175 throw(RuntimeException
)
177 MutexGuard
aGuard( GetLinguMutex() );
178 return aWordWithHyphens
;
182 Sequence
< sal_Int16
> SAL_CALL
PossibleHyphens::getHyphenationPositions()
183 throw(RuntimeException
)
185 MutexGuard
aGuard( GetLinguMutex() );
186 return aOrigHyphenPos
;
189 ///////////////////////////////////////////////////////////////////////////
191 } // namespace linguistic