1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <linguistic/hyphdta.hxx>
22 #include <linguistic/misc.hxx>
23 #include <osl/mutex.hxx>
26 #include <tools/debug.hxx>
27 #include <unotools/localedatawrapper.hxx>
30 using namespace com::sun::star
;
31 using namespace com::sun::star::lang
;
32 using namespace com::sun::star::uno
;
33 using namespace com::sun::star::linguistic2
;
40 HyphenatedWord::HyphenatedWord(const OUString
&rWord
, LanguageType nLang
, sal_Int16 nHPos
,
41 const OUString
&rHyphWord
, sal_Int16 nPos
) :
43 aHyphenatedWord (rHyphWord
),
45 nHyphenationPos (nHPos
),
48 OUString
aSingleQuote( GetLocaleDataWrapper( nLanguage
).getQuotationMarkEnd() );
49 DBG_ASSERT( 1 == aSingleQuote
.getLength(), "unexpected length of quotation mark" );
50 if (!aSingleQuote
.isEmpty())
52 // ignore typographical apostrophes (which got replaced in original
53 // word when being checked for hyphenation) in results.
54 OUString
aTmpWord( rWord
);
55 OUString
aTmpHyphWord( rHyphWord
);
56 aTmpWord
= aTmpWord
.replace( aSingleQuote
[0], '\'' );
57 aTmpHyphWord
= aTmpHyphWord
.replace( aSingleQuote
[0], '\'' );
58 bIsAltSpelling
= aTmpWord
!= aTmpHyphWord
;
61 bIsAltSpelling
= rWord
!= rHyphWord
;
65 HyphenatedWord::~HyphenatedWord()
70 OUString SAL_CALL
HyphenatedWord::getWord()
72 MutexGuard
aGuard( GetLinguMutex() );
77 Locale SAL_CALL
HyphenatedWord::getLocale()
79 MutexGuard
aGuard( GetLinguMutex() );
81 return LanguageTag::convertToLocale( nLanguage
);
85 sal_Int16 SAL_CALL
HyphenatedWord::getHyphenationPos()
87 MutexGuard
aGuard( GetLinguMutex() );
88 return nHyphenationPos
;
92 OUString SAL_CALL
HyphenatedWord::getHyphenatedWord()
94 MutexGuard
aGuard( GetLinguMutex() );
95 return aHyphenatedWord
;
99 sal_Int16 SAL_CALL
HyphenatedWord::getHyphenPos()
101 MutexGuard
aGuard( GetLinguMutex() );
106 sal_Bool SAL_CALL
HyphenatedWord::isAlternativeSpelling()
108 MutexGuard
aGuard( GetLinguMutex() );
109 return bIsAltSpelling
;
113 PossibleHyphens::PossibleHyphens(const OUString
&rWord
, LanguageType nLang
,
114 const OUString
&rHyphWord
,
115 const Sequence
< sal_Int16
> &rPositions
) :
117 aWordWithHyphens(rHyphWord
),
118 aOrigHyphenPos (rPositions
),
124 PossibleHyphens::~PossibleHyphens()
129 OUString SAL_CALL
PossibleHyphens::getWord()
131 MutexGuard
aGuard( GetLinguMutex() );
136 Locale SAL_CALL
PossibleHyphens::getLocale()
138 MutexGuard
aGuard( GetLinguMutex() );
139 return LanguageTag::convertToLocale( nLanguage
);
143 OUString SAL_CALL
PossibleHyphens::getPossibleHyphens()
145 MutexGuard
aGuard( GetLinguMutex() );
146 return aWordWithHyphens
;
150 Sequence
< sal_Int16
> SAL_CALL
PossibleHyphens::getHyphenationPositions()
152 MutexGuard
aGuard( GetLinguMutex() );
153 return aOrigHyphenPos
;
156 css::uno::Reference
<css::linguistic2::XHyphenatedWord
> HyphenatedWord::CreateHyphenatedWord(
157 const OUString
&rWord
, LanguageType nLang
, sal_Int16 nHyphenationPos
,
158 const OUString
&rHyphenatedWord
, sal_Int16 nHyphenPos
)
160 return new HyphenatedWord( rWord
, nLang
, nHyphenationPos
, rHyphenatedWord
, nHyphenPos
);
163 css::uno::Reference
< css::linguistic2::XPossibleHyphens
> PossibleHyphens::CreatePossibleHyphens
164 (const OUString
&rWord
, LanguageType nLang
,
165 const OUString
&rHyphWord
,
166 const css::uno::Sequence
< sal_Int16
> &rPositions
)
168 return new PossibleHyphens( rWord
, nLang
, rHyphWord
, rPositions
);
172 } // namespace linguistic
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */