1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21 #include <linguistic/hyphdta.hxx>
22 #include <linguistic/misc.hxx>
23 #include <osl/mutex.hxx>
24
25
26 #include <tools/debug.hxx>
27 #include <unotools/localedatawrapper.hxx>
28
29 using namespace osl;
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;
34
35
36 namespace linguistic
37 {
38
39
HyphenatedWord(const OUString & rWord,LanguageType nLang,sal_Int16 nHPos,const OUString & rHyphWord,sal_Int16 nPos)40 HyphenatedWord::HyphenatedWord(const OUString &rWord, LanguageType nLang, sal_Int16 nHPos,
41 const OUString &rHyphWord, sal_Int16 nPos ) :
42 aWord (rWord),
43 aHyphenatedWord (rHyphWord),
44 nHyphPos (nPos),
45 nHyphenationPos (nHPos),
46 nLanguage (nLang)
47 {
48 OUString aSingleQuote( GetLocaleDataWrapper( nLanguage ).getQuotationMarkEnd() );
49 DBG_ASSERT( 1 == aSingleQuote.getLength(), "unexpected length of quotation mark" );
50 if (!aSingleQuote.isEmpty())
51 {
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;
59 }
60 else
61 bIsAltSpelling = rWord != rHyphWord;
62 }
63
64
~HyphenatedWord()65 HyphenatedWord::~HyphenatedWord()
66 {
67 }
68
69
getWord()70 OUString SAL_CALL HyphenatedWord::getWord()
71 {
72 MutexGuard aGuard( GetLinguMutex() );
73 return aWord;
74 }
75
76
getLocale()77 Locale SAL_CALL HyphenatedWord::getLocale()
78 {
79 MutexGuard aGuard( GetLinguMutex() );
80
81 return LanguageTag::convertToLocale( nLanguage );
82 }
83
84
getHyphenationPos()85 sal_Int16 SAL_CALL HyphenatedWord::getHyphenationPos()
86 {
87 MutexGuard aGuard( GetLinguMutex() );
88 return nHyphenationPos;
89 }
90
91
getHyphenatedWord()92 OUString SAL_CALL HyphenatedWord::getHyphenatedWord()
93 {
94 MutexGuard aGuard( GetLinguMutex() );
95 return aHyphenatedWord;
96 }
97
98
getHyphenPos()99 sal_Int16 SAL_CALL HyphenatedWord::getHyphenPos()
100 {
101 MutexGuard aGuard( GetLinguMutex() );
102 return nHyphPos;
103 }
104
105
isAlternativeSpelling()106 sal_Bool SAL_CALL HyphenatedWord::isAlternativeSpelling()
107 {
108 MutexGuard aGuard( GetLinguMutex() );
109 return bIsAltSpelling;
110 }
111
112
PossibleHyphens(const OUString & rWord,LanguageType nLang,const OUString & rHyphWord,const Sequence<sal_Int16> & rPositions)113 PossibleHyphens::PossibleHyphens(const OUString &rWord, LanguageType nLang,
114 const OUString &rHyphWord,
115 const Sequence< sal_Int16 > &rPositions) :
116 aWord (rWord),
117 aWordWithHyphens(rHyphWord),
118 aOrigHyphenPos (rPositions),
119 nLanguage (nLang)
120 {
121 }
122
123
~PossibleHyphens()124 PossibleHyphens::~PossibleHyphens()
125 {
126 }
127
128
getWord()129 OUString SAL_CALL PossibleHyphens::getWord()
130 {
131 MutexGuard aGuard( GetLinguMutex() );
132 return aWord;
133 }
134
135
getLocale()136 Locale SAL_CALL PossibleHyphens::getLocale()
137 {
138 MutexGuard aGuard( GetLinguMutex() );
139 return LanguageTag::convertToLocale( nLanguage );
140 }
141
142
getPossibleHyphens()143 OUString SAL_CALL PossibleHyphens::getPossibleHyphens()
144 {
145 MutexGuard aGuard( GetLinguMutex() );
146 return aWordWithHyphens;
147 }
148
149
getHyphenationPositions()150 Sequence< sal_Int16 > SAL_CALL PossibleHyphens::getHyphenationPositions()
151 {
152 MutexGuard aGuard( GetLinguMutex() );
153 return aOrigHyphenPos;
154 }
155
CreateHyphenatedWord(const OUString & rWord,LanguageType nLang,sal_Int16 nHyphenationPos,const OUString & rHyphenatedWord,sal_Int16 nHyphenPos)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 )
159 {
160 return new HyphenatedWord( rWord, nLang, nHyphenationPos, rHyphenatedWord, nHyphenPos );
161 }
162
CreatePossibleHyphens(const OUString & rWord,LanguageType nLang,const OUString & rHyphWord,const css::uno::Sequence<sal_Int16> & rPositions)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)
167 {
168 return new PossibleHyphens( rWord, nLang, rHyphWord, rPositions );
169 }
170
171
172 } // namespace linguistic
173
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
175