21#if !defined WIN32_LEAN_AND_MEAN
22# define WIN32_LEAN_AND_MEAN
27#include <osl/thread.h>
28#include <osl/file.hxx>
29#include <osl/process.h>
37#include <rtl/bootstrap.hxx>
38#include <rtl/ustring.hxx>
39#include <rtl/string.hxx>
40#include <rtl/tencinfo.h>
54OString Win_AddLongPathPrefix(
const OString &rPathName )
56 constexpr OStringLiteral WIN32_LONG_PATH_PREFIX =
"\\\\?\\";
57 if (!rPathName.match(WIN32_LONG_PATH_PREFIX))
return WIN32_LONG_PATH_PREFIX + rPathName;
62#if defined SYSTEM_DICTS || defined IOS
64static void GetOldStyleDicsInDir(
65 OUString
const & aSystemDir, OUString
const & aFormatName,
66 std::u16string_view aSystemSuffix, std::u16string_view aSystemPrefix,
67 std::set< OUString >& aDicLangInUse,
68 std::vector< SvtLinguConfigDictionaryEntry >& aRes )
70 osl::Directory aSystemDicts(aSystemDir);
71 if (aSystemDicts.open() != osl::FileBase::E_None)
74 osl::DirectoryItem aItem;
75 osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL);
76 while (aSystemDicts.getNextItem(aItem) == osl::FileBase::E_None)
78 aItem.getFileStatus(aFileStatus);
79 OUString sPath = aFileStatus.getFileURL();
80 if (sPath.endsWith(aSystemSuffix))
82 sal_Int32 nStartIndex = sPath.lastIndexOf(
'/') + 1;
83 if (!sPath.match(aSystemPrefix, nStartIndex))
85 OUString sChunk = sPath.copy(nStartIndex + aSystemPrefix.size(),
86 sPath.getLength() - aSystemSuffix.size() -
87 nStartIndex - aSystemPrefix.size());
96 sChunk = sChunk.replace(
'_',
'-');
109 if (sChunk ==
"hu-HU-u8")
113 if (!aLangTag.isValidBcp47())
117 const OUString& aLocaleName(aLangTag.getBcp47());
119 if (aDicLangInUse.insert(aLocaleName).second)
125 if (aLocaleName == u
"ar")
128 u"ar-AE",
u"ar-BH",
u"ar-DJ",
u"ar-DZ",
u"ar-EG",
129 u"ar-ER",
u"ar-IL",
u"ar-IQ",
u"ar-JO",
u"ar-KM",
130 u"ar-KW",
u"ar-LB",
u"ar-LY",
u"ar-MA",
u"ar-MR",
131 u"ar-OM",
u"ar-PS",
u"ar-QA",
u"ar-SA",
u"ar-SD",
132 u"ar-SO",
u"ar-SY",
u"ar-TD",
u"ar-TN",
u"ar-YE"
136 aRes.push_back( aDicEntry );
148 std::vector< SvtLinguConfigDictionaryEntry > aRes;
153 OUString aFormatName;
154 OUString aDicExtension;
155#if defined SYSTEM_DICTS || defined IOS
157 OUString aSystemPrefix;
158 OUString aSystemSuffix;
160 if (strcmp( pDicType,
"DICT" ) == 0)
162 aFormatName =
"DICT_SPELL";
163 aDicExtension =
".dic";
165 aSystemDir = DICT_SYSTEM_DIR;
166 aSystemSuffix = aDicExtension;
168 aSystemDir =
"$BRAND_BASE_DIR/share/spell";
169 rtl::Bootstrap::expandMacros(aSystemDir);
170 aSystemSuffix =
".dic";
173 else if (strcmp( pDicType,
"HYPH" ) == 0)
175 aFormatName =
"DICT_HYPH";
176 aDicExtension =
".dic";
178 aSystemDir = HYPH_SYSTEM_DIR;
179 aSystemPrefix =
"hyph_";
180 aSystemSuffix = aDicExtension;
183 else if (strcmp( pDicType,
"THES" ) == 0)
185 aFormatName =
"DICT_THES";
186 aDicExtension =
".dat";
188 aSystemDir = THES_SYSTEM_DIR;
189 aSystemPrefix =
"th_";
190 aSystemSuffix =
"_v2.dat";
192 aSystemDir =
"$BRAND_BASE_DIR/share/thes";
193 rtl::Bootstrap::expandMacros(aSystemDir);
194 aSystemPrefix =
"th_";
195 aSystemSuffix =
"_v2.dat";
199 if (aFormatName.isEmpty() || aDicExtension.isEmpty())
202#if defined SYSTEM_DICTS || defined IOS
205 std::set< OUString > aDicLangInUse;
209 rtl_uString * pSearchPath =
nullptr;
210 osl_getEnvironment(OUString(
"DICPATH").
pData, &pSearchPath);
214 OUString aSearchPath(pSearchPath);
215 rtl_uString_release(pSearchPath);
220 OUString aSystem( aSearchPath.getToken(0,
':',
nIndex) );
227 if (osl::FileBase::getFileURLFromSystemPath(aSystem, aRelative)
228 != osl::FileBase::E_None)
230 if (osl::FileBase::getAbsoluteFileURL(aCWD, aRelative, aAbsolute)
231 != osl::FileBase::E_None)
237 GetOldStyleDicsInDir(aAbsolute, aFormatName, aSystemSuffix,
238 aSystemPrefix, aDicLangInUse, aRes);
245 GetOldStyleDicsInDir(aSystemDir, aFormatName, aSystemSuffix, aSystemPrefix,
246 aDicLangInUse, aRes);
253 std::vector< SvtLinguConfigDictionaryEntry > &rNewStyleDics,
254 const std::vector< SvtLinguConfigDictionaryEntry > &rOldStyleDics )
257 std::set< OUString > aNewStyleLanguages;
258 for (
auto const& newStyleDic : rNewStyleDics)
260 const uno::Sequence< OUString > aLocaleNames(newStyleDic.aLocaleNames);
261 sal_Int32 nLocaleNames = aLocaleNames.getLength();
262 for (sal_Int32 k = 0; k < nLocaleNames; ++k)
264 aNewStyleLanguages.insert( aLocaleNames[k] );
270 for (
auto const& oldStyleDic : rOldStyleDics)
272 sal_Int32 nOldStyleDics = oldStyleDic.aLocaleNames.getLength();
275 DBG_ASSERT( nOldStyleDics,
"old style dictionary with more than one language found!");
276 if (nOldStyleDics > 0)
280 OSL_FAIL(
"old style dictionary with invalid language found!" );
285 if (aNewStyleLanguages.find( oldStyleDic.aLocaleNames[0] ) == aNewStyleLanguages.end())
286 rNewStyleDics.push_back(oldStyleDic);
290 OSL_FAIL(
"old style dictionary with no language found!" );
298 rtl_TextEncoding eRet = RTL_TEXTENCODING_DONTKNOW;
302 eRet = rtl_getTextEncodingFromMimeCharset(pCharset);
303 if (eRet == RTL_TEXTENCODING_DONTKNOW)
304 eRet = rtl_getTextEncodingFromUnixCharset(pCharset);
305 if (eRet == RTL_TEXTENCODING_DONTKNOW)
307 if (strcmp(
"ISCII-DEVANAGARI", pCharset) == 0)
308 eRet = RTL_TEXTENCODING_ISCII_DEVANAGARI;
static bool getProcessWorkingDir(OUString &rUrl)
#define DBG_ASSERT(sCon, aError)
std::vector< SvtLinguConfigDictionaryEntry > GetOldStyleDics(const char *pDicType)
void MergeNewStyleDicsAndOldStyleDics(std::vector< SvtLinguConfigDictionaryEntry > &rNewStyleDics, const std::vector< SvtLinguConfigDictionaryEntry > &rOldStyleDics)
rtl_TextEncoding getTextEncodingFromCharset(const char *pCharset)
std::unique_ptr< sal_Int32[]> pData
bool LinguIsUnspecified(LanguageType nLanguage)
css::uno::Sequence< OUString > aLocaleNames
css::uno::Sequence< OUString > aLocations