Kaydet (Commit) c8fbce43 authored tarafından László Németh's avatar László Németh

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/47397Reviewed-by: 's avatarLászló Németh <nemeth@numbertext.org>
Tested-by: 's avatarLászló Németh <nemeth@numbertext.org>
üst 6247c966
......@@ -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("---"));
......
......@@ -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
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment