[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-4.2' - 4 commits - distro-configs/CPOSX.conf sw/source writerfilter/CppunitTest_writerfilter_misc.mk writerfilter/Module_writerfilter.mk writerfilter/qa writerfilter/source

Michael Stahl mstahl at redhat.com
Wed Mar 5 00:31:56 PST 2014


 distro-configs/CPOSX.conf                         |    2 
 sw/source/core/unocore/unofield.cxx               |    2 
 writerfilter/CppunitTest_writerfilter_misc.mk     |   36 +++
 writerfilter/Module_writerfilter.mk               |    1 
 writerfilter/qa/cppunittests/misc/misc.cxx        |  162 ++++++++++++++
 writerfilter/source/dmapper/DomainMapper.cxx      |    4 
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |  245 +++++++++++++++-------
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |   10 
 8 files changed, 383 insertions(+), 79 deletions(-)

New commits:
commit 793e4ae782483ac159cd59cad4e8eef881914bb6
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sun Mar 2 00:32:17 2014 +0100

    fdo#47811: RTF import: fix Database field content
    
    1. the Database field master does not have a "Content" property
    2. SetFieldContent was called once for every chunk of text in the field
       result, always overwriting the previous value; accumulate the text.
    
    Change-Id: I63cfda19e2e416c52d100d9071796305a5d813c6
    (cherry picked from commit e24ae38c8ef233e4b44840058e35959194724743)
    Reviewed-on: https://gerrit.libreoffice.org/8442
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 4b6ed8e..2532942 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3827,7 +3827,7 @@ void DomainMapper::lcl_text(const sal_uInt8 * data_, size_t len)
         else if( m_pImpl->IsOpenField() && m_pImpl->IsFieldResultAsString())
              /*depending on the success of the field insert operation this result will be
               set at the field or directly inserted into the text*/
-            m_pImpl->SetFieldResult( sText );
+            m_pImpl->AppendFieldResult(sText);
         else
         {
             if (pContext == 0)
@@ -3930,7 +3930,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
             else if( m_pImpl->IsOpenField() && m_pImpl->IsFieldResultAsString())
                 /*depending on the success of the field insert operation this result will be
                   set at the field or directly inserted into the text*/
-                m_pImpl->SetFieldResult( sText );
+                m_pImpl->AppendFieldResult(sText);
             else
             {
                 if (pContext == 0)
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index c7302cf..8822882 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -3304,7 +3304,6 @@ void DomainMapper_Impl::CloseFieldCommand()
     //                             uno::makeAny( pContext->GetCommand().copy( nIndex + 1 )));
                         uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
                         xDependentField->attachTextFieldMaster( xMaster );
-                        m_bSetUserFieldContent = true;
                     }
                     break;
                     case FIELD_MERGEREC     : break;
@@ -3538,8 +3537,18 @@ bool DomainMapper_Impl::IsFieldResultAsString()
     return bRet;
 }
 
+void DomainMapper_Impl::AppendFieldResult(OUString const& rString)
+{
+    assert(!m_aFieldStack.empty());
+    FieldContextPtr pContext = m_aFieldStack.top();
+    SAL_WARN_IF(!pContext.get(), "writerfilter.dmapper", "no field context");
+    if (pContext.get())
+    {
+        pContext->AppendResult(rString);
+    }
+}
 
-void DomainMapper_Impl::SetFieldResult( OUString& rResult )
+void DomainMapper_Impl::SetFieldResult(OUString const& rResult)
 {
 #ifdef DEBUG_DOMAINMAPPER
     dmapper_logger->startElement("setFieldResult");
@@ -3595,9 +3604,10 @@ void DomainMapper_Impl::SetFieldResult( OUString& rResult )
                 }
             }
         }
-        catch( const uno::Exception& )
+        catch (const uno::Exception& e)
         {
-
+            SAL_WARN("writerfilter.dmapper",
+                "DomainMapper_Impl::SetFieldResult: exception: " << e.Message);
         }
     }
 }
@@ -3641,6 +3651,9 @@ void DomainMapper_Impl::PopFieldContext()
         if( !pContext->IsCommandCompleted() )
             CloseFieldCommand();
 
+        if (!pContext->GetResult().isEmpty())
+            SetFieldResult(pContext->GetResult());
+
         //insert the field, TC or TOC
         uno::Reference< text::XTextAppend >  xTextAppend;
         if (!m_aTextAppendStack.empty())
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 4686baa..6792be2 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -124,6 +124,7 @@ class FieldContext
     ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange >          m_xStartRange;
 
     OUString                                                                 m_sCommand;
+    OUString m_sResult;
 
     ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextField >          m_xTextField;
     ::com::sun::star::uno::Reference< ::com::sun::star::text::XFormField >          m_xFormField;
@@ -142,6 +143,9 @@ public:
     void                    AppendCommand(const OUString& rPart);
     const OUString&  GetCommand() const {return m_sCommand; }
 
+    void AppendResult(OUString const& rResult) { m_sResult += rResult; }
+    const OUString&  GetResult() const { return m_sResult; }
+
     void                    SetCommandCompleted() { m_bFieldCommandCompleted = true; }
     bool                    IsCommandCompleted() const { return m_bFieldCommandCompleted;    }
 
@@ -597,8 +601,9 @@ public:
     void CloseFieldCommand();
     //the _current_ fields require a string type result while TOCs accept richt results
     bool IsFieldResultAsString();
+    void AppendFieldResult(OUString const& rResult);
     //apply the result text to the related field
-    void SetFieldResult( OUString& rResult );
+    void SetFieldResult(OUString const& rResult);
     // set FFData of top field context
     void SetFieldFFData( FFDataHandler::Pointer_t pFFDataHandler );
     //the end of field is reached (0x15 appeared) - the command might still be open
commit 86a36b084eda21a8ac0f02a475572848412e98ba
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat Mar 1 23:13:39 2014 +0100

    fdo#47811: fix setPropertyValue("Name") of Database fieldmaster
    
    This one is assigning to the wrong pType variable.
    
    (regression from CWS swwarnings)
    
    Change-Id: I9a74734d22313f215ed69c9a57edf7eb035736ea
    (cherry picked from commit c06f686fe001392ceb7f606f5dc3c775997cc7de)
    Reviewed-on: https://gerrit.libreoffice.org/8441
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx
index 11f347f..f49595c 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -652,7 +652,7 @@ throw (beans::UnknownPropertyException, beans::PropertyVetoException,
             case RES_DBFLD :
             {
                 rValue >>= m_pImpl->m_sParam3;
-                pType = GetFldType();
+                pType2 = GetFldType();
             }
             break;
         }
commit 7556b9349c3aadd742c051332434927c854d3700
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat Mar 1 22:05:51 2014 +0100

    writerfilter: salvage a field parameter parsing train wreck
    
    Field parameters get horribly maimed by lcl_ExtractParameter which
    clearly has never worked in its 7 years of existence (and looking at the
    inanity at the call sites makes one wonder what the author was smoking).
    
    The format is actually quite annoying, since spaces between parameters
    are optional.
    
    The old RTF filter was at least able to parse "PAGEREF bookmark" fields,
    so this fixes such regressions (related: rhbz#1065629).
    
    (cherry picked from commit 3dc548476c7e88f7a67cc38daf622631a34e34dd)
    
    Conflicts:
    	writerfilter/source/dmapper/DomainMapper_Impl.cxx
    
    Change-Id: I9b2e32c3c7264be0fc1077cb8fb3f1bc5c1955bb
    Reviewed-on: https://gerrit.libreoffice.org/8440
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/writerfilter/CppunitTest_writerfilter_misc.mk b/writerfilter/CppunitTest_writerfilter_misc.mk
new file mode 100644
index 0000000..1cdcd80
--- /dev/null
+++ b/writerfilter/CppunitTest_writerfilter_misc.mk
@@ -0,0 +1,36 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,writerfilter_misc))
+
+$(eval $(call gb_CppunitTest_use_api,writerfilter_misc,\
+	offapi \
+	udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_external,writerfilter_misc,boost_headers))
+
+$(eval $(call gb_CppunitTest_use_libraries,writerfilter_misc, \
+	writerfilter \
+	cppu \
+	sal \
+	$(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_set_include,writerfilter_misc, \
+	$$(INCLUDE) \
+	-I$(SRCDIR)/writerfilter/inc \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,writerfilter_misc, \
+	writerfilter/qa/cppunittests/misc/misc \
+))
+
+
+# vim: set noet sw=4 ts=4:
diff --git a/writerfilter/Module_writerfilter.mk b/writerfilter/Module_writerfilter.mk
index 783b6ca..2fcb9e6 100644
--- a/writerfilter/Module_writerfilter.mk
+++ b/writerfilter/Module_writerfilter.mk
@@ -16,6 +16,7 @@ $(eval $(call gb_Module_add_targets,writerfilter,\
 
 $(eval $(call gb_Module_add_slowcheck_targets,writerfilter,\
     CppunitTest_writerfilter_rtftok \
+    CppunitTest_writerfilter_misc \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/writerfilter/qa/cppunittests/misc/misc.cxx b/writerfilter/qa/cppunittests/misc/misc.cxx
new file mode 100644
index 0000000..f7031b4
--- /dev/null
+++ b/writerfilter/qa/cppunittests/misc/misc.cxx
@@ -0,0 +1,162 @@
+/* -*- 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/.
+ */
+
+#include <limits>
+#include <vector>
+
+#include <boost/tuple/tuple.hpp>
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <sal/types.h>
+
+#include <rtl/ustring.hxx>
+
+#include <WriterFilterDllApi.hxx>
+
+
+using namespace std;
+
+
+namespace writerfilter { namespace dmapper {
+
+SAL_DLLPUBLIC_IMPORT // export just for test
+boost::tuple<OUString, vector<OUString>, vector<OUString> >
+lcl_SplitFieldCommand(const OUString& rCommand);
+
+} }
+
+
+namespace {
+
+class WriterfilterMiscTest
+    : public ::CppUnit::TestFixture
+{
+public:
+    virtual void setUp();
+    virtual void tearDown();
+
+    void testFieldParameters();
+
+    CPPUNIT_TEST_SUITE(WriterfilterMiscTest);
+    CPPUNIT_TEST(testFieldParameters);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void WriterfilterMiscTest::setUp()
+{
+}
+
+void WriterfilterMiscTest::tearDown()
+{
+}
+
+void WriterfilterMiscTest::testFieldParameters()
+{
+    using writerfilter::dmapper::lcl_SplitFieldCommand;
+    boost::tuple<OUString, vector<OUString>, vector<OUString> > result;
+
+    result = lcl_SplitFieldCommand("PAGEREF last_page");
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
+    CPPUNIT_ASSERT(boost::get<2>(result).empty());
+
+    result = lcl_SplitFieldCommand(" PAGEREF last_page ");
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
+
+    result = lcl_SplitFieldCommand("pageref last_page");
+    CPPUNIT_ASSERT(boost::get<2>(result).empty());
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
+    CPPUNIT_ASSERT(boost::get<2>(result).empty());
+
+    result = lcl_SplitFieldCommand("pageref \"last_page\"");
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
+    CPPUNIT_ASSERT(boost::get<2>(result).empty());
+
+    result = lcl_SplitFieldCommand("\"PAGEREF\" \"last_page\" \"\" ");
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT_EQUAL(size_t(2), boost::get<1>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
+    CPPUNIT_ASSERT_EQUAL(OUString(), boost::get<1>(result)[1]);
+    CPPUNIT_ASSERT(boost::get<2>(result).empty());
+
+    result = lcl_SplitFieldCommand("\"PAGEREF\"\"last_page\"  ");
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
+    CPPUNIT_ASSERT(boost::get<2>(result).empty());
+
+    result = lcl_SplitFieldCommand("PAGEREF\"last_page\"  ");
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
+    CPPUNIT_ASSERT(boost::get<2>(result).empty());
+
+    result = lcl_SplitFieldCommand("\"PAGEREF\"last_page \"\"");
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT_EQUAL(size_t(2), boost::get<1>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
+    CPPUNIT_ASSERT_EQUAL(OUString(), boost::get<1>(result)[1]);
+    CPPUNIT_ASSERT(boost::get<2>(result).empty());
+
+    result = lcl_SplitFieldCommand("\"PAGEREF\"last_page \"\"");
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT_EQUAL(size_t(2), boost::get<1>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
+    CPPUNIT_ASSERT_EQUAL(OUString(), boost::get<1>(result)[1]);
+    CPPUNIT_ASSERT(boost::get<2>(result).empty());
+
+    result = lcl_SplitFieldCommand("pageref \"last\\\\pa\\\"ge\"");
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("last\\pa\"ge"), boost::get<1>(result)[0]);
+    CPPUNIT_ASSERT(boost::get<2>(result).empty());
+
+    result = lcl_SplitFieldCommand("PAGEREF\"last_page\"\\*");
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
+    CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<2>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("\\*"), boost::get<2>(result)[0]);
+
+    result = lcl_SplitFieldCommand("PAGEREF  last_page   \\b   foobar ");
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
+    CPPUNIT_ASSERT_EQUAL(size_t(2), boost::get<2>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("\\B"), boost::get<2>(result)[0]);
+    CPPUNIT_ASSERT_EQUAL(OUString("foobar"), boost::get<2>(result)[1]);
+
+    result = lcl_SplitFieldCommand("PAGEREF\\bfoobar\\A\"\"");
+    CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
+    CPPUNIT_ASSERT(boost::get<1>(result).empty());
+    CPPUNIT_ASSERT_EQUAL(size_t(4), boost::get<2>(result).size());
+    CPPUNIT_ASSERT_EQUAL(OUString("\\B"), boost::get<2>(result)[0]);
+    CPPUNIT_ASSERT_EQUAL(OUString("foobar"), boost::get<2>(result)[1]);
+    CPPUNIT_ASSERT_EQUAL(OUString("\\A"), boost::get<2>(result)[2]);
+    CPPUNIT_ASSERT_EQUAL(OUString(), boost::get<2>(result)[3]);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(WriterfilterMiscTest);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 6b9562b..c7302cf 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -66,6 +66,7 @@
 #include <ooxml/OOXMLFastTokens.hxx>
 
 #include <map>
+#include <boost/tuple/tuple.hpp>
 
 #include <vcl/svapp.hxx>
 #include <vcl/outdev.hxx>
@@ -2003,37 +2004,133 @@ OUString lcl_ParseFormat( const OUString& rCommand )
 /*-------------------------------------------------------------------------
 extract a parameter (with or without quotes) between the command and the following backslash
   -----------------------------------------------------------------------*/
-OUString lcl_ExtractParameter(const OUString& rCommand, sal_Int32 nCommandLength )
+static OUString lcl_ExtractToken(OUString const& rCommand,
+        sal_Int32 & rIndex, bool & rHaveToken, bool & rIsSwitch)
 {
-    sal_Int32 nStartIndex = nCommandLength;
-    sal_Int32 nEndIndex = 0;
-    sal_Int32 nQuoteIndex = rCommand.indexOf( '\"', nStartIndex);
-    if( nQuoteIndex >= 0)
+    rHaveToken = false;
+    rIsSwitch = false;
+
+    OUStringBuffer token;
+    bool bQuoted(false);
+    for (; rIndex < rCommand.getLength(); ++rIndex)
     {
-        nStartIndex = nQuoteIndex + 1;
-        nEndIndex = rCommand.indexOf( '\"', nStartIndex + 1) - 1;
+        sal_Unicode const currentChar(rCommand[rIndex]);
+        switch (currentChar)
+        {
+            case '\\':
+            {
+                if (rIndex == rCommand.getLength() - 1)
+                {
+                    SAL_INFO("writerfilter.dmapper", "field: trailing escape");
+                    ++rIndex;
+                    return OUString();
+                }
+                sal_Unicode const nextChar(rCommand[rIndex+1]);
+                if (bQuoted || '\\' == nextChar)
+                {
+                    ++rIndex; // read 2 chars
+                    token.append(nextChar);
+                }
+                else // field switch (case insensitive)
+                {
+                    rHaveToken = true;
+                    if (token.isEmpty())
+                    {
+                        rIsSwitch = true;
+                        rIndex += 2; // read 2 chars
+                        return rCommand.copy(rIndex - 2, 2).toAsciiUpperCase();
+                    }
+                    else
+                    {   // leave rIndex, read it again next time
+                        return token.makeStringAndClear();
+                    }
+                }
+            }
+            break;
+            case '\"':
+                if (bQuoted || !token.isEmpty())
+                {
+                    rHaveToken = true;
+                    if (bQuoted)
+                    {
+                        ++rIndex;
+                    }
+                    return token.makeStringAndClear();
+                }
+                else
+                {
+                    bQuoted = true;
+                }
+            break;
+            case ' ':
+                if (bQuoted)
+                {
+                    token.append(' ');
+                }
+                else
+                {
+                    if (!token.isEmpty())
+                    {
+                        rHaveToken = true;
+                        ++rIndex;
+                        return token.makeStringAndClear();
+                    }
+                }
+            break;
+            default:
+                token.append(currentChar);
+            break;
+        }
+    }
+    assert(rIndex == rCommand.getLength());
+    if (bQuoted)
+    {
+        SAL_INFO("writerfilter.dmapper",
+                    "field argument with unterminated quote");
+        return OUString();
     }
     else
     {
-        nEndIndex = rCommand.indexOf(" \\", nStartIndex);
+        rHaveToken = !token.isEmpty();
+        return token.makeStringAndClear();
     }
-    OUString sRet;
-    if( nEndIndex > nStartIndex + 1 )
+}
+
+SAL_DLLPUBLIC_EXPORT // export just for test
+boost::tuple<OUString, vector<OUString>, vector<OUString> >
+lcl_SplitFieldCommand(const OUString& rCommand)
+{
+    OUString sType;
+    vector<OUString> arguments;
+    vector<OUString> switches;
+    sal_Int32 nStartIndex(0);
+
+    do
     {
-        //remove spaces at start and end of the result
-        if(nQuoteIndex <= 0)
+        bool bHaveToken;
+        bool bIsSwitch;
+        OUString const token =
+            lcl_ExtractToken(rCommand, nStartIndex, bHaveToken, bIsSwitch);
+        assert(nStartIndex <= rCommand.getLength());
+        if (bHaveToken)
         {
-            const sal_Unicode* pCommandStr = rCommand.getStr();
-            while( nStartIndex < nEndIndex && pCommandStr[nStartIndex] == ' ')
-                    ++nStartIndex;
-            while( nEndIndex > nStartIndex && pCommandStr[nEndIndex] == ' ')
-                    --nEndIndex;
+            if (sType.isEmpty())
+            {
+                sType = token.toAsciiUpperCase();
+            }
+            else if (bIsSwitch || !switches.empty())
+            {
+                switches.push_back(token);
+            }
+            else
+            {
+                arguments.push_back(token);
+            }
         }
-        sRet = rCommand.copy( nStartIndex, nEndIndex - nStartIndex + 1);
-    }
-    return sRet;
-}
+    } while (nStartIndex < rCommand.getLength());
 
+    return boost::make_tuple(sType, arguments, switches);
+}
 
 
 OUString lcl_ExctractAskVariableAndHint( const OUString& rCommand, OUString& rHint )
@@ -2480,7 +2577,7 @@ void DomainMapper_Impl::handleAutoNum
 }
 
 void DomainMapper_Impl::handleAuthor
-    (FieldContextPtr pContext,
+    (OUString const& rFirstParam,
     PropertyNameSupplier& rPropNameSupplier,
      uno::Reference< uno::XInterface > & /*xFieldInterface*/,
      uno::Reference< beans::XPropertySet > xFieldProperties,
@@ -2490,19 +2587,7 @@ void DomainMapper_Impl::handleAuthor
         xFieldProperties->setPropertyValue
             ( rPropNameSupplier.GetName(PROP_FULL_NAME), uno::makeAny( true ));
 
-    sal_Int32 nLen = sizeof( " AUTHOR" );
-    if ( eFieldId != FIELD_AUTHOR )
-    {
-        if (  eFieldId == FIELD_USERINITIALS )
-            nLen = sizeof( " USERINITIALS" );
-        else if (  eFieldId == FIELD_USERNAME )
-            nLen = sizeof( " USERNAME" );
-    }
-
-    OUString sParam =
-        lcl_ExtractParameter(pContext->GetCommand(), nLen );
-
-    if(!sParam.isEmpty())
+    if (!rFirstParam.isEmpty())
     {
         xFieldProperties->setPropertyValue(
                 rPropNameSupplier.GetName( PROP_IS_FIXED ),
@@ -2513,16 +2598,14 @@ void DomainMapper_Impl::handleAuthor
 
     void DomainMapper_Impl::handleDocProperty
         (FieldContextPtr pContext,
+        OUString const& rFirstParam,
         PropertyNameSupplier& rPropNameSupplier,
         uno::Reference< uno::XInterface > & xFieldInterface,
         uno::Reference< beans::XPropertySet > xFieldProperties)
 {
     //some docproperties should be imported as document statistic fields, some as DocInfo fields
     //others should be user fields
-    OUString sParam =
-        lcl_ExtractParameter(pContext->GetCommand(), sizeof(" DOCPROPERTY") );
-
-    if(!sParam.isEmpty())
+    if (!rFirstParam.isEmpty())
     {
         #define SET_ARABIC      0x01
         #define SET_FULL_NAME   0x02
@@ -2562,7 +2645,7 @@ void DomainMapper_Impl::handleAuthor
         for( ; nMap < sizeof(aDocProperties) / sizeof(DocPropertyMap);
             ++nMap )
         {
-            if(sParam.equalsAscii(aDocProperties[nMap].pDocPropertyName))
+            if (rFirstParam.equalsAscii(aDocProperties[nMap].pDocPropertyName))
             {
                 sFieldServiceName =
                 OUString::createFromAscii
@@ -2589,7 +2672,7 @@ void DomainMapper_Impl::handleAuthor
                 uno::UNO_QUERY_THROW);
         if( bIsCustomField )
             xFieldProperties->setPropertyValue(
-                rPropNameSupplier.GetName(PROP_NAME), uno::makeAny( sParam ));
+                rPropNameSupplier.GetName(PROP_NAME), uno::makeAny(rFirstParam));
         else
         {
             if(0 != (aDocProperties[nMap].nFlags & SET_ARABIC))
@@ -2889,13 +2972,14 @@ void DomainMapper_Impl::CloseFieldCommand()
         try
         {
             uno::Reference< uno::XInterface > xFieldInterface;
-            //at first determine the field type - erase leading and trailing whitespaces
-            OUString sCommand( pContext->GetCommand().trim() );
-            sal_Int32 nSpaceIndex = sCommand.indexOf( ' ' );
-            if( 0 <= nSpaceIndex )
-                sCommand = sCommand.copy(0, nSpaceIndex).toAsciiUpperCase();
 
-            FieldConversionMap_t::iterator aIt = aFieldConversionMap.find(sCommand);
+            boost::tuple<OUString, vector<OUString>, vector<OUString> > const
+                field(lcl_SplitFieldCommand(pContext->GetCommand()));
+            OUString const sFirstParam(boost::get<1>(field).empty()
+                    ? OUString() : boost::get<1>(field).front());
+
+            FieldConversionMap_t::iterator const aIt =
+                aFieldConversionMap.find(boost::get<0>(field));
             if(aIt != aFieldConversionMap.end())
             {
                 uno::Reference< beans::XPropertySet > xFieldProperties;
@@ -2937,7 +3021,8 @@ void DomainMapper_Impl::CloseFieldCommand()
                     if ( bCreateEnhancedField )
                     {
                         FieldConversionMap_t aEnhancedFieldConversionMap = lcl_GetEnhancedFieldConversion();
-                        FieldConversionMap_t::iterator aEnhancedIt = aEnhancedFieldConversionMap.find(sCommand);
+                        FieldConversionMap_t::iterator aEnhancedIt =
+                            aEnhancedFieldConversionMap.find(boost::get<0>(field));
                         if ( aEnhancedIt != aEnhancedFieldConversionMap.end())
                             sServiceName += OUString::createFromAscii(aEnhancedIt->second.cFieldServiceName );
                     }
@@ -2975,7 +3060,9 @@ void DomainMapper_Impl::CloseFieldCommand()
                     case FIELD_AUTHOR       :
                     case FIELD_USERNAME     :
                     case FIELD_USERINITIALS :
-                        handleAuthor(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties, aIt->second.eFieldId  );
+                        handleAuthor(sFirstParam, rPropNameSupplier,
+                            xFieldInterface, xFieldProperties,
+                            aIt->second.eFieldId);
                     break;
                     case FIELD_DATE:
                     if (xFieldProperties.is())
@@ -3014,14 +3101,14 @@ void DomainMapper_Impl::CloseFieldCommand()
                     }
                     break;
                     case FIELD_DOCPROPERTY :
-                        handleDocProperty(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties);
+                        handleDocProperty(pContext, sFirstParam, rPropNameSupplier,
+                                xFieldInterface, xFieldProperties);
                     break;
                     case FIELD_DOCVARIABLE  :
                     {
-                        OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" DOCVARIABLE") );
                         //create a user field and type
                         uno::Reference< beans::XPropertySet > xMaster =
-                            FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.User", sParam );
+                            FindOrCreateFieldMaster("com.sun.star.text.FieldMaster.User", sFirstParam);
                         uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
                         xDependentField->attachTextFieldMaster( xMaster );
                         m_bSetUserFieldContent = true;
@@ -3047,7 +3134,7 @@ void DomainMapper_Impl::CloseFieldCommand()
                         else
                         {
                             //merge Read_SubF_Ruby into filter/.../util.cxx and reuse that ?
-                            nSpaceIndex = aCommand.indexOf(' ');
+                            sal_Int32 nSpaceIndex = aCommand.indexOf(' ');
                             if(nSpaceIndex > 0)
                                 aCommand = aCommand.copy(nSpaceIndex).trim();
                             if (aCommand.startsWith("\\s"))
@@ -3178,8 +3265,7 @@ void DomainMapper_Impl::CloseFieldCommand()
                     case FIELD_INCLUDEPICTURE: break;
                     case FIELD_KEYWORDS     :
                     {
-                        OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" KEYWORDS") );
-                        if(!sParam.isEmpty())
+                        if (!sFirstParam.isEmpty())
                         {
                             xFieldProperties->setPropertyValue(
                                     rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
@@ -3209,10 +3295,9 @@ void DomainMapper_Impl::CloseFieldCommand()
                     case FIELD_MERGEFIELD  :
                     {
                         //todo: create a database field and fieldmaster pointing to a column, only
-                        OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" MERGEFIELD") );
                         //create a user field and type
                         uno::Reference< beans::XPropertySet > xMaster =
-                            FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.Database", sParam );
+                            FindOrCreateFieldMaster("com.sun.star.text.FieldMaster.Database", sFirstParam);
 
     //                    xFieldProperties->setPropertyValue(
     //                             "FieldCode",
@@ -3243,21 +3328,21 @@ void DomainMapper_Impl::CloseFieldCommand()
                     if (xFieldProperties.is())
                     {
                         bool bPageRef = aIt->second.eFieldId == FIELD_PAGEREF;
-                        OUString sBookmark = lcl_ExtractParameter(pContext->GetCommand(),
-                                (bPageRef ? sizeof(" PAGEREF") : sizeof(" REF")));
 
                         // Do we need a GetReference (default) or a GetExpression field?
                         uno::Reference< text::XTextFieldsSupplier > xFieldsSupplier( GetTextDocument(), uno::UNO_QUERY );
                         uno::Reference< container::XNameAccess > xFieldMasterAccess = xFieldsSupplier->getTextFieldMasters();
 
-                        if (!xFieldMasterAccess->hasByName("com.sun.star.text.FieldMaster.SetExpression." + sBookmark))
+                        if (!xFieldMasterAccess->hasByName(
+                                "com.sun.star.text.FieldMaster.SetExpression."
+                                + sFirstParam))
                         {
                         xFieldProperties->setPropertyValue(
                             rPropNameSupplier.GetName(PROP_REFERENCE_FIELD_SOURCE),
                             uno::makeAny( sal_Int16(text::ReferenceFieldSource::BOOKMARK)) );
                         xFieldProperties->setPropertyValue(
                             rPropNameSupplier.GetName(PROP_SOURCE_NAME),
-                            uno::makeAny( sBookmark) );
+                            uno::makeAny(sFirstParam) );
                         sal_Int16 nFieldPart = (bPageRef ? text::ReferenceFieldPart::PAGE : text::ReferenceFieldPart::TEXT);
                         OUString sValue;
                         if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue ))
@@ -3287,7 +3372,9 @@ void DomainMapper_Impl::CloseFieldCommand()
                         {
                             xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.TextField.GetExpression");
                             xFieldProperties.set(xFieldInterface, uno::UNO_QUERY);
-                            xFieldProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_CONTENT), uno::makeAny(sBookmark));
+                            xFieldProperties->setPropertyValue(
+                                rPropNameSupplier.GetName(PROP_CONTENT),
+                                uno::makeAny(sFirstParam));
                             xFieldProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING));
                         }
                     }
@@ -3354,8 +3441,7 @@ void DomainMapper_Impl::CloseFieldCommand()
                     case FIELD_STYLEREF     : break;
                     case FIELD_SUBJECT      :
                     {
-                        OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" SUBJECT") );
-                        if(!sParam.isEmpty())
+                        if (!sFirstParam.isEmpty())
                         {
                             xFieldProperties->setPropertyValue(
                                     rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
@@ -3370,8 +3456,7 @@ void DomainMapper_Impl::CloseFieldCommand()
                     break;
                     case FIELD_TITLE        :
                     {
-                        OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" TITLE") );
-                        if(!sParam.isEmpty())
+                        if (!sFirstParam.isEmpty())
                         {
                             xFieldProperties->setPropertyValue(
                                     rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
@@ -3391,10 +3476,11 @@ void DomainMapper_Impl::CloseFieldCommand()
                             m_xTextFactory->createInstance(
                                 OUString::createFromAscii(aIt->second.cFieldServiceName)),
                                 uno::UNO_QUERY_THROW);
-                        OUString sTCText = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" TC") );
-                        if( !sTCText.isEmpty())
+                        if (!sFirstParam.isEmpty())
+                        {
                             xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_ALTERNATIVE_TEXT),
-                                uno::makeAny(sTCText));
+                                uno::makeAny(sFirstParam));
+                        }
                         OUString sValue;
                         // \f TC entry in doc with multiple tables
     //                    if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue ))
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 1ebf067..4686baa 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -576,13 +576,14 @@ public:
         uno::Reference< uno::XInterface > & xFieldInterface,
         uno::Reference< beans::XPropertySet > xFieldProperties);
     void handleAuthor
-        (FieldContextPtr pContext,
+        (OUString const& rFirstParam,
         PropertyNameSupplier& rPropNameSupplier,
         uno::Reference< uno::XInterface > & xFieldInterface,
         uno::Reference< beans::XPropertySet > xFieldProperties,
         FieldId eFieldId);
     void handleDocProperty
         (FieldContextPtr pContext,
+        OUString const& rFirstParam,
         PropertyNameSupplier& rPropNameSupplier,
         uno::Reference< uno::XInterface > & xFieldInterface,
         uno::Reference< beans::XPropertySet > xFieldProperties);
commit ab0bf393720ba29d9caecb4df4270b267bc3ef64
Author: Tor Lillqvist <tml at collabora.com>
Date:   Wed Mar 5 10:30:21 2014 +0200

    Drop el for now because it is broken and crashes HelpLinker
    
    Change-Id: I3c79d58a35bcf9788f1e4ef18fa14cb983b7c8e6

diff --git a/distro-configs/CPOSX.conf b/distro-configs/CPOSX.conf
index c1dea82..2e31ca8 100644
--- a/distro-configs/CPOSX.conf
+++ b/distro-configs/CPOSX.conf
@@ -17,4 +17,4 @@
 --enable-ext-google-docs
 --enable-ext-languagetool
 --enable-release-build
---with-lang=ar as ast bg bn-IN br ca ca-valencia cy cs da de el en-US en-GB es et eu fi fr ga gd gl gu he hi hr hu id is it ja km kn ko lt lv ml mr nb nl nn oc or pa-IN pl pt pt-BR ro ru sk sl sr sv ta te tr uk vi zh-CN zh-TW
+--with-lang=ar as ast bg bn-IN br ca ca-valencia cy cs da de en-US en-GB es et eu fi fr ga gd gl gu he hi hr hu id is it ja km kn ko lt lv ml mr nb nl nn oc or pa-IN pl pt pt-BR ro ru sk sl sr sv ta te tr uk vi zh-CN zh-TW


More information about the Libreoffice-commits mailing list