[Libreoffice-commits] core.git: include/unotools unotools/source vcl/source
include/unotools/datetime.hxx |2 +- include/unotools/fontdefs.hxx |2 +- unotools/source/misc/datetime.cxx | 14 +++--- unotools/source/misc/fontdefs.cxx |6 +++--- vcl/source/font/PhysicalFontCollection.cxx |4 ++-- vcl/source/font/fontmetric.cxx |2 +- 6 files changed, 15 insertions(+), 15 deletions(-) New commits: commit ca1027e7d3a47402a016dba26d12db93b097a856 Author: Noel Grandin AuthorDate: Thu Apr 21 16:08:20 2022 +0200 Commit: Noel Grandin CommitDate: Fri Apr 22 13:29:40 2022 +0200 use more string_view in unotools Change-Id: If32767647d3fba22a8e4a2b10fc57f47efca01d2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133270 Tested-by: Jenkins Reviewed-by: Noel Grandin diff --git a/include/unotools/datetime.hxx b/include/unotools/datetime.hxx index afb06bc652a1..368ffcb393f9 100644 --- a/include/unotools/datetime.hxx +++ b/include/unotools/datetime.hxx @@ -48,7 +48,7 @@ namespace utl UNOTOOLS_DLLPUBLIC void typeConvert(const css::util::DateTime& _rDateTime, DateTime& _rOut); UNOTOOLS_DLLPUBLIC OUString toISO8601(const css::util::DateTime& _rDateTime); -UNOTOOLS_DLLPUBLIC boolISO8601parseDateTime(const OUString &i_rIn, css::util::DateTime& o_rDateTime); +UNOTOOLS_DLLPUBLIC bool ISO8601parseDateTime(std::u16string_view i_rIn, css::util::DateTime& o_rDateTime); UNOTOOLS_DLLPUBLIC boolISO8601parseDate(std::u16string_view i_rIn, css::util::Date& o_rDate); UNOTOOLS_DLLPUBLIC boolISO8601parseTime(std::u16string_view i_rIn, css::util::Time& o_Time); diff --git a/include/unotools/fontdefs.hxx b/include/unotools/fontdefs.hxx index f5ff03efc837..7f145eba309e 100644 --- a/include/unotools/fontdefs.hxx +++ b/include/unotools/fontdefs.hxx @@ -84,7 +84,7 @@ enum class DefaultFontType CTL_DISPLAY = 4004, }; -UNOTOOLS_DLLPUBLIC OUString GetNextFontToken( const OUString& rTokenStr, sal_Int32& rIndex ); +UNOTOOLS_DLLPUBLIC std::u16string_view GetNextFontToken( const OUString& rTokenStr, sal_Int32& rIndex ); UNOTOOLS_DLLPUBLIC OUString GetEnglishSearchFontName( std::u16string_view rName ); /** Strip any "script font suffix" from the font name diff --git a/unotools/source/misc/datetime.cxx b/unotools/source/misc/datetime.cxx index f1b1d6a8a33e..db7216ffa268 100644 --- a/unotools/source/misc/datetime.cxx +++ b/unotools/source/misc/datetime.cxx @@ -303,25 +303,25 @@ OUString toISO8601(const css::util::DateTime& rDateTime) } /** convert ISO8601 DateTime String to util::DateTime */ -bool ISO8601parseDateTime(const OUString &rString, css::util::DateTime& rDateTime) +bool ISO8601parseDateTime(std::u16string_view rString, css::util::DateTime& rDateTime) { bool bSuccess = true; -OUString aDateStr, aTimeStr; +std::u16string_view aDateStr, aTimeStr; css::util::Date aDate; css::util::Time aTime; -sal_Int32 nPos = rString.indexOf( 'T' ); -if ( nPos >= 0 ) +size_t nPos = rString.find( 'T' ); +if ( nPos != std::u16string_view::npos ) { -aDateStr = rString.copy( 0, nPos ); -aTimeStr = rString.copy( nPos + 1 ); +aDateStr = rString.substr( 0, nPos ); +aTimeStr = rString.substr( nPos + 1 ); } else aDateStr = rString; // no separator: only date part bSuccess = ISO8601parseDate(aDateStr, aDate); -if ( bSuccess && !aTimeStr.isEmpty() ) // time is optional +if ( bSuccess && !aTimeStr.empty() ) // time is optional { bSuccess = ISO8601parseTime(aTimeStr, aTime); } diff --git a/unotools/source/misc/fontdefs.cxx b/unotools/source/misc/fontdefs.cxx index 9015f93e9de6..4a07087fd71f 100644 --- a/unotools/source/misc/fontdefs.cxx +++ b/unotools/source/misc/fontdefs.cxx @@ -457,14 +457,14 @@ OUString GetEnglishSearchFontName(std::u16string_view rInName) return rNameStr; } -OUString GetNextFontToken( const OUString& rTokenStr, sal_Int32& rIndex ) +std::u16string_view GetNextFontToken( const OUString& rTokenStr, sal_Int32& rIndex ) { // check for valid start index sal_Int32 nStringLen = rTokenStr.getLength(); if( rIndex >= nStringLen ) { rIndex = -1; -return OUString(); +return {}; } // find the next token delimiter and return the token substring @@ -498,7 +498,7 @@ OUString GetNextFontToken( const OUString& rTokenStr, sal_Int32& rIndex ) } } -return rTokenStr.copy( nTokenStart, nTokenLen ); +return rTokenStr.subView( nTokenStart, nTokenLen ); } static bool ImplIsFontToken( const OUString& rName, std::u16string_view rToken ) diff --git a/vcl/source/font/PhysicalFontCollection.cxx b/vcl/source/font/PhysicalFontCollection.cxx index 139e4f133e88..6a1b35372952 100644 --- a/vcl/source/font/PhysicalFontCollection.cxx +++ b/vcl/source/font/PhysicalFontCollection.
[Libreoffice-commits] core.git: include/unotools unotools/source vcl/source
include/unotools/ucbstreamhelper.hxx | 15 +-- unotools/source/ucbhelper/ucbstreamhelper.cxx | 34 +- vcl/source/graphic/GraphicLoader.cxx |4 +-- 3 files changed, 26 insertions(+), 27 deletions(-) New commits: commit 7c9d8afd913c17100aa4185e3b044137f225c81f Author: Noel Grandin Date: Wed Apr 25 10:22:25 2018 +0200 Revert "make UcbStreamHelper return SvStream by std::unique_ptr" This reverts commit eeefb8c440b514cefdc4e82cc06843da9eabeb13. this was pushed in error diff --git a/include/unotools/ucbstreamhelper.hxx b/include/unotools/ucbstreamhelper.hxx index d89048500bcd..68309d094acf 100644 --- a/include/unotools/ucbstreamhelper.hxx +++ b/include/unotools/ucbstreamhelper.hxx @@ -25,7 +25,6 @@ #include #include -#include namespace com { @@ -53,13 +52,13 @@ namespace utl class UNOTOOLS_DLLPUBLIC UcbStreamHelper { public: -static std::unique_ptr CreateStream( const OUString& rFileName, StreamMode eOpenMode ); -static std::unique_ptr CreateStream( const OUString& rFileName, StreamMode eOpenMode, - bool bFileExists ); -static std::unique_ptr CreateStream( const css::uno::Reference < css::io::XInputStream >& xStream ); -static std::unique_ptr CreateStream( const css::uno::Reference < css::io::XStream >& xStream ); -static std::unique_ptr CreateStream( const css::uno::Reference < css::io::XInputStream >& xStream, bool bCloseStream ); -static std::unique_ptr CreateStream( const css::uno::Reference < css::io::XStream >& xStream, bool bCloseStream ); +static SvStream*CreateStream( const OUString& rFileName, StreamMode eOpenMode ); +static SvStream*CreateStream( const OUString& rFileName, StreamMode eOpenMode, + bool bFileExists ); +static SvStream*CreateStream( const css::uno::Reference < css::io::XInputStream >& xStream ); +static SvStream*CreateStream( const css::uno::Reference < css::io::XStream >& xStream ); +static SvStream*CreateStream( const css::uno::Reference < css::io::XInputStream >& xStream, bool bCloseStream ); +static SvStream*CreateStream( const css::uno::Reference < css::io::XStream >& xStream, bool bCloseStream ); }; } diff --git a/unotools/source/ucbhelper/ucbstreamhelper.cxx b/unotools/source/ucbhelper/ucbstreamhelper.cxx index 87f7d903a481..63260f632b91 100644 --- a/unotools/source/ucbhelper/ucbstreamhelper.cxx +++ b/unotools/source/ucbhelper/ucbstreamhelper.cxx @@ -42,11 +42,11 @@ using namespace ::com::sun::star::beans; namespace utl { -static std::unique_ptr lcl_CreateStream( const OUString& rFileName, StreamMode eOpenMode, +static SvStream* lcl_CreateStream( const OUString& rFileName, StreamMode eOpenMode, const Reference < XInteractionHandler >& xInteractionHandler, bool bEnsureFileExists ) { -std::unique_ptr pStream; +SvStream* pStream = nullptr; UcbLockBytesRef xLockBytes; if ( eOpenMode & StreamMode::WRITE ) { @@ -119,7 +119,7 @@ static std::unique_ptr lcl_CreateStream( const OUString& rFileName, St eOpenMode, xInteractionHandler ); if ( xLockBytes.is() ) { -pStream.reset(new SvStream( xLockBytes.get() )); +pStream = new SvStream( xLockBytes.get() ); pStream->SetBufferSize( 4096 ); pStream->SetError( xLockBytes->GetError() ); } @@ -137,7 +137,7 @@ static std::unique_ptr lcl_CreateStream( const OUString& rFileName, St return pStream; } -std::unique_ptr UcbStreamHelper::CreateStream( const OUString& rFileName, StreamMode eOpenMode ) +SvStream* UcbStreamHelper::CreateStream( const OUString& rFileName, StreamMode eOpenMode ) { // related tdf#99312 // create a specialized interaction handler to manages Web certificates and Web credentials when needed @@ -149,7 +149,7 @@ std::unique_ptr UcbStreamHelper::CreateStream( const OUString& rFileNa return lcl_CreateStream( rFileName, eOpenMode, xIHScoped, true /* bEnsureFileExists */ ); } -std::unique_ptr UcbStreamHelper::CreateStream( const OUString& rFileName, StreamMode eOpenMode, +SvStream* UcbStreamHelper::CreateStream( const OUString& rFileName, StreamMode eOpenMode, bool bFileExists ) { // related tdf#99312 @@ -162,13 +162,13 @@ std::unique_ptr UcbStreamHelper::CreateStream( const OUString& rFileNa } -std::unique_ptr UcbStreamHelper::CreateStream( const Reference < XInputStream >& xStream ) +SvStream* UcbStreamHelper::CreateStream( const Reference < XInputStream >& xStream ) { -std::unique_ptr pStream; +SvStream* pStream = nullptr; UcbLockBytesRef xLockBytes = UcbLockBytes::Crea
[Libreoffice-commits] core.git: include/unotools unotools/source vcl/source
include/unotools/fontdefs.hxx |9 +++ unotools/source/misc/fontdefs.cxx | 67 - vcl/source/font/PhysicalFontCollection.cxx | 36 --- 3 files changed, 48 insertions(+), 64 deletions(-) New commits: commit e12ba2eddc827e39444f5efe6107d8afe1f7aaff Author: Caolán McNamara Date: Mon Oct 20 11:17:56 2014 +0100 Resolves: fdo#85006 limit script stripping to known suffixes Change-Id: I276535b007bbb5148d5937076b86da5de825 diff --git a/include/unotools/fontdefs.hxx b/include/unotools/fontdefs.hxx index 7ac715e..e060106 100644 --- a/include/unotools/fontdefs.hxx +++ b/include/unotools/fontdefs.hxx @@ -83,6 +83,15 @@ UNOTOOLS_DLLPUBLIC OUString GetNextFontToken( const OUString& rTokenStr, sal_Int UNOTOOLS_DLLPUBLIC OUString GetEnglishSearchFontName( const OUString& rName ); +/** Strip any "script font suffix" from the font name + +Related: fdo#49271 RTF files often contain weird-ass +Win 3.1/Win95 style fontnames which attempt to put the +charset encoding into the filename +http://www.webcenter.ru/~kazarn/eng/fonts_ttf.htm +*/ +UNOTOOLS_DLLPUBLIC OUString StripScriptFromName(const OUString& rName); + /** Determine if the font is the special Star|Open Symbol font @param rFontName diff --git a/unotools/source/misc/fontdefs.cxx b/unotools/source/misc/fontdefs.cxx index 4f0fb08..cac720f 100644 --- a/unotools/source/misc/fontdefs.cxx +++ b/unotools/source/misc/fontdefs.cxx @@ -320,9 +320,43 @@ static ImplLocalizedFontName aImplLocalizedNamesList[] = { NULL, NULL }, }; -OUString GetEnglishSearchFontName( const OUString& rInName ) +OUString StripScriptFromName(const OUString& _aName) { -OUStringBuffer rName( rInName.getStr()); +// I worry that someone will have a font which *does* have +// e.g. "Greek" legitimately at the end of its name :-( +const char*suffixes[] = { " baltic", + " ce", + " cyr", + " greek", + " tur", + " (arabic)", + " (hebrew)", + " (thai)", + " (vietnamese)" +}; + +OUString aName = _aName; +// These can be crazily piled up, e.g. Times New Roman CYR Greek +bool bFinished = false; +while (!bFinished) +{ +bFinished = true; +for (size_t i = 0; i < SAL_N_ELEMENTS(suffixes); ++i) +{ +size_t nLen = strlen(suffixes[i]); +if (aName.endsWithIgnoreAsciiCaseAsciiL(suffixes[i], nLen)) +{ +bFinished = false; +aName = aName.copy(0, aName.getLength() - nLen); +} +} +} +return aName; +} + +OUString GetEnglishSearchFontName(const OUString& rInName) +{ +OUStringBuffer rName(rInName); boolbNeedTranslation = false; sal_Int32 nLen = rName.getLength(); @@ -334,33 +368,8 @@ OUString GetEnglishSearchFontName( const OUString& rInName ) rName.truncate(i); // Remove Script at the end -// Scriptname must be the last part of the fontname and -// looks like "fontname (scriptname)". So there can only be a -// script name at the end of the fontname, when the last char is ')' -if ( (nLen >= 3) && rName[ nLen-1 ] == ')' ) -{ -int nOpen = 1; -sal_Int32 nTempLen = nLen-2; -while ( nTempLen ) -{ -if ( rName[ nTempLen ] == '(' ) -{ -nOpen--; -if ( !nOpen ) -{ -// Remove Space at the end -if ( nTempLen && (rName[ nTempLen-1 ] == ' ') ) -nTempLen--; -rName.truncate(nTempLen); -nLen = nTempLen; -break; -} -} -if ( rName[ nTempLen ] == ')' ) -nOpen++; -nTempLen--; -} -} +rName = StripScriptFromName(rName.toString()); +nLen = rName.getLength(); // remove all whitespaces and converts to lower case ASCII // TODO: better transliteration to ASCII e.g. all digits diff --git a/vcl/source/font/PhysicalFontCollection.cxx b/vcl/source/font/PhysicalFontCollection.cxx index af2440c..416cc6b 100644 --- a/vcl/source/font/PhysicalFontCollection.cxx +++ b/vcl/source/font/PhysicalFontCollection.cxx @@ -36,40 +36,6 @@ #include "PhysicalFontCollection.hxx" -static OUString lcl_stripCharSetFromName(const OUString& _aName) -{ -// I worry that someone will have a font which *does* have -// e.g. "Greek" legitimately at the end of its name :-( -const char*suffixes[] = { " baltic", - " ce", - " cyr", - " greek", -