diff options
author | László Németh <nemeth@numbertext.org> | 2018-01-04 12:18:28 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2018-01-05 02:01:16 +0100 |
commit | c8fbce439db78dd85295833df494a651bd64dcd4 (patch) | |
tree | 96cf56a8629a5bbca16a2b3feedb58f50ebda4f8 /linguistic | |
parent | 6247c966942a0e43320a234302a67c1f92c2eea7 (diff) |
Add optional title: field to user dictionaries
LibreOffice stores the title of an user dictionary
only in its file name, but special characters in
file names can result configuration problem for user
dictionaries shipped with LibreOffice.
Optional "title:" field of user dictionaries
supports custom titles with spaces and other UTF-8
characters.
Change-Id: Idbc4c41a2e08f50cfc0fc0d25e960084f5773bec
Reviewed-on: https://gerrit.libreoffice.org/47397
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'linguistic')
-rw-r--r-- | linguistic/source/dicimp.cxx | 38 | ||||
-rw-r--r-- | linguistic/source/dicimp.hxx | 2 | ||||
-rw-r--r-- | linguistic/source/dlistimp.cxx | 11 |
3 files changed, 43 insertions, 8 deletions
diff --git a/linguistic/source/dicimp.cxx b/linguistic/source/dicimp.cxx index 911735ce3815..42147866991c 100644 --- a/linguistic/source/dicimp.cxx +++ b/linguistic/source/dicimp.cxx @@ -63,8 +63,26 @@ using namespace linguistic; #define MAX_HEADER_LENGTH 16 // XML-header to query SPELLML support +// to handle user words with "Grammar By" model words #define SPELLML_SUPPORT "<?xml?>" +// User dictionaries can contain optional "title:" tags +// to support custom titles with space and other characters. +// (old mechanism stores the title of the user dictionary +// only in its file name, but special characters are +// problem for user dictionaries shipped with LibreOffice). +// +// The following fake file name extension will be +// added to the text of the title: field for correct +// text stripping and dictionary saving. +// +// TODO: add translation support? +// tdf#50827 language dependent wordlists are already in +// the appropriate dict packages. +// Note: Also name of the special run-time dictionary +// "IgnoreAllList" hasn't been localized yet. +#define EXTENSION_FOR_TITLE_TEXT "." + static const sal_Char* const pVerStr2 = "WBSWG2"; static const sal_Char* const pVerStr5 = "WBSWG5"; static const sal_Char* const pVerStr6 = "WBSWG6"; @@ -96,7 +114,7 @@ static bool getTag(const OString &rLine, const sal_Char *pTagName, } -sal_Int16 ReadDicVersion( SvStreamPtr const &rpStream, LanguageType &nLng, bool &bNeg ) +sal_Int16 ReadDicVersion( SvStreamPtr const &rpStream, LanguageType &nLng, bool &bNeg, OUString &aDicName ) { // Sniff the header sal_Int16 nDicVersion = DIC_VERSION_DONTKNOW; @@ -146,6 +164,16 @@ sal_Int16 ReadDicVersion( SvStreamPtr const &rpStream, LanguageType &nLng, bool bNeg = aTagValue == "negative"; } + // lang: title + if (getTag(aLine, "title: ", aTagValue)) + { + aDicName = OStringToOUString( aTagValue, RTL_TEXTENCODING_UTF8) + + // recent title text preparation in GetDicInfoStr() waits for an + // extension, so we add it to avoid bad stripping at final dot + // of the title text + EXTENSION_FOR_TITLE_TEXT; + } + if (aLine.indexOf("---") != -1) // end of header break; } @@ -274,7 +302,7 @@ ErrCode DictionaryNeo::loadEntries(const OUString &rMainURL) // read header bool bNegativ; LanguageType nLang; - nDicVersion = ReadDicVersion(pStream, nLang, bNegativ); + nDicVersion = ReadDicVersion(pStream, nLang, bNegativ, aDicName); ErrCode nErr = pStream->GetError(); if (nErr != ERRCODE_NONE) return nErr; @@ -429,6 +457,12 @@ ErrCode DictionaryNeo::saveEntries(const OUString &rURL) pStream->WriteLine(OString("type: positive")); else pStream->WriteLine(OString("type: negative")); + if (aDicName.endsWith(EXTENSION_FOR_TITLE_TEXT)) + { + pStream->WriteLine(OUStringToOString("title: " + + // strip EXTENSION_FOR_TITLE_TEXT + aDicName.copy(0, aDicName.lastIndexOf(EXTENSION_FOR_TITLE_TEXT)), eEnc)); + } if (ERRCODE_NONE != (nErr = pStream->GetError())) return nErr; pStream->WriteLine(OString("---")); diff --git a/linguistic/source/dicimp.hxx b/linguistic/source/dicimp.hxx index 6833d3f94235..99560ff8898a 100644 --- a/linguistic/source/dicimp.hxx +++ b/linguistic/source/dicimp.hxx @@ -34,7 +34,7 @@ #define DIC_MAX_ENTRIES 30000 -sal_Int16 ReadDicVersion( SvStreamPtr const &rpStream, LanguageType &nLng, bool &bNeg ); +sal_Int16 ReadDicVersion( SvStreamPtr const &rpStream, LanguageType &nLng, bool &bNeg, OUString &aDicName ); class DictionaryNeo : public ::cppu::WeakImplHelper diff --git a/linguistic/source/dlistimp.cxx b/linguistic/source/dlistimp.cxx index b2a63d6e9480..cdace82de2c6 100644 --- a/linguistic/source/dlistimp.cxx +++ b/linguistic/source/dlistimp.cxx @@ -52,7 +52,7 @@ using namespace com::sun::star::linguistic2; using namespace linguistic; -static bool IsVers2OrNewer( const OUString& rFileURL, LanguageType& nLng, bool& bNeg ); +static bool IsVers2OrNewer( const OUString& rFileURL, LanguageType& nLng, bool& bNeg, OUString& aDicName ); static void AddInternal( const uno::Reference< XDictionary > &rDic, const OUString& rNew ); @@ -294,8 +294,9 @@ void DicList::SearchForDictionaries( OUString aURL( pDirCnt[i] ); LanguageType nLang = LANGUAGE_NONE; bool bNeg = false; + OUString aDicTitle = ""; - if(!::IsVers2OrNewer( aURL, nLang, bNeg )) + if(!::IsVers2OrNewer( aURL, nLang, bNeg, aDicTitle )) { // When not sal_Int32 nPos = aURL.indexOf('.'); @@ -335,7 +336,7 @@ void DicList::SearchForDictionaries( DictionaryType eType = bNeg ? DictionaryType_NEGATIVE : DictionaryType_POSITIVE; uno::Reference< XDictionary > xDic = - new DictionaryNeo( aDicName, nLang, eType, aURL, bIsWriteablePath ); + new DictionaryNeo( aDicTitle.isEmpty() ? aDicName : aDicTitle, nLang, eType, aURL, bIsWriteablePath ); addDictionary( xDic ); nCount++; @@ -794,7 +795,7 @@ static void AddUserData( const uno::Reference< XDictionary > &rDic ) } } -static bool IsVers2OrNewer( const OUString& rFileURL, LanguageType& nLng, bool& bNeg ) +static bool IsVers2OrNewer( const OUString& rFileURL, LanguageType& nLng, bool& bNeg, OUString& aDicName ) { if (rFileURL.isEmpty()) return false; @@ -826,7 +827,7 @@ static bool IsVers2OrNewer( const OUString& rFileURL, LanguageType& nLng, bool& SvStreamPtr pStream = SvStreamPtr( utl::UcbStreamHelper::CreateStream( xStream ) ); - int nDicVersion = ReadDicVersion(pStream, nLng, bNeg); + int nDicVersion = ReadDicVersion(pStream, nLng, bNeg, aDicName); return 2 == nDicVersion || nDicVersion >= 5; } |