filter/source/msfilter/util.cxx | 19 +++++++++++++++++++ include/filter/msfilter/util.hxx | 2 ++ sw/source/filter/ww8/wrtw8sty.cxx | 15 +-------------- writerfilter/source/dmapper/DomainMapper_Impl.cxx | 15 ++------------- 4 files changed, 24 insertions(+), 27 deletions(-)
New commits: commit 0fafc03c24996ccd53dbf76eaab372779cfbca90 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Tue Feb 7 14:12:54 2023 +0100 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Tue Feb 7 15:17:30 2023 +0000 tdf#153083 writerfilter,sw: consolidate StyleName->StyleId in msfilter Turns out there was already a function MSWordStyles::CreateStyleId() doing the same thing as FilterChars(), presumably better. Change-Id: Idd0129c753841b86bd026e1300aa57a56721c89e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146609 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/filter/source/msfilter/util.cxx b/filter/source/msfilter/util.cxx index aea2f816bde9..32783f2c42f8 100644 --- a/filter/source/msfilter/util.cxx +++ b/filter/source/msfilter/util.cxx @@ -10,6 +10,7 @@ #include <com/sun/star/awt/Size.hpp> #include <com/sun/star/lang/Locale.hpp> #include <rtl/ustring.hxx> +#include <rtl/character.hxx> #include <comphelper/string.hxx> #include <unotools/fontcvt.hxx> #include <unotools/fontdefs.hxx> @@ -311,6 +312,24 @@ const ApiPaperSize& PaperSizeConv::getApiSizeForMSPaperSizeIndex( sal_Int32 nMSO return spPaperSizeTable[ nMSOPaperIndex ]; } +OUString CreateDOCXStyleId(std::u16string_view const aName) +{ + OUStringBuffer aStyleIdBuf(aName.size()); + for (size_t i = 0; i < aName.size(); ++i) + { + sal_Unicode nChar = aName[i]; + if (rtl::isAsciiAlphanumeric(nChar) || nChar == '-') + { + // first letter should be uppercase + if (aStyleIdBuf.isEmpty()) + aStyleIdBuf.append(char(rtl::toAsciiUpperCase(nChar))); + else + aStyleIdBuf.append(char(nChar)); + } + } + return aStyleIdBuf.makeStringAndClear(); +} + std::u16string_view findQuotedText( std::u16string_view rCommand, const char* cStartQuote, const sal_Unicode uEndQuote ) { diff --git a/include/filter/msfilter/util.hxx b/include/filter/msfilter/util.hxx index 3dd7c88843d0..b9b92ba930ef 100644 --- a/include/filter/msfilter/util.hxx +++ b/include/filter/msfilter/util.hxx @@ -79,6 +79,8 @@ public: static const ApiPaperSize& getApiSizeForMSPaperSizeIndex( sal_Int32 nMSOPaperIndex ); }; +MSFILTER_DLLPUBLIC OUString CreateDOCXStyleId(std::u16string_view aName); + /** * Finds the quoted text in a field instruction text. * diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx index 2954a94c239c..c520cd867772 100644 --- a/sw/source/filter/ww8/wrtw8sty.cxx +++ b/sw/source/filter/ww8/wrtw8sty.cxx @@ -423,20 +423,7 @@ void MSWordStyles::BuildWwNames() OString MSWordStyles::CreateStyleId(std::u16string_view aName) { - OStringBuffer aStyleIdBuf(aName.size()); - for (size_t i = 0; i < aName.size(); ++i) - { - sal_Unicode nChar = aName[i]; - if (rtl::isAsciiAlphanumeric(nChar) || nChar == '-') - { - // first letter should be uppercase - if (aStyleIdBuf.isEmpty()) - aStyleIdBuf.append(char(rtl::toAsciiUpperCase(nChar))); - else - aStyleIdBuf.append(char(nChar)); - } - } - return aStyleIdBuf.makeStringAndClear(); + return OUStringToOString(msfilter::util::CreateDOCXStyleId(aName), RTL_TEXTENCODING_UTF8); } void MSWordStyles::BuildStyleIds() diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 8c424e12dda8..485a9399a7c7 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -89,7 +89,6 @@ #include <oox/mathml/imexport.hxx> #include <utility> #include <xmloff/odffields.hxx> -#include <rtl/character.hxx> #include <rtl/uri.hxx> #include <unotools/ucbstreamhelper.hxx> #include <unotools/streamwrap.hxx> @@ -6139,19 +6138,9 @@ DomainMapper_Impl::StartIndexSectionChecked(const OUString& sServiceName) Hopefully this works and a complete map of >100 built-in style names localised to all languages isn't needed. */ -static auto FilterChars(OUString const& rStyleName) -> OUString +static auto FilterChars(std::u16string_view const& rStyleName) -> OUString { - OUStringBuffer ret; - sal_Int32 index(0); - while (index < rStyleName.getLength()) - { - auto const c(rStyleName.iterateCodePoints(&index)); - if (rtl::isAsciiAlphanumeric(c)) - { - ret.appendUtf32(c); - } - } - return ret.makeStringAndClear(); + return msfilter::util::CreateDOCXStyleId(rStyleName); } OUString DomainMapper_Impl::ConvertTOCStyleName(OUString const& rTOCStyleName)