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/ustring.hxx>
38 #include <rtl/string.hxx>
39 #include <rtl/tencinfo.h>
53 OString Win_AddLongPathPrefix(
const OString &rPathName )
55 #define WIN32_LONG_PATH_PREFIX "\\\\?\\"
56 if (!rPathName.match(WIN32_LONG_PATH_PREFIX))
return WIN32_LONG_PATH_PREFIX + rPathName;
59 #endif //defined(_WIN32)
63 static void GetOldStyleDicsInDir(
64 OUString
const & aSystemDir, OUString
const & aFormatName,
65 OUString
const & aSystemSuffix, OUString
const & aSystemPrefix,
66 std::set< OUString >& aDicLangInUse,
67 std::vector< SvtLinguConfigDictionaryEntry >& aRes )
69 osl::Directory aSystemDicts(aSystemDir);
70 if (aSystemDicts.open() != osl::FileBase::E_None)
73 osl::DirectoryItem aItem;
74 osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL);
75 while (aSystemDicts.getNextItem(aItem) == osl::FileBase::E_None)
77 aItem.getFileStatus(aFileStatus);
78 OUString sPath = aFileStatus.getFileURL();
79 if (sPath.endsWith(aSystemSuffix))
81 sal_Int32 nStartIndex = sPath.lastIndexOf(
'/') + 1;
82 if (!sPath.match(aSystemPrefix, nStartIndex))
84 OUString sChunk = sPath.copy(nStartIndex + aSystemPrefix.getLength(),
85 sPath.getLength() - aSystemSuffix.getLength() -
86 nStartIndex - aSystemPrefix.getLength());
95 sChunk = sChunk.replace(
'_',
'-');
108 if (sChunk ==
"hu-HU-u8")
112 if (!aLangTag.isValidBcp47())
116 const OUString& aLocaleName(aLangTag.getBcp47());
118 if (aDicLangInUse.insert(aLocaleName).second)
127 aRes.push_back( aDicEntry );
139 std::vector< SvtLinguConfigDictionaryEntry > aRes;
144 OUString aFormatName;
145 OUString aDicExtension;
148 OUString aSystemPrefix;
149 OUString aSystemSuffix;
151 if (strcmp( pDicType,
"DICT" ) == 0)
153 aFormatName =
"DICT_SPELL";
154 aDicExtension =
".dic";
156 aSystemDir = DICT_SYSTEM_DIR;
157 aSystemSuffix = aDicExtension;
160 else if (strcmp( pDicType,
"HYPH" ) == 0)
162 aFormatName =
"DICT_HYPH";
163 aDicExtension =
".dic";
165 aSystemDir = HYPH_SYSTEM_DIR;
166 aSystemPrefix =
"hyph_";
167 aSystemSuffix = aDicExtension;
170 else if (strcmp( pDicType,
"THES" ) == 0)
172 aFormatName =
"DICT_THES";
173 aDicExtension =
".dat";
175 aSystemDir = THES_SYSTEM_DIR;
176 aSystemPrefix =
"th_";
177 aSystemSuffix =
"_v2.dat";
181 if (aFormatName.isEmpty() || aDicExtension.isEmpty())
187 std::set< OUString > aDicLangInUse;
190 rtl_uString * pSearchPath =
nullptr;
191 osl_getEnvironment(OUString(
"DICPATH").
pData, &pSearchPath);
195 OUString aSearchPath(pSearchPath);
196 rtl_uString_release(pSearchPath);
201 OUString aSystem = aSearchPath.getToken(0,
':', nIndex);
208 if (osl::FileBase::getFileURLFromSystemPath(aSystem, aRelative)
209 != osl::FileBase::E_None)
211 if (osl::FileBase::getAbsoluteFileURL(aCWD, aRelative, aAbsolute)
212 != osl::FileBase::E_None)
218 GetOldStyleDicsInDir(aAbsolute, aFormatName, aSystemSuffix,
219 aSystemPrefix, aDicLangInUse, aRes);
221 while (nIndex != -1);
225 GetOldStyleDicsInDir(aSystemDir, aFormatName, aSystemSuffix, aSystemPrefix,
226 aDicLangInUse, aRes);
233 std::vector< SvtLinguConfigDictionaryEntry > &rNewStyleDics,
234 const std::vector< SvtLinguConfigDictionaryEntry > &rOldStyleDics )
237 std::set< OUString > aNewStyleLanguages;
238 for (
auto const& newStyleDic : rNewStyleDics)
240 const uno::Sequence< OUString > aLocaleNames(newStyleDic.aLocaleNames);
241 sal_Int32 nLocaleNames = aLocaleNames.getLength();
242 for (sal_Int32 k = 0; k < nLocaleNames; ++k)
244 aNewStyleLanguages.insert( aLocaleNames[k] );
250 for (
auto const& oldStyleDic : rOldStyleDics)
252 sal_Int32 nOldStyleDics = oldStyleDic.aLocaleNames.getLength();
255 DBG_ASSERT( nOldStyleDics,
"old style dictionary with more than one language found!");
256 if (nOldStyleDics > 0)
260 OSL_FAIL(
"old style dictionary with invalid language found!" );
265 if (aNewStyleLanguages.find( oldStyleDic.aLocaleNames[0] ) == aNewStyleLanguages.end())
266 rNewStyleDics.push_back(oldStyleDic);
270 OSL_FAIL(
"old style dictionary with no language found!" );
278 rtl_TextEncoding eRet = RTL_TEXTENCODING_DONTKNOW;
282 eRet = rtl_getTextEncodingFromMimeCharset(pCharset);
283 if (eRet == RTL_TEXTENCODING_DONTKNOW)
284 eRet = rtl_getTextEncodingFromUnixCharset(pCharset);
285 if (eRet == RTL_TEXTENCODING_DONTKNOW)
287 if (strcmp(
"ISCII-DEVANAGARI", pCharset) == 0)
288 eRet = RTL_TEXTENCODING_ISCII_DEVANAGARI;
std::unique_ptr< ContentProperties > pData
static bool getProcessWorkingDir(OUString &rUrl)
std::vector< SvtLinguConfigDictionaryEntry > GetOldStyleDics(const char *pDicType)
rtl_TextEncoding getTextEncodingFromCharset(const char *pCharset)
bool LinguIsUnspecified(LanguageType nLanguage)
#define DBG_ASSERT(sCon, aError)
css::uno::Sequence< OUString > aLocaleNames
void MergeNewStyleDicsAndOldStyleDics(std::vector< SvtLinguConfigDictionaryEntry > &rNewStyleDics, const std::vector< SvtLinguConfigDictionaryEntry > &rOldStyleDics)
css::uno::Sequence< OUString > aLocations