diff options
-rw-r--r-- | include/rtl/ustring.h | 4 | ||||
-rw-r--r-- | include/rtl/ustring.hxx | 4 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf111964.docx | bin | 0 -> 1481 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 10 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 28 |
5 files changed, 43 insertions, 3 deletions
diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h index 831ecd66d9be..50dbd75a5ecc 100644 --- a/include/rtl/ustring.h +++ b/include/rtl/ustring.h @@ -2023,7 +2023,9 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_newToAsciiUpperCase( string. The new string results from removing all characters with values less than - or equal to 32 (the space character) form both ends of str. + or equal to 32 (the space character), and also Unicode General Punctuation + area Space and some Control characters, form both ends of str (see + rtl_ImplIsWhitespace). This function cannot be used for language-specific conversion. The new string does not necessarily have a reference count of 1 (in cases where diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index 337e8509a53d..bc87c2936eef 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -2635,7 +2635,9 @@ public: of the string. All characters that have codes less than or equal to - 32 (the space character) are considered to be white space. + 32 (the space character), and Unicode General Punctuation area Space + and some Control characters are considered to be white space (see + rtl_ImplIsWhitespace). If the string doesn't contain white spaces at both ends, then the new string is assigned with str. diff --git a/sw/qa/extras/ooxmlexport/data/tdf111964.docx b/sw/qa/extras/ooxmlexport/data/tdf111964.docx Binary files differnew file mode 100644 index 000000000000..7cb85a1d87df --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf111964.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index b2c8a417109c..8c1537ffc268 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -384,6 +384,16 @@ DECLARE_OOXMLEXPORT_TEST(testTdf107684, "tdf107684.odt") assertXPath(pXmlDoc, "//w:style[@w:styleId='Heading1']/w:pPr/w:outlineLvl", 1); } +DECLARE_OOXMLEXPORT_TEST(testTdf111964, "tdf111964.docx") +{ + xmlDocPtr pXmlDoc = parseExport("word/document.xml"); + if (!pXmlDoc) + return; + // Unicode spaces that are not XML whitespace must not be trimmed + const sal_Unicode sWSReference [] { 0x2002, 0x2002, 0x2002, 0x2002, 0x2002, 0 }; + assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[4]/w:t", sWSReference); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index bb59ed9bebdc..1485ce0ed177 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -620,6 +620,32 @@ void OOXMLFastContextHandler::endTxbxContent() mpParserState->endTxbxContent(); } +namespace { +// XML schema defines white space as one of four characters: +// #x9 (tab), #xA (line feed), #xD (carriage return), and #x20 (space) +bool IsXMLWhitespace(sal_Unicode cChar) +{ + return cChar == 0x9 || cChar == 0xA || cChar == 0xD || cChar == 0x20; +} + +OUString TrimXMLWhitespace(const OUString & sText) +{ + sal_Int32 nTrimmedStart = 0; + const sal_Int32 nLen = sText.getLength(); + sal_Int32 nTrimmedEnd = nLen - 1; + while (nTrimmedStart < nLen && IsXMLWhitespace(sText[nTrimmedStart])) + ++nTrimmedStart; + while (nTrimmedStart <= nTrimmedEnd && IsXMLWhitespace(sText[nTrimmedEnd])) + --nTrimmedEnd; + if ((nTrimmedStart == 0) && (nTrimmedEnd == nLen - 1)) + return sText; + else if (nTrimmedStart > nTrimmedEnd) + return OUString(); + else + return sText.copy(nTrimmedStart, nTrimmedEnd-nTrimmedStart+1); +} +} + void OOXMLFastContextHandler::text(const OUString & sText) { if (isForwardEvents()) @@ -631,7 +657,7 @@ void OOXMLFastContextHandler::text(const OUString & sText) // tabs are converted to spaces if (!IsPreserveSpace()) { - sNormalizedText = sNormalizedText.trim().replaceAll("\t", " "); + sNormalizedText = TrimXMLWhitespace(sNormalizedText).replaceAll("\t", " "); } mpStream->utext(reinterpret_cast < const sal_uInt8 * > (sNormalizedText.getStr()), |