/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
pPropHelper = new PropertyHelper_Thesaurus( static_cast<XThesaurus *>(this), xPropSet );
pPropHelper->AddAsPropListener(); //! after a reference is established
} return *pPropHelper;
}
// this routine should return the locales supported by the installed // dictionaries. if (mvThesInfo.empty())
{
SvtLinguConfig aLinguCfg;
// get list of dictionaries-to-use
std::vector< SvtLinguConfigDictionaryEntry > aDics;
uno::Sequence< OUString > aFormatList;
aLinguCfg.GetSupportedDictionaryFormatsFor( u"Thesauri"_ustr,
u"org.openoffice.lingu.new.Thesaurus"_ustr, aFormatList ); for (constauto& rFormat : aFormatList)
{
std::vector< SvtLinguConfigDictionaryEntry > aTmpDic(
aLinguCfg.GetActiveDictionariesByFormat( rFormat ) );
aDics.insert( aDics.end(), aTmpDic.begin(), aTmpDic.end() );
}
//!! for compatibility with old dictionaries (the ones not using extensions //!! or new configuration entries, but still using the dictionary.lst file) //!! Get the list of old style spell checking dictionaries to use...
std::vector< SvtLinguConfigDictionaryEntry > aOldStyleDics(
GetOldStyleDics( "THES" ) );
// to prefer dictionaries with configuration entries we will only // use those old style dictionaries that add a language that // is not yet supported by the list of new style dictionaries
MergeNewStyleDicsAndOldStyleDics( aDics, aOldStyleDics );
if (!aDics.empty())
{ // get supported locales from the dictionaries-to-use...
std::set<OUString> aLocaleNamesSet; for (autoconst& dict : aDics)
{ for (constauto& rLocaleName : dict.aLocaleNames)
{ if (!comphelper::LibreOfficeKit::isAllowlistedLanguage(rLocaleName)) continue;
aLocaleNamesSet.insert( rLocaleName );
}
} // ... and add them to the resulting sequence
std::vector<Locale> aLocalesVec;
aLocalesVec.reserve(aLocaleNamesSet.size());
//! For each dictionary and each locale we need a separate entry. //! If this results in more than one dictionary per locale than (for now) //! it is undefined which dictionary gets used. //! In the future the implementation should support using several dictionaries //! for one locale.
sal_Int32 numthes = std::accumulate(aDics.begin(), aDics.end(), 0,
[](const sal_Int32 nSum, const SvtLinguConfigDictionaryEntry& dict) { return nSum + dict.aLocaleNames.getLength(); });
// add dictionary information
mvThesInfo.resize(numthes);
sal_Int32 k = 0; for (autoconst& dict : aDics)
{ if (dict.aLocaleNames.hasElements() &&
dict.aLocations.hasElements())
{ // currently only one language per dictionary is supported in the actual implementation... // Thus here we work-around this by adding the same dictionary several times. // Once for each of its supported locales. for (constauto& rLocaleName : dict.aLocaleNames)
{
LanguageTag aLanguageTag(rLocaleName);
mvThesInfo[k].aEncoding = RTL_TEXTENCODING_DONTKNOW;
mvThesInfo[k].aLocale = aLanguageTag.getLocale();
mvThesInfo[k].aCharSetInfo.reset( new CharClass( std::move(aLanguageTag) ) ); // also both files have to be in the same directory and the // file names must only differ in the extension (.aff/.dic). // Thus we use the first location only and strip the extension part.
OUString aLocation = dict.aLocations[0];
sal_Int32 nPos = aLocation.lastIndexOf( '.' );
aLocation = aLocation.copy( 0, nPos );
mvThesInfo[k].aName = aLocation;
++k;
}
}
}
DBG_ASSERT( k == numthes, "index mismatch?" );
} else
{ /* no dictionary found so register no dictionaries */
mvThesInfo.clear();
aSuppLocales.realloc(0);
}
}
// find the first thesaurus that matches the locale for (size_t i =0; i < mvThesInfo.size(); i++)
{ if (rLocale == mvThesInfo[i].aLocale)
{ // open up and initialize this thesaurus if need be if (!mvThesInfo[i].aThes)
{
OUString datpath = mvThesInfo[i].aName + ".dat";
OUString idxpath = mvThesInfo[i].aName + ".idx";
OUString ndat;
OUString nidx;
osl::FileBase::getSystemPathFromFileURL(datpath,ndat);
osl::FileBase::getSystemPathFromFileURL(idxpath,nidx);
// we don't want to work with a default text encoding since following incorrect // results may occur only for specific text and thus may be hard to notice. // Thus better always make a clean exit here if the text encoding is in question. // Hopefully something not working at all will raise proper attention quickly. ;-)
DBG_ASSERT( eEnc != RTL_TEXTENCODING_DONTKNOW, "failed to get text encoding! (maybe incorrect encoding string in file)" ); if (eEnc == RTL_TEXTENCODING_DONTKNOW) return noMeanings;
while (pTH)
{ // convert word to all lower case for searching if (!stem)
ct = capitalType(aRTerm, pCC);
OUString nTerm(makeLowerCase(aRTerm, pCC));
OString aTmp( OU2ENC(nTerm, eEnc) );
nmean = pTH->Lookup(aTmp.getStr(),aTmp.getLength(),&pmean);
sal_Int32 nLen = rArguments.getLength(); // Accept one of two args so we can be compatible with the call site in GetAvailLocales() // linguistic module if (1 == nLen || 2 == nLen)
{
Reference< XLinguProperties > xPropSet;
rArguments.getConstArray()[0] >>= xPropSet;
assert(xPropSet);
//! Pointer allows for access of the non-UNO functions. //! And the reference to the UNO-functions while increasing //! the ref-count and will implicitly free the memory //! when the object is no longer used.
pPropHelper = new PropertyHelper_Thesaurus( static_cast<XThesaurus *>(this), xPropSet );
pPropHelper->AddAsPropListener(); //! after a reference is established
} else
OSL_FAIL( "wrong number of arguments in sequence" );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.