[Libreoffice-commits] core.git: include/rtl

2023-12-04 Thread Stephan Bergmann (via logerrit)
 include/rtl/strbuf.hxx  |2 +-
 include/rtl/string.hxx  |2 +-
 include/rtl/stringutils.hxx |2 +-
 include/rtl/ustrbuf.hxx |2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 312efd56ea810063848841df951aa13aa5859bbb
Author: Stephan Bergmann 
AuthorDate: Mon Dec 4 13:35:38 2023 +0100
Commit: Stephan Bergmann 
CommitDate: Mon Dec 4 15:16:23 2023 +0100

At least VS 2022 Preview 17.9.0 Preview 1.1 needs the fix too

...from 3c6de7e20e35e37cbddd2d35e065525616deac00 "Fix build against VS 2022
17.7.5"

Change-Id: I765db22aba2823e6d9a38282ac53e9ba5bcff092
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160309
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 56f3e2abcc38..5fa769241444 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -122,7 +122,7 @@ public:
 explicit OStringBuffer(bool) = delete;
 explicit OStringBuffer(char) = delete;
 explicit OStringBuffer(wchar_t) = delete;
-#if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1938 && defined 
_MANAGED)
+#if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1939 && defined 
_MANAGED)
 explicit OStringBuffer(char8_t) = delete;
 #endif
 explicit OStringBuffer(char16_t) = delete;
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 55b83d675d8d..ce683beb5e60 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -102,7 +102,7 @@ public:
 std::copy_n(literal, N, more.buffer);
 }
 
-#if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1938 && defined 
_MANAGED)
+#if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1939 && defined 
_MANAGED)
 #if HAVE_CPP_CONSTEVAL
 consteval
 #else
diff --git a/include/rtl/stringutils.hxx b/include/rtl/stringutils.hxx
index 3cd66ee6c146..622542c7dab8 100644
--- a/include/rtl/stringutils.hxx
+++ b/include/rtl/stringutils.hxx
@@ -247,7 +247,7 @@ struct ConstCharArrayDetector< const char[ 1 ], T >
 #endif
 
 #if defined LIBO_INTERNAL_ONLY \
-&& !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1938 && defined 
_MANAGED)
+&& !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1939 && defined 
_MANAGED)
 template
 struct ConstCharArrayDetector {
 using Type = T;
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index f41e34aa9d5d..30aa1959a67d 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -124,7 +124,7 @@ public:
 explicit OUStringBuffer(bool) = delete;
 explicit OUStringBuffer(char) = delete;
 explicit OUStringBuffer(wchar_t) = delete;
-#if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1938 && defined 
_MANAGED)
+#if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1939 && defined 
_MANAGED)
 explicit OUStringBuffer(char8_t) = delete;
 #endif
 explicit OUStringBuffer(char16_t) = delete;


[Libreoffice-commits] core.git: include/rtl sal/qa sal/rtl

2023-11-03 Thread Stephan Bergmann (via logerrit)
 include/rtl/uri.h  |5 +
 sal/qa/rtl/uri/rtl_testuri.cxx |   41 +
 sal/rtl/uri.cxx|3 ++-
 3 files changed, 48 insertions(+), 1 deletion(-)

New commits:
commit cef555e9a43b2cf1f46763b768973f89c5c1b053
Author: Stephan Bergmann 
AuthorDate: Fri Nov 3 16:07:44 2023 +0100
Commit: Stephan Bergmann 
CommitDate: Fri Nov 3 17:26:58 2023 +0100

Make ExternalReferenceUriTranslator more robust against broken UTF-8



"CppunitTest_stoc_uriproc failed on Windows" reports that
translateToExternal("file:///abc/%feef") produces an empty string 
(indicating
failure) instead of "file:///abc/%FEef" (as expected in
stoc/test/uriproc/test_uriproc.cxx) when osl_getThreadTextEncoding() is 
Shift
JIS.

This was due to how the call to rtl::Uri::encode in
Translator::translateToExternal (in
stoc/source/uriproc/ExternalUriReferenceTranslator.cxx) behaved:  It 
internally
interpreted its input "%FE" as the single-byte Shift JIS character 0xFE.  
Which
gets mapped to U+2122 as an extension (see "APPLE additions over SJIS, we
convert this like Apple, because I think, this gives better result, then 
[sic]
we take a replacement char" in sal/textenc/tcvtjp6.tab) in readUcs4, but 
which
in turn doesn't get mapped back to any Shift JIS character in 
writeEscapeChar.

Translator::translateToExternal is the only user of
rtl_UriEncodeStrictKeepEscapes, as introduced by
6ff5d3341dbc5df3f0cb5368ccb0e1089338916c "INTEGRATION: CWS c07v013_SRC680
(1.4.40); FILE MERGED: 2007/06/21 13:00:56 sb 1.4.40.1: #b6550116# Made
XExternalUriReferenceTranslator.translateToExternal more robust when the 
input
URL contains spurious non--UTF-8 octets like %FE (which are now copied 
verbatim,
instead of signalling error)."

To make the claim true that such "spurious non--UTF-8 octets like %FE" are
always "copied verbatim", regardless of text encoding being used, repurpose
rtl_UriEncodeStrictKeepEscapes to always treat any escape sequences that are
present as (potentially broken) UTF-8.

Change-Id: I0fa0b14d3e3d44e4b5514e1b73c84c407a947ce9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/15
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/uri.h b/include/rtl/uri.h
index 1fbd0128ab89..28975060c03e 100644
--- a/include/rtl/uri.h
+++ b/include/rtl/uri.h
@@ -174,6 +174,11 @@ typedef enum
 /** Like rtl_UriEncodeKeepEscapes, but indicating failure when converting
 unmappable characters.
 
+Also, any escape sequences that are present are always considered to 
be (potentially broken)
+UTF-8.  This mechanism is meant to be used on the result of a 
rtl_UriDecodeToIuri decoding,
+which will thus only contain escape sequences representing either 
ASCII characters or broken
+UTF-8 sequences, and which will all be kept as-is.
+
 @since UDK 3.2.7
  */
 rtl_UriEncodeStrictKeepEscapes,
diff --git a/sal/qa/rtl/uri/rtl_testuri.cxx b/sal/qa/rtl/uri/rtl_testuri.cxx
index 6389f0222418..2686d3607d37 100644
--- a/sal/qa/rtl/uri/rtl_testuri.cxx
+++ b/sal/qa/rtl/uri/rtl_testuri.cxx
@@ -495,6 +495,47 @@ void Test::test_Uri() {
 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
 RTL_TEXTENCODING_ISO_8859_5));
 }
+
+CPPUNIT_ASSERT_EQUAL(
+u"%80"_ustr,
+rtl::Uri::encode(
+u"%80"_ustr, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
+RTL_TEXTENCODING_ASCII_US));
+CPPUNIT_ASSERT_EQUAL(
+u"%80"_ustr,
+rtl::Uri::encode(
+u"%80"_ustr, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
+RTL_TEXTENCODING_ISO_8859_1));
+CPPUNIT_ASSERT_EQUAL(
+u"%80"_ustr,
+rtl::Uri::encode(
+u"%80"_ustr, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
+RTL_TEXTENCODING_UTF8));
+CPPUNIT_ASSERT_EQUAL(
+u"%80"_ustr,
+rtl::Uri::encode(
+u"%80"_ustr, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
+RTL_TEXTENCODING_SHIFT_JIS));
+CPPUNIT_ASSERT_EQUAL(
+u"%FE"_ustr,
+rtl::Uri::encode(
+u"%FE"_ustr, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
+RTL_TEXTENCODING_ASCII_US));
+CPPUNIT_ASSERT_EQUAL(
+u"%FE"_ustr,
+rtl::Uri::encode(
+u"%FE"_ustr, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
+RTL_TEXTENCODING_ISO_8859_1));
+CPPUNIT_ASSERT_EQUAL(
+u"%FE"_ustr,
+rtl::Uri::encode(
+u"%FE"_ustr, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
+RTL_TEXTENCODING_UTF8));
+CPPUNIT_ASSERT_EQUAL(
+u"%FE"_ustr,
+rtl::Uri::encode(
+   

[Libreoffice-commits] core.git: include/rtl

2023-10-27 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.h  |8 
 include/rtl/ustring.h |8 
 2 files changed, 16 deletions(-)

New commits:
commit 30027d95f96e8732292391721da8d126c8896fec
Author: Stephan Bergmann 
AuthorDate: Fri Oct 27 11:56:14 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Oct 27 15:50:09 2023 +0200

Step 2 of removing cargo-cult pragma pack around rtl_[u]String

see 8ae3ae4bf75fdd0aaa132c956d9da029baa3adc6 "Step 1 of removing cargo-cult
pragma pack around rtl_[u]String"

Change-Id: Ie9140b92da8895c4991a7f449359bb1747fdb23d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158553
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.h b/include/rtl/string.h
index 854a83832c99..26f361529771 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -864,10 +864,6 @@ SAL_DLLPUBLIC double SAL_CALL rtl_str_toDouble(
 
 /* === */
 
-#ifdef _WIN32
-#   pragma pack(push, 8)
-#endif
-
 /** @cond INTERNAL */
 /** The implementation of a byte string.
  */
@@ -879,10 +875,6 @@ typedef struct _rtl_String
 } rtl_String;
 /** @endcond */
 
-#if defined(_WIN32)
-#pragma pack(pop)
-#endif
-
 /* --- */
 
 /** Increment the reference count of a string.
diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h
index da4278e5a683..303aff446023 100644
--- a/include/rtl/ustring.h
+++ b/include/rtl/ustring.h
@@ -1194,10 +1194,6 @@ SAL_DLLPUBLIC double SAL_CALL rtl_ustr_toDouble(
 
 /* === */
 
-#if defined(_WIN32)
-#pragma pack(push, 4)
-#endif
-
 /** @cond INTERNAL */
 /** The implementation of a Unicode string.
 */
@@ -1209,10 +1205,6 @@ typedef struct SAL_DLLPUBLIC_RTTI _rtl_uString
 } rtl_uString;
 /** @endcond */
 
-#if defined(_WIN32)
-#pragma pack(pop)
-#endif
-
 /* --- */
 
 /** Increment the reference count of a string.


[Libreoffice-commits] core.git: include/rtl

2023-10-19 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx  |   13 -
 include/rtl/ustring.hxx |7 ++-
 2 files changed, 6 insertions(+), 14 deletions(-)

New commits:
commit e6ca379bcbe7d9fb426cf8944f24e345e8856d3f
Author: Stephan Bergmann 
AuthorDate: Thu Oct 19 13:21:20 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Thu Oct 19 17:16:29 2023 +0200

Clean up some C++20 TODOs

Change-Id: I8baece4349683c7a83a283b85e24f33874b47ba3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158177
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 62bf0530e819..55b83d675d8d 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -36,6 +36,7 @@
 #include 
 
 #if defined LIBO_INTERNAL_ONLY
+#include 
 #include 
 #include 
 #endif
@@ -98,10 +99,7 @@ public:
 OStringLiteral(char const ()[N]) {
 assertLayout();
 assert(literal[N - 1] == '\0');
-//TODO: Use C++20 constexpr std::copy_n (P0202R3):
-for (std::size_t i = 0; i != N; ++i) {
-more.buffer[i] = literal[i];
-}
+std::copy_n(literal, N, more.buffer);
 }
 
 #if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1938 && defined 
_MANAGED)
@@ -113,10 +111,7 @@ public:
 OStringLiteral(char8_t const ()[N]) {
 assertLayout();
 assert(literal[N - 1] == '\0');
-//TODO: Use C++20 constexpr std::copy_n (P0202R3):
-for (std::size_t i = 0; i != N; ++i) {
-more.buffer[i] = literal[i];
-}
+std::copy_n(literal, N, more.buffer);
 }
 #endif
 
@@ -141,7 +136,7 @@ private:
 
 oslInterlockedCount refCount = 0x4000; // SAL_STRING_STATIC_FLAG 
(sal/rtl/strimp.hxx)
 sal_Int32 length = N - 1;
-char buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2)
+char buffer[N];
 };
 
 public:
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index cd23f121e2ac..cad8cc10ac48 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -96,10 +96,7 @@ public:
 OUStringLiteral(char16_t const ()[N]) {
 assertLayout();
 assert(literal[N - 1] == '\0');
-//TODO: Use C++20 constexpr std::copy_n (P0202R3):
-for (std::size_t i = 0; i != N; ++i) {
-more.buffer[i] = literal[i];
-}
+std::copy_n(literal, N, more.buffer);
 }
 
 constexpr sal_Int32 getLength() const { return more.length; }
@@ -123,7 +120,7 @@ private:
 
 oslInterlockedCount refCount = 0x4000; // SAL_STRING_STATIC_FLAG 
(sal/rtl/strimp.hxx)
 sal_Int32 length = N - 1;
-sal_Unicode buffer[N] = {}; //TODO: drop initialization for C++20 
(P1331R2)
+sal_Unicode buffer[N];
 };
 
 public:


[Libreoffice-commits] core.git: include/rtl

2023-10-18 Thread Stephan Bergmann (via logerrit)
 include/rtl/strbuf.hxx  |2 +-
 include/rtl/string.hxx  |2 +-
 include/rtl/stringutils.hxx |2 +-
 include/rtl/ustrbuf.hxx |2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit ca58f649196ed6b4ce15d0db3935f7de4cb0f2ea
Author: Stephan Bergmann 
AuthorDate: Wed Oct 18 17:04:26 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Oct 18 19:33:52 2023 +0200

Extend /clr /std:c++20 char8_t workaround to old versions of VS 2022

On IRC, pppregin now reported that she ran into the issue addressed by
3c6de7e20e35e37cbddd2d35e065525616deac00 "Fix build against VS 2022 17.7.5" 
when
using (a presumably old version of) VS 2022.  And


suggests that older versions of VS 2022 used _MSV_VER values 1930...1936, so
cover those too here.

Change-Id: Ifee80114c5cd39aeabc31907adafb03eb2f388e9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158122
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index e4e4eda1fecd..56f3e2abcc38 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -122,7 +122,7 @@ public:
 explicit OStringBuffer(bool) = delete;
 explicit OStringBuffer(char) = delete;
 explicit OStringBuffer(wchar_t) = delete;
-#if !(defined _MSC_VER && _MSC_VER >= 1937 && _MSC_VER <= 1938 && defined 
_MANAGED)
+#if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1938 && defined 
_MANAGED)
 explicit OStringBuffer(char8_t) = delete;
 #endif
 explicit OStringBuffer(char16_t) = delete;
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index a2be12ab320d..62bf0530e819 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -104,7 +104,7 @@ public:
 }
 }
 
-#if !(defined _MSC_VER && _MSC_VER >= 1937 && _MSC_VER <= 1938 && defined 
_MANAGED)
+#if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1938 && defined 
_MANAGED)
 #if HAVE_CPP_CONSTEVAL
 consteval
 #else
diff --git a/include/rtl/stringutils.hxx b/include/rtl/stringutils.hxx
index 0239505be0d2..3cd66ee6c146 100644
--- a/include/rtl/stringutils.hxx
+++ b/include/rtl/stringutils.hxx
@@ -247,7 +247,7 @@ struct ConstCharArrayDetector< const char[ 1 ], T >
 #endif
 
 #if defined LIBO_INTERNAL_ONLY \
-&& !(defined _MSC_VER && _MSC_VER >= 1937 && _MSC_VER <= 1938 && defined 
_MANAGED)
+&& !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1938 && defined 
_MANAGED)
 template
 struct ConstCharArrayDetector {
 using Type = T;
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index cd868b0c6d7b..f41e34aa9d5d 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -124,7 +124,7 @@ public:
 explicit OUStringBuffer(bool) = delete;
 explicit OUStringBuffer(char) = delete;
 explicit OUStringBuffer(wchar_t) = delete;
-#if !(defined _MSC_VER && _MSC_VER >= 1937 && _MSC_VER <= 1938 && defined 
_MANAGED)
+#if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1938 && defined 
_MANAGED)
 explicit OUStringBuffer(char8_t) = delete;
 #endif
 explicit OUStringBuffer(char16_t) = delete;


[Libreoffice-commits] core.git: include/rtl

2023-10-17 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx  |   14 ++
 include/rtl/ustring.hxx |   14 ++
 2 files changed, 28 insertions(+)

New commits:
commit c7cef7500105c6122df90900b3ba919e80c3bbb9
Author: Stephan Bergmann 
AuthorDate: Tue Oct 17 23:40:05 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Oct 18 07:36:40 2023 +0200

O[U]String move ctors should be constexpr, too

...similar to 5f2206e3ccf1cf64d2b11b0e5d419973269920a8 "O{U]String copy ctor
should be constexpr", which will again be useful for some upcoming 
replacements
of OUStringConstExpr with OUString, and making data actually constexpr.  
(For
example, the

  static o3tl::enumarray const map

in INetURLObject::getSchemeInfo (tools/source/fsys/urlobj.cxx) can actually 
be
constexpr, but the o3tl::enumarray ctor forwards its SchemeInfo arguments by
forwarding references, so uses an implicitly generated constexpr SchemeInfo 
move
ctor, which in turn requires constexpr member move ctors.  So when the 
m_sScheme
member will be changed from rtl::OUStringConstExpr to OUString, the OUString
move ctor better be constexpr.)

Change-Id: Icfc5edbb8422919186517667f876ea90bec1be90
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158099
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index de468f127757..a2be12ab320d 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -240,9 +240,23 @@ public:
   @paramstr an OString.
   @since LibreOffice 5.2
 */
+#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
+constexpr
+#endif
 OString( OString && str ) noexcept
 {
 pData = str.pData;
+#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
+if (std::is_constant_evaluated()) {
+//TODO: We would want to
+//
+//   assert(SAL_STRING_IS_STATIC(pData));
+//
+// here, but that wouldn't work because read of member `str` of 
OUStringLiteral's
+// anonymous union with active member `more` is not allowed in a 
constant expression.
+return;
+}
+#endif
 str.pData = nullptr;
 rtl_string_new(  );
 }
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 8e8bd8e9580e..a88c2a303194 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -250,9 +250,23 @@ public:
   @paramstr an OUString.
   @since LibreOffice 5.2
 */
+#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
+constexpr
+#endif
 OUString( OUString && str ) noexcept
 {
 pData = str.pData;
+#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
+if (std::is_constant_evaluated()) {
+//TODO: We would want to
+//
+//   assert(SAL_STRING_IS_STATIC(pData));
+//
+// here, but that wouldn't work because read of member `str` of 
OUStringLiteral's
+// anonymous union with active member `more` is not allowed in a 
constant expression.
+return;
+}
+#endif
 str.pData = nullptr;
 rtl_uString_new(  );
 }


[Libreoffice-commits] core.git: include/rtl vcl/source

2023-10-15 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx|   38 --
 vcl/source/fontsubset/cff.cxx |2 +-
 2 files changed, 1 insertion(+), 39 deletions(-)

New commits:
commit d3a0815b12c0d040e99e22e53f6574726b868ec7
Author: Stephan Bergmann 
AuthorDate: Fri Oct 13 22:53:16 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Sun Oct 15 22:05:17 2023 +0200

Drop OStringConstExpr, use constexpr OString instead

Change-Id: Ibb41a27fe7d5456d8db0c98821d5b2acf8586b70
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157949
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 6cc26e7befe3..de468f127757 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -153,39 +153,6 @@ public:
 };
 };
 
-/**
-  This is intended to be used when declaring compile-time-constant structs or 
arrays
-  that can be initialised from named OStringLiteral e.g.
-
-constexpr OStringLiteral AAA = u"aaa";
-constexpr OStringLiteral BBB = u"bbb";
-constexpr OStringConstExpr FOO[] { AAA, BBB };
-*/
-class OString;
-class OStringConstExpr
-{
-public:
-template constexpr OStringConstExpr(OStringLiteral const 
& literal):
-pData(const_cast()) {}
-
-// prevent mis-use
-template constexpr OStringConstExpr(OStringLiteral && 
literal)
-= delete;
-
-// no destructor necessary because we know we are pointing at a 
compile-time
-// constant OStringLiteral, which bypasses ref-counting.
-
-/**
-  make it easier to pass to OStringBuffer and similar without 
casting/converting
-*/
-constexpr std::string_view asView() const { return 
std::string_view(pData->buffer, pData->length); }
-
-inline operator const OString&() const;
-
-private:
-rtl_String* pData;
-};
-
 #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
 
 namespace detail {
@@ -2286,11 +2253,6 @@ public:
 #endif
 };
 
-#if defined LIBO_INTERNAL_ONLY
-// Can only define this after we define OString
-inline OStringConstExpr::operator const OString &() const { return 
OString::unacquired(); }
-#endif
-
 #if defined LIBO_INTERNAL_ONLY
 inline bool operator ==(OString const & lhs, StringConcatenation const & 
rhs)
 { return lhs == std::string_view(rhs); }
diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx
index 7284954397fd..365d5459ee0a 100644
--- a/vcl/source/fontsubset/cff.cxx
+++ b/vcl/source/fontsubset/cff.cxx
@@ -433,7 +433,7 @@ constexpr OStringLiteral tok_Regular = "Regular";
 constexpr OStringLiteral tok_Roman = "Roman";
 constexpr OStringLiteral tok_Semibold = "Semibold";
 
-constexpr rtl::OStringConstExpr pStringIds[] = {
+constexpr OString pStringIds[] = {
 /*0*/   tok_notdef,   tok_space,tok_exclam,   
tok_quotedbl,
 tok_numbersign,   tok_dollar,   tok_percent,  
tok_ampersand,
 tok_quoteright,   tok_parenleft,tok_parenright,   
tok_asterisk,


[Libreoffice-commits] core.git: include/rtl

2023-10-13 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx  |   15 ++-
 include/rtl/ustring.hxx |   15 ++-
 2 files changed, 28 insertions(+), 2 deletions(-)

New commits:
commit 5f2206e3ccf1cf64d2b11b0e5d419973269920a8
Author: Stephan Bergmann 
AuthorDate: Fri Oct 13 18:06:53 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Oct 13 22:41:10 2023 +0200

O{U]String copy ctor should be constexpr

...similar to the dtors, which will be useful for some upcoming 
replacements of
O[U]StringLiteral and O[U]StringConstExpr

Change-Id: Iad905d8466ee76eba1891fbc340073c482d568d5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157944
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 3482bb833ebd..6cc26e7befe3 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -247,10 +247,23 @@ public:
 
   @paramstr an OString.
 */
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
+constexpr
+#endif
 OString( const OString & str )
 {
 pData = str.pData;
-rtl_string_acquire( pData );
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
+if (std::is_constant_evaluated()) {
+//TODO: We would want to
+//
+//   assert(SAL_STRING_IS_STATIC(pData));
+//
+// here, but that wouldn't work because read of member `str` of 
OUStringLiteral's
+// anonymous union with active member `more` is not allowed in a 
constant expression.
+} else
+#endif
+rtl_string_acquire( pData );
 }
 
 #if defined LIBO_INTERNAL_ONLY
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index fc88942c8277..8e8bd8e9580e 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -224,10 +224,23 @@ public:
 
   @paramstr an OUString.
 */
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
+constexpr
+#endif
 OUString( const OUString & str )
 {
 pData = str.pData;
-rtl_uString_acquire( pData );
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
+if (std::is_constant_evaluated()) {
+//TODO: We would want to
+//
+//   assert(SAL_STRING_IS_STATIC(pData));
+//
+// here, but that wouldn't work because read of member `str` of 
OUStringLiteral's
+// anonymous union with active member `more` is not allowed in a 
constant expression.
+} else
+#endif
+rtl_uString_acquire( pData );
 }
 
 #if defined LIBO_INTERNAL_ONLY


[Libreoffice-commits] core.git: include/rtl

2023-10-13 Thread Stephan Bergmann (via logerrit)
 include/rtl/strbuf.hxx  |2 +-
 include/rtl/string.hxx  |2 +-
 include/rtl/stringutils.hxx |3 ++-
 include/rtl/ustrbuf.hxx |2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)

New commits:
commit 282f9206b77a03e1864f2f9d4f9c17086495d447
Author: Stephan Bergmann 
AuthorDate: Fri Oct 13 13:30:37 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Oct 13 16:33:07 2023 +0200

At least VS 2022 Preview 17.8.0 Preview 3.0 needs the fix too

...from 3c6de7e20e35e37cbddd2d35e065525616deac00 "Fix build against VS 2022
17.7.5"

Change-Id: I36a7d02959c5ad04781c3d484966727c3283cbbb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157932
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index dd4187e30fc3..e4e4eda1fecd 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -122,7 +122,7 @@ public:
 explicit OStringBuffer(bool) = delete;
 explicit OStringBuffer(char) = delete;
 explicit OStringBuffer(wchar_t) = delete;
-#if !(defined _MSC_VER && _MSC_VER == 1937 && defined _MANAGED)
+#if !(defined _MSC_VER && _MSC_VER >= 1937 && _MSC_VER <= 1938 && defined 
_MANAGED)
 explicit OStringBuffer(char8_t) = delete;
 #endif
 explicit OStringBuffer(char16_t) = delete;
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 566ff7ff4d2c..3482bb833ebd 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -104,7 +104,7 @@ public:
 }
 }
 
-#if !(defined _MSC_VER && _MSC_VER == 1937 && defined _MANAGED)
+#if !(defined _MSC_VER && _MSC_VER >= 1937 && _MSC_VER <= 1938 && defined 
_MANAGED)
 #if HAVE_CPP_CONSTEVAL
 consteval
 #else
diff --git a/include/rtl/stringutils.hxx b/include/rtl/stringutils.hxx
index fa6c82f50d6f..0239505be0d2 100644
--- a/include/rtl/stringutils.hxx
+++ b/include/rtl/stringutils.hxx
@@ -246,7 +246,8 @@ struct ConstCharArrayDetector< const char[ 1 ], T >
 };
 #endif
 
-#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER == 1937 && 
defined _MANAGED)
+#if defined LIBO_INTERNAL_ONLY \
+&& !(defined _MSC_VER && _MSC_VER >= 1937 && _MSC_VER <= 1938 && defined 
_MANAGED)
 template
 struct ConstCharArrayDetector {
 using Type = T;
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index a96dac187455..cd868b0c6d7b 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -124,7 +124,7 @@ public:
 explicit OUStringBuffer(bool) = delete;
 explicit OUStringBuffer(char) = delete;
 explicit OUStringBuffer(wchar_t) = delete;
-#if !(defined _MSC_VER && _MSC_VER == 1937 && defined _MANAGED)
+#if !(defined _MSC_VER && _MSC_VER >= 1937 && _MSC_VER <= 1938 && defined 
_MANAGED)
 explicit OUStringBuffer(char8_t) = delete;
 #endif
 explicit OUStringBuffer(char16_t) = delete;


[Libreoffice-commits] core.git: include/rtl

2023-10-12 Thread Stephan Bergmann (via logerrit)
 include/rtl/strbuf.hxx  |2 ++
 include/rtl/string.hxx  |2 ++
 include/rtl/stringutils.hxx |2 +-
 include/rtl/ustrbuf.hxx |2 ++
 4 files changed, 7 insertions(+), 1 deletion(-)

New commits:
commit 3c6de7e20e35e37cbddd2d35e065525616deac00
Author: Stephan Bergmann 
AuthorDate: Thu Oct 12 14:13:25 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Thu Oct 12 18:51:08 2023 +0200

Fix build against VS 2022 17.7.5

After af9c3ed6f748781f2a77e676ffe740992788969b "__cpp_char8_t is generally
available now" (which Jenkins built successfully against some VS 2019 
version),
various people using at least exactly VS 2022 17.7.5 
(--with-visual-studio=2022)
started to experience issues like

> include\rtl/stringutils.hxx(251): error C2065: 'char8_t': undeclared 
identifier

when compiling e.g. cli_ure/source/climaker/climaker_app.cxx (i.e., in /clr
mode).

This is similar to the VS 2019 16.11.30 /clr issue discussed in the commit
message of 5a40abc86b94c0be5b4a252c6ab5b0b0df6e520d "Drop some newly 
obsolete
__cplusplus version checks", just that it apparently hits with a different 
set
of VS versions.  The fix here is similar to the fix there, just 
conditionally
disable char8_t functionality for certain VS versions in /clr mode, and keep
fingers crossed.

Change-Id: I8c4ed2e3d290dc1c94f329d314407a56170564f5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157866
Reviewed-by: Noel Grandin 
Reviewed-by: Mike Kaganski 
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index bb7f72e78cb5..dd4187e30fc3 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -122,7 +122,9 @@ public:
 explicit OStringBuffer(bool) = delete;
 explicit OStringBuffer(char) = delete;
 explicit OStringBuffer(wchar_t) = delete;
+#if !(defined _MSC_VER && _MSC_VER == 1937 && defined _MANAGED)
 explicit OStringBuffer(char8_t) = delete;
+#endif
 explicit OStringBuffer(char16_t) = delete;
 explicit OStringBuffer(char32_t) = delete;
 #endif
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index a9038fc3cef0..566ff7ff4d2c 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -104,6 +104,7 @@ public:
 }
 }
 
+#if !(defined _MSC_VER && _MSC_VER == 1937 && defined _MANAGED)
 #if HAVE_CPP_CONSTEVAL
 consteval
 #else
@@ -117,6 +118,7 @@ public:
 more.buffer[i] = literal[i];
 }
 }
+#endif
 
 constexpr sal_Int32 getLength() const { return more.length; }
 
diff --git a/include/rtl/stringutils.hxx b/include/rtl/stringutils.hxx
index b8a978efbcc6..fa6c82f50d6f 100644
--- a/include/rtl/stringutils.hxx
+++ b/include/rtl/stringutils.hxx
@@ -246,7 +246,7 @@ struct ConstCharArrayDetector< const char[ 1 ], T >
 };
 #endif
 
-#if defined LIBO_INTERNAL_ONLY
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER == 1937 && 
defined _MANAGED)
 template
 struct ConstCharArrayDetector {
 using Type = T;
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 41af86e13119..a96dac187455 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -124,7 +124,9 @@ public:
 explicit OUStringBuffer(bool) = delete;
 explicit OUStringBuffer(char) = delete;
 explicit OUStringBuffer(wchar_t) = delete;
+#if !(defined _MSC_VER && _MSC_VER == 1937 && defined _MANAGED)
 explicit OUStringBuffer(char8_t) = delete;
+#endif
 explicit OUStringBuffer(char16_t) = delete;
 explicit OUStringBuffer(char32_t) = delete;
 #endif


[Libreoffice-commits] core.git: include/rtl

2023-10-11 Thread Stephan Bergmann (via logerrit)
 include/rtl/uri.hxx |8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

New commits:
commit 8ef60830e4d3eec70fe98244b2eaa18db091385a
Author: Stephan Bergmann 
AuthorDate: Wed Oct 11 13:45:30 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Oct 11 19:56:32 2023 +0200

__cpp_lib_char8_t is generally available now

...after 1eef07805021b7ca26a1a8894809b6d995747ba1 "Bump baseline to C++20"

Change-Id: I45aa7538174a0c62ad5a4871e2914b30580546c0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157827
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/uri.hxx b/include/rtl/uri.hxx
index 3221a9fba8b2..b0b3e9ad8190 100644
--- a/include/rtl/uri.hxx
+++ b/include/rtl/uri.hxx
@@ -154,13 +154,7 @@ consteval
 #else
 constexpr
 #endif
-auto createUriCharClass(
-#if defined __cpp_lib_char8_t
-std::u8string_view
-#else
-std::string_view
-#endif
-unencoded)
+auto createUriCharClass(std::u8string_view unencoded)
 {
 std::array a = {};
 for (auto c: unencoded) {


[Libreoffice-commits] core.git: include/rtl sal/qa

2023-10-11 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx |2 +-
 sal/qa/rtl/strings/test_ostring_stringliterals.cxx |1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

New commits:
commit 019d969d73efcb4ad876b294c968761ee8ed9733
Author: Stephan Bergmann 
AuthorDate: Wed Oct 11 12:32:42 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Oct 11 17:08:44 2023 +0200

The other OStringLiteral ctor should be non-explicit too

It had been missed by 31cd6fd0f3c856a81a03d0229de1c4d10442844f "Make
OStringLiteral ctor non-explicit", and now prevented u8"..."_ostr from
compiling.

Change-Id: Ifb214fba0957b0d26b11daae6190ffa9d21713f0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157823
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index bb67c2f46354..a9038fc3cef0 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -109,7 +109,7 @@ public:
 #else
 constexpr
 #endif
-explicit OStringLiteral(char8_t const ()[N]) {
+OStringLiteral(char8_t const ()[N]) {
 assertLayout();
 assert(literal[N - 1] == '\0');
 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
diff --git a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx 
b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
index 28755316ed8f..ef8b8f3d73c9 100644
--- a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
@@ -276,6 +276,7 @@ void test::ostring::StringLiterals::checkOstr() {
 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ""_ostr.getLength());
 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), "foobar"_ostr.getLength());
 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), "foo\0bar"_ostr.getLength());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(4), u8"\U0001"_ostr.getLength());
 CPPUNIT_ASSERT_EQUAL(""_ostr, rtl::OString(""_tstr));
 CPPUNIT_ASSERT_EQUAL("foobar"_ostr, rtl::OString("foobar"_tstr));
 CPPUNIT_ASSERT_EQUAL("foo\0bar"_ostr, rtl::OString("foo\0bar"_tstr));


[Libreoffice-commits] core.git: include/rtl include/unotools sal/qa sc/qa vcl/unx

2023-09-29 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx  |   10 +-
 include/rtl/ustring.hxx |8 
 include/unotools/weakref.hxx|2 +-
 sal/qa/rtl/strings/test_ostring_stringliterals.cxx  |7 +--
 sal/qa/rtl/strings/test_oustring_stringliterals.cxx |   11 +++
 sc/qa/unit/ucalc_formula2.cxx   |   10 +-
 vcl/unx/gtk3/customcellrenderer.cxx |6 ++
 7 files changed, 17 insertions(+), 37 deletions(-)

New commits:
commit 5a40abc86b94c0be5b4a252c6ab5b0b0df6e520d
Author: Stephan Bergmann 
AuthorDate: Sun Sep 24 12:16:36 2023 +0300
Commit: Stephan Bergmann 
CommitDate: Fri Sep 29 16:45:08 2023 +0200

Drop some newly obsolete __cplusplus version checks

...after 1eef07805021b7ca26a1a8894809b6d995747ba1 "Bump baseline to C++20".

Which revealed that at least for VS 2019 16.11.30 (but not for at least VS 
2022
17.7.4), in /clr mode (e.g., when compiling
cli_ure/source/climaker/climaker_app.cxx), the -std:c++20 is effectively
ignored, and compilation of such source files failed with

> include\rtl/string.hxx(191): error C2955: 'rtl::OStringLiteral': use of 
class template requires template argument list
> include\rtl/string.hxx(88): note: see declaration of 'rtl::OStringLiteral'
> include\rtl/string.hxx(191): error C7592: a non-type template-parameter 
of type 'rtl::OStringLiteral' requires at least '/std:c++20'
> include\rtl/string.hxx(397): error C2955: 'rtl::OStringLiteral': use of 
class template requires template argument list
> include\rtl/string.hxx(88): note: see declaration of 'rtl::OStringLiteral'

etc.  To work around that, keep the 27d1f3ac016d77d3c907cebedca558308f366855
"O[U]String literals (unusable for now, C++20 only)" functionality disabled 
when
compiling /clr sources (i.e., where _MANAGED is defined) for that old 
compiler.

Change-Id: If62ceef5f8e55a828b880f197111fe387e4953fe
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157205
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index eb7f137a203c..72b046e26a0b 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -186,7 +186,7 @@ private:
 rtl_String* pData;
 };
 
-#if __cplusplus >= 202002L
+#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
 
 namespace detail {
 
@@ -396,7 +396,7 @@ public:
 /// @endcond
 #endif
 
-#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
 // For operator ""_tstr:
 template constexpr OString(detail::OStringHolder 
const & holder):
 pData(const_cast()) {}
@@ -472,12 +472,12 @@ public:
 /**
   Release the string data.
 */
-#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
 constexpr
 #endif
 ~OString()
 {
-#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
 if (std::is_constant_evaluated()) {
//TODO: We would want to
//
@@ -2393,7 +2393,7 @@ using ::rtl::OStringHash;
 using ::rtl::OStringLiteral;
 #endif
 
-#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
 
 template<
 #if defined RTL_STRING_UNITTEST
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 34d4fd8f5be5..764ad026bdff 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -440,7 +440,7 @@ public:
 /// @endcond
 #endif
 
-#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
 // For operator ""_tstr:
 template OUString(detail::OStringHolder const & 
holder) {
 pData = nullptr;
@@ -545,12 +545,12 @@ public:
 /**
   Release the string data.
 */
-#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
 constexpr
 #endif
 ~OUString()
 {
-#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
 if (std::is_constant_evaluated()) {
//TODO: We would want to
//
@@ -3590,7 +3590,7 @@ using ::rtl::OUStringChar;
 using ::rtl::Concat2View;
 #endif
 
-#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
 
 template<
 #if defined RTL_STRING_UNITTEST
diff --git 

[Libreoffice-commits] core.git: include/rtl

2023-09-15 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx  |   12 ++--
 include/rtl/ustring.hxx |   24 ++--
 2 files changed, 4 insertions(+), 32 deletions(-)

New commits:
commit b9ffee3074d8eb0e95b3d8f78cb7aac10b41c279
Author: Stephan Bergmann 
AuthorDate: Wed Sep 13 13:18:51 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Sep 15 11:09:13 2023 +0200

StringHolder detour is only really needed for ""_tstr

Change-Id: Ifd3b21cdfa3738737b47fde0d014c312494227e3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156933
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index eae18bc30d0d..eb7f137a203c 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -146,7 +146,7 @@ private:
 
 public:
 // (Data members must be public so that OStringLiteral is a structural 
type that can be used as
-// a non-type template parameter type for rtl::detail::OStringHolder:)
+// a non-type template parameter type for operator ""_ostr and 
rtl::detail::OStringHolder:)
 union {
 rtl_String str;
 Data more = {};
@@ -2405,15 +2405,7 @@ constexpr
 rtlunittest::
 #endif
 OString
-operator ""_ostr() {
-return
-#if defined RTL_STRING_UNITTEST
-rtlunittest
-#else
-rtl
-#endif
-::detail::OStringHolder::literal;
-}
+operator ""_ostr() { return L; }
 
 template<
 #if defined RTL_STRING_UNITTEST
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index c273c76ace6a..34d4fd8f5be5 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -128,7 +128,7 @@ private:
 
 public:
 // (Data members must be public so that OUStringLiteral is a structural 
type that can be used as
-// a non-type template parameter type for rtl::detail::OUStringHolder:)
+// a non-type template parameter type for operator ""_ustr:)
 union {
 rtl_uString str;
 Data more = {};
@@ -175,18 +175,6 @@ private:
 rtl_uString* pData;
 };
 
-#if __cplusplus >= 202002L
-
-namespace detail {
-
-template struct OUStringHolder {
-static constexpr auto & literal = L;
-};
-
-}
-
-#endif
-
 /// @endcond
 #endif
 
@@ -3614,15 +3602,7 @@ constexpr
 rtlunittest::
 #endif
 OUString
-operator ""_ustr() {
-return
-#if defined RTL_STRING_UNITTEST
-rtlunittest
-#else
-rtl
-#endif
-::detail::OUStringHolder::literal;
-}
+operator ""_ustr() { return L; }
 
 #endif
 


[Libreoffice-commits] core.git: include/rtl sal/qa

2023-07-30 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx  |   51 +++-
 include/rtl/ustring.hxx |   37 +-
 sal/qa/rtl/strings/test_ostring_stringliterals.cxx  |3 +
 sal/qa/rtl/strings/test_oustring_stringliterals.cxx |3 +
 4 files changed, 70 insertions(+), 24 deletions(-)

New commits:
commit 6fce450b8a66d7e98a4d39528f8591184277e9fa
Author: Stephan Bergmann 
AuthorDate: Fri Jul 21 14:20:57 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Mon Jul 31 07:58:08 2023 +0200

Introduce "..."_tstr as a companion to "..."_ostr/u"..."_ustr in template 
code

...like

> *path = "/";

in

> template oslFileError getSystemPathFromFileUrl(
> OUString const & url, T * path, bool resolveHome)

in sal/osl/unx/file_url.cxx, where T is either OString or OUString.  That 
can
now be replaced with

> *path = "/"_tstr;

and for OString it will be a no-cost constexpr operation, while for 
OUString it
will still construct the OUString instance at runtime (as did the original 
code
for both OString and OUString).

(This change required moving the definition of rtl::detail::OStringHolder
around in include/rtl/string.hxx.  For consistency, I similarly moved 
around the
definition of rtl::detail::OUStringHolder in include/rtl/ustring.hxx, too.)

Change-Id: I7fb3a81b438f98c609684f7e70b7a60068d32fdb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154748
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index aae291f46053..eae18bc30d0d 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -186,6 +186,18 @@ private:
 rtl_String* pData;
 };
 
+#if __cplusplus >= 202002L
+
+namespace detail {
+
+template struct OStringHolder {
+static constexpr auto & literal = L;
+};
+
+}
+
+#endif
+
 #endif
 
 /* === */
@@ -384,6 +396,12 @@ public:
 /// @endcond
 #endif
 
+#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+// For operator ""_tstr:
+template constexpr OString(detail::OStringHolder 
const & holder):
+pData(const_cast()) {}
+#endif
+
 #if defined LIBO_INTERNAL_ONLY
 explicit OString(std::string_view sv) {
 if (sv.size() > sal_uInt32(std::numeric_limits::max())) {
@@ -2275,18 +2293,6 @@ inline bool operator !=(StringConcatenation const 
& lhs, OString const & r
 
 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
 
-#if __cplusplus >= 202002L
-
-namespace detail {
-
-template struct OStringHolder {
-static constexpr auto & literal = L;
-};
-
-}
-
-#endif
-
 /**
  @internal
 */
@@ -2409,6 +2415,27 @@ operator ""_ostr() {
 ::detail::OStringHolder::literal;
 }
 
+template<
+#if defined RTL_STRING_UNITTEST
+rtlunittest::
+#endif
+OStringLiteral L>
+constexpr
+#if defined RTL_STRING_UNITTEST
+rtlunittest
+#else
+rtl
+#endif
+::detail::OStringHolder operator ""_tstr() {
+return
+#if defined RTL_STRING_UNITTEST
+rtlunittest
+#else
+rtl
+#endif
+::detail::OStringHolder();
+}
+
 #endif
 
 /// @cond INTERNAL
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 90b195754a17..c273c76ace6a 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -175,6 +175,18 @@ private:
 rtl_uString* pData;
 };
 
+#if __cplusplus >= 202002L
+
+namespace detail {
+
+template struct OUStringHolder {
+static constexpr auto & literal = L;
+};
+
+}
+
+#endif
+
 /// @endcond
 #endif
 
@@ -440,6 +452,19 @@ public:
 /// @endcond
 #endif
 
+#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+// For operator ""_tstr:
+template OUString(detail::OStringHolder const & 
holder) {
+pData = nullptr;
+if (holder.literal.getLength() == 0) {
+rtl_uString_new();
+} else {
+rtl_uString_newFromLiteral(
+, holder.literal.getStr(), holder.literal.getLength(), 
0);
+}
+}
+#endif
+
 /**
   New string from an 8-Bit character buffer array.
 
@@ -3414,18 +3439,6 @@ inline bool operator !=(StringConcatenation 
const & lhs, OUString cons
 #if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
 /// @cond INTERNAL
 
-#if __cplusplus >= 202002L
-
-namespace detail {
-
-template struct OUStringHolder {
-static constexpr auto & literal = L;
-};
-
-}
-
-#endif
-
 /**
  @internal
 */
diff --git a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx 
b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
index 8cfc3a65bdde..1017106e2800 100644
--- a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
@@ -280,6 +280,9 @@ void test::ostring::StringLiterals::checkOstr() {
 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ""_ostr.getLength());
 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), 

[Libreoffice-commits] core.git: include/rtl sal/qa

2023-07-19 Thread Stephan Bergmann (via logerrit)
 include/rtl/ustring.hxx |2 +-
 sal/qa/rtl/strings/test_oustring_stringliterals.cxx |6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit e83e62fe376a91f7270435e06ee7f6864c48fb4b
Author: Stephan Bergmann 
AuthorDate: Wed Jul 19 08:27:02 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Jul 19 10:24:45 2023 +0200

Work around MSVC bug with "..."_ostr vs. u"..."_ostr

Since 27d1f3ac016d77d3c907cebedca558308f366855 "O[U]String literals 
(unusable
for now, C++20 only)",


"Using same string literal suffix for char and char16_t string overloads 
causes
'no matching overloaded function found'" caused --with-latest-c++ builds to 
fail
with

> sal/qa/rtl/strings/test_oustring_stringliterals.cxx(432): error C2672: 
'""_ostr': no matching overloaded function found
> include\rtl/ustring.hxx(3604): note: could be 'rtlunittest::OUString 
operator ""_ostr(void)'
> include\rtl/string.hxx(2402): note: or   'rtlunittest::OString 
operator ""_ostr(void)'
> sal/qa/rtl/strings/test_oustring_stringliterals.cxx(432): error C2672: 
'CppUnit::assertEquals': no matching overloaded function found
> workdir\UnpackedTarball\cppunit\include\cppunit/TestAssert.h(161): note: 
could be 'void CppUnit::assertEquals(const T &,const T 
&,CppUnit::SourceLine,const std::string &)'
> sal/qa/rtl/strings/test_oustring_stringliterals.cxx(432): note: 'void 
CppUnit::assertEquals(const T &,const T &,CppUnit::SourceLine,const std::string 
&)': expects 4 arguments - 3 provided

etc.  So help MSVC along by renaming from u"..."_ostr to u"..."_ustr for 
now.

Change-Id: Iad401f0681ac9326b7c57259c5483263ddfbfd4e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154634
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 67275ee07932..90b195754a17 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -3601,7 +3601,7 @@ constexpr
 rtlunittest::
 #endif
 OUString
-operator ""_ostr() {
+operator ""_ustr() {
 return
 #if defined RTL_STRING_UNITTEST
 rtlunittest
diff --git a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx 
b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
index d2f471ba61fc..709ddb669cc5 100644
--- a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
@@ -429,9 +429,9 @@ void test::oustring::StringLiterals::checkEmbeddedNul() {
 
 void test::oustring::StringLiterals::checkOstr() {
 #if __cplusplus >= 202002L
-CPPUNIT_ASSERT_EQUAL(sal_Int32(0), u""_ostr.getLength());
-CPPUNIT_ASSERT_EQUAL(sal_Int32(6), u"foobar"_ostr.getLength());
-CPPUNIT_ASSERT_EQUAL(sal_Int32(7), u"foo\0bar"_ostr.getLength());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(0), u""_ustr.getLength());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(6), u"foobar"_ustr.getLength());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(7), u"foo\0bar"_ustr.getLength());
 #endif
 }
 


[Libreoffice-commits] core.git: include/rtl sal/qa

2023-07-14 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx  |   41 +++-
 include/rtl/ustring.hxx |   41 +++-
 sal/qa/rtl/strings/test_ostring_stringliterals.cxx  |   10 
 sal/qa/rtl/strings/test_oustring_stringliterals.cxx |   10 
 4 files changed, 98 insertions(+), 4 deletions(-)

New commits:
commit 27d1f3ac016d77d3c907cebedca558308f366855
Author: Stephan Bergmann 
AuthorDate: Fri Jul 14 09:36:59 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Jul 14 13:32:46 2023 +0200

O[U]String literals (unusable for now, C++20 only)

Change-Id: I0ecd1a8b60a01aefdf0139e3777dc006532764fd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154434
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 091f224b25d6..aae291f46053 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -88,8 +88,6 @@ This class is not part of public API and is meant to be used 
only in LibreOffice
 template class SAL_WARN_UNUSED OStringLiteral {
 static_assert(N != 0);
 static_assert(N - 1 <= std::numeric_limits::max(), "literal too 
long");
-friend class OString;
-friend class OStringConstExpr;
 
 public:
 #if HAVE_CPP_CONSTEVAL
@@ -146,6 +144,9 @@ private:
 char buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2)
 };
 
+public:
+// (Data members must be public so that OStringLiteral is a structural 
type that can be used as
+// a non-type template parameter type for rtl::detail::OStringHolder:)
 union {
 rtl_String str;
 Data more = {};
@@ -2274,6 +2275,18 @@ inline bool operator !=(StringConcatenation const 
& lhs, OString const & r
 
 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
 
+#if __cplusplus >= 202002L
+
+namespace detail {
+
+template struct OStringHolder {
+static constexpr auto & literal = L;
+};
+
+}
+
+#endif
+
 /**
  @internal
 */
@@ -2374,6 +2387,30 @@ using ::rtl::OStringHash;
 using ::rtl::OStringLiteral;
 #endif
 
+#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+
+template<
+#if defined RTL_STRING_UNITTEST
+rtlunittest::
+#endif
+OStringLiteral L>
+constexpr
+#if defined RTL_STRING_UNITTEST
+rtlunittest::
+#endif
+OString
+operator ""_ostr() {
+return
+#if defined RTL_STRING_UNITTEST
+rtlunittest
+#else
+rtl
+#endif
+::detail::OStringHolder::literal;
+}
+
+#endif
+
 /// @cond INTERNAL
 /**
   Make OString hashable by default for use in STL containers.
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index c4869f43a8f0..67275ee07932 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -86,8 +86,6 @@ This class is not part of public API and is meant to be used 
only in LibreOffice
 template class SAL_WARN_UNUSED OUStringLiteral {
 static_assert(N != 0);
 static_assert(N - 1 <= std::numeric_limits::max(), "literal too 
long");
-friend class OUString;
-friend class OUStringConstExpr;
 
 public:
 #if HAVE_CPP_CONSTEVAL
@@ -128,6 +126,9 @@ private:
 sal_Unicode buffer[N] = {}; //TODO: drop initialization for C++20 
(P1331R2)
 };
 
+public:
+// (Data members must be public so that OUStringLiteral is a structural 
type that can be used as
+// a non-type template parameter type for rtl::detail::OUStringHolder:)
 union {
 rtl_uString str;
 Data more = {};
@@ -3413,6 +3414,18 @@ inline bool operator !=(StringConcatenation 
const & lhs, OUString cons
 #if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
 /// @cond INTERNAL
 
+#if __cplusplus >= 202002L
+
+namespace detail {
+
+template struct OUStringHolder {
+static constexpr auto & literal = L;
+};
+
+}
+
+#endif
+
 /**
  @internal
 */
@@ -3576,6 +3589,30 @@ using ::rtl::OUStringChar;
 using ::rtl::Concat2View;
 #endif
 
+#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+
+template<
+#if defined RTL_STRING_UNITTEST
+rtlunittest::
+#endif
+OUStringLiteral L>
+constexpr
+#if defined RTL_STRING_UNITTEST
+rtlunittest::
+#endif
+OUString
+operator ""_ostr() {
+return
+#if defined RTL_STRING_UNITTEST
+rtlunittest
+#else
+rtl
+#endif
+::detail::OUStringHolder::literal;
+}
+
+#endif
+
 /// @cond INTERNAL
 /**
   Make OUString hashable by default for use in STL containers.
diff --git a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx 
b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
index ec0faec94f18..8cfc3a65bdde 100644
--- a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
@@ -31,6 +31,7 @@ private:
 void checkUsage();
 void checkNonConstUsage();
 void checkBuffer();
+void checkOstr();
 
 void testcall( const char str[] );
 
@@ -46,6 +47,7 @@ CPPUNIT_TEST(checkConstexprCtor);
 CPPUNIT_TEST(checkUsage);
 CPPUNIT_TEST(checkNonConstUsage);
 CPPUNIT_TEST(checkBuffer);

[Libreoffice-commits] core.git: include/rtl

2023-07-13 Thread Stephan Bergmann (via logerrit)
 include/rtl/stringutils.hxx |   10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

New commits:
commit bca5ba30e0bbfe04de652eb55d1a9ceac4be2b0b
Author: Stephan Bergmann 
AuthorDate: Thu Jul 13 15:33:57 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Thu Jul 13 23:35:11 2023 +0200

Restrict deleted catch-all O[U]StringChar ctor to arithmetic/enum types

...which should still cover the issues that
7320d7a4a4dd0657f2d650a6f580ad399529f0f1 "OUStringChar must either take a
sal_Unicode or an ASCII char" wanted to address, but without causing 
ambiguities
where some unrelated type would unexpectedly be sucked into a conversion 
chain
going through these ctors

Change-Id: Iee3769dc6af5d7a1c8540a548bc2e10a89e637da
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154391
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/stringutils.hxx b/include/rtl/stringutils.hxx
index 58781973fab9..2c5d05c82784 100644
--- a/include/rtl/stringutils.hxx
+++ b/include/rtl/stringutils.hxx
@@ -19,6 +19,10 @@
 #include 
 #include 
 
+#if defined LIBO_INTERNAL_ONLY
+#include 
+#endif
+
 #include "sal/types.h"
 
 // The unittest uses slightly different code to help check that the proper
@@ -48,7 +52,8 @@ namespace rtl
 //
 struct SAL_WARN_UNUSED OStringChar {
 constexpr OStringChar(char theC): c(theC) {}
-template OStringChar(T &&) = delete;
+template OStringChar(
+T, std::enable_if_t || std::is_enum_v, int> 
= 0) = delete;
 constexpr operator std::string_view() const { return {, 1}; }
 char const c;
 };
@@ -98,7 +103,8 @@ struct SAL_WARN_UNUSED OStringChar {
 struct SAL_WARN_UNUSED OUStringChar_ {
 constexpr OUStringChar_(sal_Unicode theC): c(theC) {}
 constexpr OUStringChar_(char theC): c(theC) { assert(c <= 0x7F); }
-template OUStringChar_(T &&) = delete;
+template OUStringChar_(
+T, std::enable_if_t || std::is_enum_v, int> 
= 0) = delete;
 constexpr operator std::u16string_view() const { return {, 1}; }
 sal_Unicode const c;
 };


[Libreoffice-commits] core.git: include/rtl

2023-05-27 Thread Mike Kaganski (via logerrit)
 include/rtl/stringconcat.hxx |9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

New commits:
commit 1f91efaea987c78c2755ea5d02eb3b1cb50743bd
Author: Mike Kaganski 
AuthorDate: Sat May 27 11:14:32 2023 +0200
Commit: Mike Kaganski 
CommitDate: Sat May 27 12:43:42 2023 +0200

Unify Concat2View

Change-Id: Idb0a0fc620ece33e7ed6bcec3cbd8a0a833b1e38
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152314
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx
index fd9a6f7a938a..0bed28ac810c 100644
--- a/include/rtl/stringconcat.hxx
+++ b/include/rtl/stringconcat.hxx
@@ -312,14 +312,9 @@ private:
 std::unique_ptr buffer_;
 };
 
-template  auto Concat2View(OStringConcat 
const& c)
+template  auto 
Concat2View(StringConcat const& c)
 {
-return StringConcatenation(c);
-}
-
-template  auto Concat2View(OUStringConcat 
const& c)
-{
-return StringConcatenation(c);
+return StringConcatenation(c);
 }
 
 /**


[Libreoffice-commits] core.git: include/rtl

2023-05-05 Thread Mike Kaganski (via logerrit)
 include/rtl/strbuf.hxx  |2 +-
 include/rtl/ustrbuf.hxx |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 7dbc0e991f65b51f2033b8c8c60df055926d37b9
Author: Mike Kaganski 
AuthorDate: Fri May 5 07:59:00 2023 +0200
Commit: Mike Kaganski 
CommitDate: Sat May 6 07:24:20 2023 +0200

[API CHANGE] Fix O(U)StringBuffer::insert taking float

It was broken from the start: it was introduced like this already
in commit 9399c662f36c385b0c705eb34e636a9aec450282
(initial import, 2000-09-18).

Creating a temporary copy as a return value makes no sense.

Change-Id: I6910d426c2437038ec4979be2c44cd72146dec9c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151375
Reviewed-by: Stephan Bergmann 
Tested-by: Jenkins

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index b448228d6053..e5ae1ebd0a7b 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -1030,7 +1030,7 @@ public:
 @param  fa float.
 @return this string buffer.
  */
-OStringBuffer insert(sal_Int32 offset, float f)
+OStringBuffer & insert(sal_Int32 offset, float f)
 {
 char sz[RTL_STR_MAX_VALUEOFFLOAT];
 return insert( offset, sz, rtl_str_valueOfFloat( sz, f ) );
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 578df163d819..363b4f24757f 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -1286,7 +1286,7 @@ public:
 @return this string buffer.
 @exception  StringIndexOutOfBoundsException  if the offset is invalid.
  */
-OUStringBuffer insert(sal_Int32 offset, float f)
+OUStringBuffer & insert(sal_Int32 offset, float f)
 {
 sal_Unicode sz[RTL_USTR_MAX_VALUEOFFLOAT];
 return insert( offset, sz, rtl_ustr_valueOfFloat( sz, f ) );


[Libreoffice-commits] core.git: include/rtl sal/qa

2023-04-04 Thread Mike Kaganski (via logerrit)
 include/rtl/string.hxx |4 
 include/rtl/stringconcat.hxx   |   14 ++
 include/rtl/ustring.hxx|4 
 sal/qa/rtl/strings/test_strings_valuex.cxx |4 ++--
 4 files changed, 24 insertions(+), 2 deletions(-)

New commits:
commit 1e9f4de320f67d1218c710bcee1969a2324c6888
Author: Mike Kaganski 
AuthorDate: Tue Apr 4 11:27:54 2023 +0200
Commit: Mike Kaganski 
CommitDate: Tue Apr 4 23:01:56 2023 +0200

Make O(U)String::boolean also return an O(U)StringNumber

Change-Id: I184fa0e4e45662e0fac86076d1c8733a0465bb56
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149978
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 70829b43aae2..9c2c6ae61f60 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -2125,6 +2125,9 @@ public:
 return boolean(b);
 }
 
+#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
+static OStringNumber boolean(bool b) { return 
OStringNumber(b); }
+#else
 /**
   Returns the string representation of the boolean argument.
 
@@ -2141,6 +2144,7 @@ public:
 char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
 return OString(aBuf, rtl_str_valueOfBoolean(aBuf, b));
 }
+#endif
 
 /**
   Returns the string representation of the char argument.
diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx
index da32c7982792..118d93df5007 100644
--- a/include/rtl/stringconcat.hxx
+++ b/include/rtl/stringconcat.hxx
@@ -393,6 +393,13 @@ struct OStringNumber< double >
 OStringNumber(number_t d) { length = rtl_str_valueOfDouble(buf, d); }
 };
 
+template<>
+struct OStringNumber< bool >
+: public StringNumberBase
+{
+OStringNumber(number_t b) { length = rtl_str_valueOfBoolean(buf, b); }
+};
+
 /**
  @internal
 
@@ -439,6 +446,13 @@ struct OUStringNumber< double >
 OUStringNumber(number_t d) { length = rtl_ustr_valueOfDouble(buf, d); }
 };
 
+template<>
+struct OUStringNumber< bool >
+: public StringNumberBase
+{
+OUStringNumber(number_t b) { length = rtl_ustr_valueOfBoolean(buf, b); }
+};
+
 template< typename C, typename T, std::size_t nBufSize >
 struct ToStringHelper< StringNumberBase< C, T, nBufSize > >
 {
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index ddc0b5d2c0b2..36d122c1fe5a 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -3186,6 +3186,9 @@ public:
 return boolean(b);
 }
 
+#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
+static OUStringNumber boolean(bool b) { return 
OUStringNumber(b); }
+#else
 /**
   Returns the string representation of the boolean argument.
 
@@ -3202,6 +3205,7 @@ public:
 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN];
 return OUString(aBuf, rtl_ustr_valueOfBoolean(aBuf, b));
 }
+#endif
 
 /**
   Returns the string representation of the char argument.
diff --git a/sal/qa/rtl/strings/test_strings_valuex.cxx 
b/sal/qa/rtl/strings/test_strings_valuex.cxx
index 6c9c836442e1..953cf8b68efb 100644
--- a/sal/qa/rtl/strings/test_strings_valuex.cxx
+++ b/sal/qa/rtl/strings/test_strings_valuex.cxx
@@ -42,8 +42,8 @@ namespace {
 
 template< typename T >
 void testBoolean() {
-CPPUNIT_ASSERT_EQUAL( T( "false" ), T::boolean( false ) );
-CPPUNIT_ASSERT_EQUAL( T( "true" ), T::boolean( true ) );
+CPPUNIT_ASSERT_EQUAL( T( "false" ), T(T::boolean( false )) );
+CPPUNIT_ASSERT_EQUAL( T( "true" ), T(T::boolean( true )) );
 }
 
 }


[Libreoffice-commits] core.git: include/rtl

2023-04-03 Thread Mike Kaganski (via logerrit)
 include/rtl/string.h  |4 ++--
 include/rtl/ustring.h |4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 8067c37e4197f8f07be87f4516a89b07b7462632
Author: Mike Kaganski 
AuthorDate: Mon Apr 3 11:28:23 2023 +0200
Commit: Mike Kaganski 
CommitDate: Mon Apr 3 15:04:03 2023 +0200

Fix rtl_(u)str_valueOfBoolean return value documentation

The reported numbers are factually wrong. See rtl::str::valueOfBoolean,
and back to commit cb6ab44fbef0a71984a15766d5ad7dcbe0a82a10 (template
implementation for String/UString, 2001-03-16) that introduced the
actual return values.

Change-Id: Ib692ee7164be31bde3d884823a77e6452dbf9cb7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149890
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/rtl/string.h b/include/rtl/string.h
index f80bef02ca91..854a83832c99 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -568,9 +568,9 @@ SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_trim_WithLength(
 
 /** Create the string representation of a boolean.
 
-If b is true, the buffer is filled with the string "true" and 5 is
+If b is true, the buffer is filled with the string "true" and 4 is
 returned.  If b is false, the buffer is filled with the string "false" and
-6 is returned.  This function cannot be used for language-specific
+5 is returned.  This function cannot be used for language-specific
 operations.
 
 @param str
diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h
index e8d1283791ab..da4278e5a683 100644
--- a/include/rtl/ustring.h
+++ b/include/rtl/ustring.h
@@ -898,9 +898,9 @@ SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_ustr_trim_WithLength(
 
 /** Create the string representation of a boolean.
 
-If b is true, the buffer is filled with the string "true" and 5 is
+If b is true, the buffer is filled with the string "true" and 4 is
 returned.  If b is false, the buffer is filled with the string "false" and
-6 is returned.  This function cannot be used for language-specific
+5 is returned.  This function cannot be used for language-specific
 operations.
 
 @param str


[Libreoffice-commits] core.git: include/rtl

2023-03-29 Thread Mike Kaganski (via logerrit)
 include/rtl/ustring.hxx |7 +++
 1 file changed, 7 insertions(+)

New commits:
commit c6431ba1d041379c37292337337690c01f144fe2
Author: Mike Kaganski 
AuthorDate: Wed Mar 29 13:30:20 2023 +
Commit: Mike Kaganski 
CommitDate: Wed Mar 29 18:06:38 2023 +

Prevent accidental OUString(nullptr)

Similar to commit f20162304d73bc01955e9ef6506c3bd1c7016c48
(Rule out OString(std::nullptr_t), 2015-07-12); after that,
OUString was changed to have only one ctor taking pointer
in LIBO_INTERNAL_ONLY case, so became a similar issue.

Change-Id: Iac851d1c24c0616ee52a112b81ba71877c28c493
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149696
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index c3966ac15cab..ddc0b5d2c0b2 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -252,6 +252,13 @@ public:
 rtl_uString_acquire( pData );
 }
 
+#if defined LIBO_INTERNAL_ONLY
+/// @cond INTERNAL
+// Catch inadvertent conversions to the above ctor:
+OUString(std::nullptr_t) = delete;
+/// @endcond
+#endif
+
 /** New OUString from OUString data without acquiring it.  Takeover of 
ownership.
 
 The SAL_NO_ACQUIRE dummy parameter is only there to distinguish this


[Libreoffice-commits] core.git: include/rtl

2023-03-28 Thread Stephan Bergmann (via logerrit)
 include/rtl/stringconcat.hxx |5 +
 1 file changed, 5 insertions(+)

New commits:
commit 7fcfc39232d2fea7078c15552ee092b973e9175b
Author: Stephan Bergmann 
AuthorDate: Tue Mar 28 10:14:58 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Tue Mar 28 10:58:45 2023 +

Fix build for recent GCC

...after 58dd5870a77344754ea459d8423d1b3787a6a813 "Avoid dangling 
references to
temporary O[U]StringConcatMarker instances" caused e.g.

> In file included from 
/home/tdf/lode/jenkins/workspace/lo_callgrind_linux/include/rtl/string.hxx:49,
>  from 
/home/tdf/lode/jenkins/workspace/lo_callgrind_linux/include/rtl/ustring.hxx:43,
>  from 
/home/tdf/lode/jenkins/workspace/lo_callgrind_linux/include/osl/module.hxx:31,
>  from 
/home/tdf/lode/jenkins/workspace/lo_callgrind_linux/sal/osl/all/loadmodulerelative.cxx:26:
> 
/home/tdf/lode/jenkins/workspace/lo_callgrind_linux/include/rtl/stringconcat.hxx:468:8:
 error: partial specialization ‘struct rtl::StringConcat, T2, Dummy>’ is not more specialized than 
[-fpermissive]
>   468 | struct StringConcat, T2, Dummy>
>   |^
> 
/home/tdf/lode/jenkins/workspace/lo_callgrind_linux/include/rtl/stringconcat.hxx:190:8:
 note: primary template ‘template && allowStringConcat), 
int>::type  > struct rtl::StringConcat’
>   190 | struct StringConcat
>   |^~~~

() with GCC 11.02.
(But what fixes it for recent versions of GCC would start to fail with

> In file included from sal/osl/all/loadmodulerelative.cxx:26:
> In file included from include/osl/module.hxx:31:
> In file included from include/rtl/ustring.hxx:43:
> In file included from include/rtl/string.hxx:49:
> include/rtl/stringconcat.hxx:468:8: error: non-type template argument 
specializes a template parameter with dependent type 
'std::enable_if_t && allowStringConcat, int>' 
(aka 'typename enable_if && allowStringConcat, 
int>::type')
> struct StringConcat, T2>
>^
> include/rtl/stringconcat.hxx:189:125: note: template parameter is 
declared here
> template  && allowStringConcat, int> = 0 
>
> 
~~~ ^

for e.g. Clang 17 trunk.)

Change-Id: I6110d5a2813b561748654065e76bb4b6ab2f82d8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149644
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx
index c94f8b919e14..da32c7982792 100644
--- a/include/rtl/stringconcat.hxx
+++ b/include/rtl/stringconcat.hxx
@@ -464,8 +464,13 @@ using OUStringConcatMarker = 
StringConcatMarker;
 
 template constexpr bool allowStringConcat> = true;
 
+#if defined __GNUC__ && !defined __clang__
+template 
+struct StringConcat, T2>
+#else
 template , 
int> Dummy>
 struct StringConcat, T2, Dummy>
+#endif
 {
 public:
 StringConcat( const T2& right_ ) : right( right_ ) {}


[Libreoffice-commits] core.git: include/rtl

2023-03-27 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx   |4 ++--
 include/rtl/stringconcat.hxx |   20 +---
 include/rtl/ustring.hxx  |4 ++--
 3 files changed, 17 insertions(+), 11 deletions(-)

New commits:
commit 58dd5870a77344754ea459d8423d1b3787a6a813
Author: Stephan Bergmann 
AuthorDate: Mon Mar 27 14:22:03 2023 +0200
Commit: Stephan Bergmann 
CommitDate: Mon Mar 27 15:18:44 2023 +

Avoid dangling references to temporary O[U]StringConcatMarker instances

...which were created in O[U]String::Concat and bound to 
O[U]StringConcat::left.
Thanks to Mike Kaganski for finding this.

Change-Id: Id7838bc55eec7cba8860c2ec21a247bf4abd3c62
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149629
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 6af1a1a3b339..70829b43aae2 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -2229,14 +2229,14 @@ public:
 // would not compile):
 template [[nodiscard]] static
 OStringConcat
-Concat(T const & value) { return OStringConcat({}, 
value); }
+Concat(T const & value) { return OStringConcat(value); }
 
 // This overload is needed so that an argument of type 'char const[N]' 
ends up as
 // 'OStringConcat' rather than as
 // 'OStringConcat':
 template [[nodiscard]] static
 OStringConcat
-Concat(T (& value)[N]) { return OStringConcat({}, value); }
+Concat(T (& value)[N]) { return OStringConcat(value); }
 #endif
 };
 
diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx
index 4d4eccd60ba4..c94f8b919e14 100644
--- a/include/rtl/stringconcat.hxx
+++ b/include/rtl/stringconcat.hxx
@@ -459,16 +459,22 @@ template struct 
ToStringHelper> {
 // An internal marker class used by O(U)String::Concat:
 template struct StringConcatMarker {};
 
-template struct ToStringHelper> {
-static constexpr std::size_t length(StringConcatMarker) { return 0; }
-
-constexpr C * operator()(C * buffer, StringConcatMarker) const 
SAL_RETURNS_NONNULL
-{ return buffer; }
-};
-
 using OStringConcatMarker = StringConcatMarker;
 using OUStringConcatMarker = StringConcatMarker;
 
+template constexpr bool allowStringConcat> = true;
+
+template , 
int> Dummy>
+struct StringConcat, T2, Dummy>
+{
+public:
+StringConcat( const T2& right_ ) : right( right_ ) {}
+std::size_t length() const { return ToStringHelper< T2 >::length( right ); 
}
+C* addData( C* buffer ) const SAL_RETURNS_NONNULL { return ToStringHelper< 
T2 >()( buffer, right ); }
+private:
+const T2& right;
+};
+
 } // namespace
 
 #endif
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 008f820bb3b1..c3966ac15cab 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -3313,14 +3313,14 @@ public:
 // would not compile):
 template [[nodiscard]] static
 OUStringConcat
-Concat(T const & value) { return OUStringConcat({}, value); }
+Concat(T const & value) { return OUStringConcat(value); }
 
 // This overload is needed so that an argument of type 'char const[N]' 
ends up as
 // 'OUStringConcat' rather than 
as
 // 'OUStringConcat':
 template [[nodiscard]] static
 OUStringConcat
-Concat(T (& value)[N]) { return OUStringConcat({}, value); }
+Concat(T (& value)[N]) { return OUStringConcat(value); }
 #endif
 
 private:


[Libreoffice-commits] core.git: include/rtl

2023-03-17 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx  |   15 ++-
 include/rtl/ustring.hxx |   15 ++-
 2 files changed, 28 insertions(+), 2 deletions(-)

New commits:
commit b8f131d4cc0454ffe4f809763ce6bccafeab3eb0
Author: Stephan Bergmann 
AuthorDate: Thu Mar 16 11:52:29 2023 +0100
Commit: Stephan Bergmann 
CommitDate: Fri Mar 17 14:52:05 2023 +

Towards literal O[U]String types in C++20

...(where destructors can be constexpr), making
21584b304b21bfe6b99b6f29018c6b754ea28fc0 "make OUString(OUStringLiteral)
constructor constexpr" and 983c1146ac80c038feae653e8e3752a72171d6cb 
"actually
make OString(OStringLiteral) constructor constexpr" actually useful and
eventually removing the need for O[U]StringConstExpr again

Change-Id: I55520c1d928758f61e92336206e0f14b6f12a711
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148978
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 0a90fc9f04a3..6af1a1a3b339 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -452,9 +452,22 @@ public:
 /**
   Release the string data.
 */
+#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+constexpr
+#endif
 ~OString()
 {
-rtl_string_release( pData );
+#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+if (std::is_constant_evaluated()) {
+   //TODO: We would want to
+   //
+   //   assert(SAL_STRING_IS_STATIC(pData));
+   //
+   // here, but that wouldn't work because read of member `str` of 
OUStringLiteral's
+   // anonymous union with active member `more` is not allowed in a 
constant expression.
+} else
+#endif
+rtl_string_release( pData );
 }
 
 #if defined LIBO_INTERNAL_ONLY
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index f8b5fb461d2f..008f820bb3b1 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -521,9 +521,22 @@ public:
 /**
   Release the string data.
 */
+#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+constexpr
+#endif
 ~OUString()
 {
-rtl_uString_release( pData );
+#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+if (std::is_constant_evaluated()) {
+   //TODO: We would want to
+   //
+   //   assert(SAL_STRING_IS_STATIC(pData));
+   //
+   // here, but that wouldn't work because read of member `str` of 
OUStringLiteral's
+   // anonymous union with active member `more` is not allowed in a 
constant expression.
+} else
+#endif
+rtl_uString_release( pData );
 }
 
 /** Provides an OUString const & passing a storage pointer of an


[Libreoffice-commits] core.git: include/rtl svl/source

2023-03-13 Thread Mike Kaganski (via logerrit)
 include/rtl/ustrbuf.hxx|   33 +
 svl/source/numbers/zformat.cxx |   19 +++
 2 files changed, 40 insertions(+), 12 deletions(-)

New commits:
commit 2cb2e2b9c1d55bbbc639997ca30fd6b57a81bfb2
Author: Mike Kaganski 
AuthorDate: Mon Mar 13 12:11:04 2023 +0300
Commit: Mike Kaganski 
CommitDate: Mon Mar 13 13:05:41 2023 +

Introduce OUStringBuffer::insert taking OUStringConcat

Avoids some (re)allocations, and aligns with already existing append

Change-Id: I536ba50f56fc560c0f6e8c0a8b65bd4248896a8e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148777
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index af7d0d0d9ef6..cdfb28ab556c 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -43,6 +43,7 @@
 #include "sal/types.h"
 
 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
+#include "o3tl/safeint.hxx"
 #include "rtl/stringconcat.hxx"
 #endif
 
@@ -1015,6 +1016,38 @@ public:
 }
 #endif
 
+#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
+/**
+ @overload
+ @internal
+*/
+template 
+OUStringBuffer& insert(sal_Int32 offset, OUStringConcat&& c)
+{
+const size_t l = c.length();
+if (l == 0)
+return *this;
+if (l > o3tl::make_unsigned(std::numeric_limits::max() - 
pData->length))
+throw std::bad_alloc();
+
+rtl_uStringbuffer_insert(, , offset, nullptr, l);
+
+/* insert the new characters */
+c.addData(pData->buffer + offset);
+return *this;
+}
+
+/**
+ @overload
+ @internal
+*/
+template 
+OUStringBuffer& insert(sal_Int32 offset, StringNumberBase&& c)
+{
+return insert(offset, c.buf, c.length);
+}
+#endif
+
 /**
 Inserts the string representation of the char array
 argument into this string buffer.
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index effb34ad996f..549194736e69 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -709,7 +709,7 @@ OUString SvNumberformat::ImpObtainCalendarAndNumerals( 
OUStringBuffer& rString,
 if ( nNumeralID >= 0x02 && nNumeralID <= 0x13 )
 nNatNum = 1;
 if ( nNatNum )
-rString.insert( nPos, 
Concat2View("[NatNum"+OUString::number(nNatNum)+"]"));
+rString.insert(nPos, "[NatNum" + OUString::number(nNatNum) + "]");
 return sCalendar;
 }
 
@@ -1101,11 +1101,8 @@ SvNumberformat::SvNumberformat(OUString& rString,
 sBuff.remove(nPosOld, nPos - nPosOld);
 if (!sStr.isEmpty())
 {
-sBuff.insert(nPosOld, sStr);
-nPos = nPosOld + sStr.getLength();
-sBuff.insert(nPos, "]");
-sBuff.insert(nPosOld, "[");
-nPos += 2;
+sBuff.insert(nPosOld, "[" + sStr + "]");
+nPos = nPosOld + sStr.getLength() + 2;
 nPosOld = nPos; // position before string
 }
 else
@@ -5210,18 +5207,16 @@ static void lcl_insertLCID( OUStringBuffer& rFormatStr, 
sal_uInt32 nLCID, sal_In
 // No format code, no locale.
 return;
 
-OUStringBuffer aLCIDString = OUString::number( nLCID , 16 
).toAsciiUpperCase();
+auto aLCIDString = OUString::number( nLCID , 16 ).toAsciiUpperCase();
 // Search for only last DBNum which is the last element before insertion 
position
 if ( bDBNumInserted && nPosInsertLCID >= 8
-&& aLCIDString.getLength() > 4
-&& rFormatStr.indexOf( "[DBNum", nPosInsertLCID-8) == nPosInsertLCID-8 
)
+&& aLCIDString.length > 4
+&& OUString::unacquired(rFormatStr).match( "[DBNum", nPosInsertLCID-8) 
)
 {   // remove DBNumX code if long LCID
 nPosInsertLCID -= 8;
 rFormatStr.remove( nPosInsertLCID, 8 );
 }
-aLCIDString.insert( 0, "[$-" );
-aLCIDString.append( "]" );
-rFormatStr.insert( nPosInsertLCID, aLCIDString );
+rFormatStr.insert( nPosInsertLCID, "[$-" + aLCIDString + "]" );
 }
 
 /** Increment nAlphabetID for CJK numerals


[Libreoffice-commits] core.git: include/rtl

2023-02-12 Thread Mike Kaganski (via logerrit)
 include/rtl/uri.hxx |   10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

New commits:
commit 30a215f3cee1acdb4df3285512603abede8d3ff1
Author: Mike Kaganski 
AuthorDate: Mon Feb 13 07:35:35 2023 +0300
Commit: Mike Kaganski 
CommitDate: Mon Feb 13 05:26:23 2023 +

These const_casts are unneeded

Change-Id: I4b1d81665f9bfeb040530bac6bafa3ee2c85782f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146849
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/rtl/uri.hxx b/include/rtl/uri.hxx
index 1b2601e7d1d1..3221a9fba8b2 100644
--- a/include/rtl/uri.hxx
+++ b/include/rtl/uri.hxx
@@ -92,7 +92,7 @@ inline rtl::OUString Uri::encode(rtl::OUString const & rText,
  rtl_TextEncoding eCharset)
 {
 rtl::OUString aResult;
-rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData,
+rtl_uriEncode(rText.pData,
   pCharClass,
   eMechanism,
   eCharset,
@@ -106,7 +106,7 @@ inline rtl::OUString Uri::encode(rtl::OUString const & 
rText,
  rtl_TextEncoding eCharset)
 {
 rtl::OUString aResult;
-rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData,
+rtl_uriEncode(rText.pData,
   rtl_getUriCharClass(eCharClass),
   eMechanism,
   eCharset,
@@ -119,7 +119,7 @@ inline rtl::OUString Uri::decode(rtl::OUString const & 
rText,
  rtl_TextEncoding eCharset)
 {
 rtl::OUString aResult;
-rtl_uriDecode(const_cast< rtl::OUString & >(rText).pData,
+rtl_uriDecode(rText.pData,
   eMechanism,
   eCharset,
   );
@@ -132,8 +132,8 @@ inline rtl::OUString Uri::convertRelToAbs(rtl::OUString 
const & rBaseUriRef,
 rtl::OUString aResult;
 rtl::OUString aException;
 if (!rtl_uriConvertRelToAbs(
-const_cast< rtl::OUString & >(rBaseUriRef).pData,
-const_cast< rtl::OUString & >(rRelUriRef).pData, ,
+rBaseUriRef.pData,
+rRelUriRef.pData, ,
 ))
 throw MalformedUriException(aException);
 return aResult;


[Libreoffice-commits] core.git: include/rtl

2023-01-24 Thread Tor Lillqvist (via logerrit)
 include/rtl/string.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit a771945f982a228e9076195bae5bdd0c8aaf60b3
Author: Tor Lillqvist 
AuthorDate: Tue Jan 24 14:26:27 2023 +0200
Commit: Tor Lillqvist 
CommitDate: Tue Jan 24 14:02:40 2023 +

Be consistent in checks for LIBO_INTERNAL_ONLY

Only check whether LIBO_INTERNAL_ONLY is defined or not. Don't check its 
value.

If undefined, its value will default to 0, but checking the value will
cause a warning that will be treated as an error if you compile with
-Werror, as you should.

Change-Id: I1d9e4569a016d2e6dbaa9d612071a5528ff1902e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146066
Tested-by: Jenkins
Reviewed-by: Tor Lillqvist 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 24c6a64008cf..0a90fc9f04a3 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -457,7 +457,7 @@ public:
 rtl_string_release( pData );
 }
 
-#if LIBO_INTERNAL_ONLY
+#if defined LIBO_INTERNAL_ONLY
 /** Provides an OString const & passing a storage pointer of an
 rtl_String * handle.
 It is more convenient to use C++ OString member functions when dealing


[Libreoffice-commits] core.git: include/rtl

2022-11-28 Thread Noel Grandin (via logerrit)
 include/rtl/ustring.hxx |2 --
 1 file changed, 2 deletions(-)

New commits:
commit af826c85c2eb519b9a3f76099c0e70604d9679e2
Author: Noel Grandin 
AuthorDate: Mon Nov 28 15:56:52 2022 +0200
Commit: Noel Grandin 
CommitDate: Mon Nov 28 19:17:41 2022 +0100

tdf#133343 improve perf of OUString::operator=(&&)

shaves 4% off the save time here.

We don't need to do this - either the old rtl_uString will be
overwritten in the source object, or it will be destructed, either way,
re-initialising it is a waste of time.

Change-Id: I47becb17de1e47f2a26c2ac4497e769e13523115
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143403
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 16ccecedd7a9..f8b5fb461d2f 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -577,8 +577,6 @@ public:
 OUString & operator=( OUString && str ) noexcept
 {
 std::swap(pData, str.pData);
-// rtl_uString_new will release any existing data before assigning 
empty
-rtl_uString_new(  );
 return *this;
 }
 #endif


[Libreoffice-commits] core.git: include/rtl l10ntools/source sal/osl sal/qa sc/source unotools/source

2022-11-08 Thread Stephan Bergmann (via logerrit)
 include/rtl/strbuf.hxx   |   11 +++
 include/rtl/string.hxx   |9 +
 l10ntools/source/po.cxx  |4 ++--
 sal/osl/unx/uunxapi.cxx  |2 +-
 sal/qa/rtl/strings/nonconstarray.cxx |   20 
 sc/source/filter/excel/xestream.cxx  |2 +-
 sc/source/filter/html/htmlexp.cxx|2 +-
 sc/source/filter/xcl97/XclExpChangeTrack.cxx |2 +-
 unotools/source/i18n/resmgr.cxx  |2 +-
 9 files changed, 47 insertions(+), 7 deletions(-)

New commits:
commit 46875d83476942ca215429c837a3457f55c3ccb0
Author: Stephan Bergmann 
AuthorDate: Tue Nov 8 11:51:13 2022 +0100
Commit: Stephan Bergmann 
CommitDate: Tue Nov 8 17:28:32 2022 +0100

A better fix for C++23 P2266R1

After 6d6a143913603b040c10a5db83c2103557899011 "Address some of the sprintf 
in
vcl/source/fontsubset/cff.cxx", --with-latest-c++ builds that pick up a 
C++23
compiler that implements
 
"P2266R1:
Simpler implicit move" started to fail with something like

> vcl/source/fontsubset/cff.cxx:2061:16: error: no viable conversion from 
returned value of type 'char[64]' to function return type 'OString'
> return aDefaultGlyphName;
>^
[...]
> include/rtl/string.hxx:313:5: note: candidate constructor [with T = 
char[64]] not viable: expects an lvalue for 1st argument
> OString( T& value, typename 
libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy 
>::Type = libreoffice_internal::Dummy() )
> ^

etc.  So I figured there should be something better than
433ab39b2175bdadb4916373cd2dc8e1aabc08a5 "Adapt implicit OString return 
value
construction to C++23 P2266R1" (which this commit reverts, modulo its 
conflicts
in comphelper/source/xml/xmltools.cxx and
sc/source/filter/xcl97/XclExpChangeTrack.cxx) to address the underlying 
issue in
a way that keeps code that works up to C++20 also working in C++23.

(The fix is only relevant for non-explicit constructors that involve
NonConstCharArrayDetector and non-const lvalue references, not for other
functions involving those.  OUString has a similar constructor but which is
explicit, and OUStringBuffer doesn't have any similar constructors at all, 
so
this only affects OString and OStringBuffer constructors.)

Change-Id: I31cf16b9507899f5999243f8467dfa24bc94c5ac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142455
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index dbdcd7fea39a..97368ce3ca4d 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -180,6 +180,17 @@ public:
 rtl_stringbuffer_newFromStr_WithLength( , value, length );
 }
 
+#if __cplusplus > 202002L // C++23 P2266R3 "Simpler implicit move"
+template< typename T >
+OStringBuffer( T&& value, typename 
libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy 
>::Type = libreoffice_internal::Dummy())
+: pData(NULL)
+{
+sal_Int32 length = rtl_str_getLength( value );
+nCapacity = length + 16;
+rtl_stringbuffer_newFromStr_WithLength( , value, length );
+}
+#endif
+
 /**
   Constructs a string buffer so that it represents the same
 sequence of characters as the string literal.
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 472d3074bd1b..24c6a64008cf 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -316,6 +316,15 @@ public:
 rtl_string_newFromStr( , value );
 }
 
+#if __cplusplus > 202002L // C++23 P2266R3 "Simpler implicit move"
+template< typename T >
+OString( T&& value, typename 
libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy 
>::Type = libreoffice_internal::Dummy() )
+{
+pData = NULL;
+rtl_string_newFromStr( , value );
+}
+#endif
+
 /**
   New string from a string literal.
 
diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx
index b053067ea163..e075d52b0bd5 100644
--- a/l10ntools/source/po.cxx
+++ b/l10ntools/source/po.cxx
@@ -425,7 +425,7 @@ OString PoEntry::genKeyId(const OString& rGenerator)
 nCRC >>= 6;
 }
 sKeyId[5] = '\0';
-return OString(sKeyId);
+return sKeyId;
 }
 
 namespace
@@ -437,7 +437,7 @@ namespace
 struct tm* pNow = localtime();
 char pBuff[50];
 strftime( pBuff, sizeof pBuff, "%Y-%m-%d %H:%M%z", pNow );
-return OString(pBuff);
+return pBuff;
 }
 }
 
diff --git a/sal/osl/unx/uunxapi.cxx b/sal/osl/unx/uunxapi.cxx
index 5311bc71917f..d1fc6c4f9d3f 100644
--- a/sal/osl/unx/uunxapi.cxx
+++ b/sal/osl/unx/uunxapi.cxx
@@ -154,7 +154,7 @@ 

[Libreoffice-commits] core.git: include/rtl vcl/source

2022-11-08 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx|   57 +++
 vcl/source/fontsubset/cff.cxx |  668 +-
 2 files changed, 587 insertions(+), 138 deletions(-)

New commits:
commit 6d6a143913603b040c10a5db83c2103557899011
Author: Stephan Bergmann 
AuthorDate: Mon Nov 7 16:03:15 2022 +0100
Commit: Stephan Bergmann 
CommitDate: Tue Nov 8 09:20:23 2022 +0100

Address some of the sprintf in vcl/source/fontsubset/cff.cxx

...(which cause -Werror,-Wdeprecated-declarations with macOS 13 SDK), by 
making
CffSubsetterContext::getString, and in turn 
CffSubsetterContext::getGlyphName,
return OString.  Which in turn required adding rtl::OStringConstExpr and
OString::unacquired counterparts of rtl/ustring.hxx functionality to
rtl/string.hxx.

(It's not quite clear to me whether the nMaxLen clipping in
CffSubsetterContext::getString was only there to avoid overflow of the--
somewhat arbitrarily sized?---static aNameBuf, so could go now, or rather 
served
as a more general safety measure to not read past the mpReadPtr buffer end 
and
should thus remain.  Hence, I added a TODO comment for now.)

Change-Id: I473d5a54a4be5b02917e197391e4f0982dcf690c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142412
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 3d9ef8ff9aa3..472d3074bd1b 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -77,6 +77,7 @@ namespace rtl
 /// @endcond
 
 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
+
 /**
 A wrapper dressing a string literal as a static-refcount rtl_String.
 
@@ -87,6 +88,7 @@ template class SAL_WARN_UNUSED OStringLiteral {
 static_assert(N != 0);
 static_assert(N - 1 <= std::numeric_limits::max(), "literal too 
long");
 friend class OString;
+friend class OStringConstExpr;
 
 public:
 #if HAVE_CPP_CONSTEVAL
@@ -148,6 +150,40 @@ private:
 Data more = {};
 };
 };
+
+/**
+  This is intended to be used when declaring compile-time-constant structs or 
arrays
+  that can be initialised from named OStringLiteral e.g.
+
+constexpr OStringLiteral AAA = u"aaa";
+constexpr OStringLiteral BBB = u"bbb";
+constexpr OStringConstExpr FOO[] { AAA, BBB };
+*/
+class OString;
+class OStringConstExpr
+{
+public:
+template constexpr OStringConstExpr(OStringLiteral const 
& literal):
+pData(const_cast()) {}
+
+// prevent mis-use
+template constexpr OStringConstExpr(OStringLiteral && 
literal)
+= delete;
+
+// no destructor necessary because we know we are pointing at a 
compile-time
+// constant OStringLiteral, which bypasses ref-counting.
+
+/**
+  make it easier to pass to OStringBuffer and similar without 
casting/converting
+*/
+constexpr std::string_view asView() const { return 
std::string_view(pData->buffer, pData->length); }
+
+inline operator const OString&() const;
+
+private:
+rtl_String* pData;
+};
+
 #endif
 
 /* === */
@@ -412,6 +448,22 @@ public:
 rtl_string_release( pData );
 }
 
+#if LIBO_INTERNAL_ONLY
+/** Provides an OString const & passing a storage pointer of an
+rtl_String * handle.
+It is more convenient to use C++ OString member functions when dealing
+with rtl_String * handles.  Using this function avoids unnecessary
+acquire()/release() calls for a temporary OString object.
+
+@param ppHandle
+   pointer to storage
+@return
+   OString const & based on given storage
+*/
+static OString const & unacquired( rtl_String * const * ppHandle )
+{ return * reinterpret_cast< OString const * >( ppHandle ); }
+#endif
+
 /**
   Assign a new string.
 
@@ -2166,6 +2218,11 @@ public:
 #endif
 };
 
+#if defined LIBO_INTERNAL_ONLY
+// Can only define this after we define OString
+inline OStringConstExpr::operator const OString &() const { return 
OString::unacquired(); }
+#endif
+
 #if defined LIBO_INTERNAL_ONLY
 inline bool operator ==(OString const & lhs, StringConcatenation const & 
rhs)
 { return lhs == std::string_view(rhs); }
diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx
index 371c3bbc0682..b02d5df4022b 100644
--- a/vcl/source/fontsubset/cff.cxx
+++ b/vcl/source/fontsubset/cff.cxx
@@ -26,6 +26,8 @@
 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -37,105 +39,497 @@ typedef sal_Int64 S64;
 typedef double RealType;
 typedef RealType ValType;
 
-static const char* pStringIds[] = {
-/*0*/   ".notdef",  "space","exclam",   "quotedbl",
-"numbersign",   "dollar",   "percent",  "ampersand",
-"quoteright",   "parenleft","parenright",   "asterisk",
-"plus", "comma","hyphen",   

[Libreoffice-commits] core.git: include/rtl

2022-11-07 Thread Stephan Bergmann (via logerrit)
 include/rtl/ustring.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit c8eaebecd3af29c031c26142c9d3f7d7abf75b0d
Author: Stephan Bergmann 
AuthorDate: Mon Nov 7 15:11:07 2022 +0100
Commit: Stephan Bergmann 
CommitDate: Tue Nov 8 07:15:28 2022 +0100

Avoid an explicit static_cast

...when shoehorning a std::size_t value into sal_Int32, to not suppress
potential warnings from tools like 
-fsanitize=implicit-signed-integer-truncation
and -fsanitize=implicit-integer-sign-change

Change-Id: I610410f7cd69769c3721b2019e16b4c9f214ad81
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142407
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index d7d529f55e3f..16ccecedd7a9 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -163,7 +163,7 @@ public:
 /**
   make it easier to pass to OUStringBuffer and similar without 
casting/converting
 */
-constexpr std::u16string_view asView() const { return {pData->buffer, 
static_cast(pData->length)}; }
+constexpr std::u16string_view asView() const { return 
std::u16string_view(pData->buffer, pData->length); }
 
 inline operator const OUString&() const;
 


[Libreoffice-commits] core.git: include/rtl

2022-11-07 Thread Stephan Bergmann (via logerrit)
 include/rtl/ustring.hxx |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

New commits:
commit 1ec337b100755f7ad8cd5cb2c8acb072c6f18964
Author: Stephan Bergmann 
AuthorDate: Mon Nov 7 15:06:03 2022 +0100
Commit: Stephan Bergmann 
CommitDate: Tue Nov 8 07:15:08 2022 +0100

Remove some trailing whitespace noise

...from ustring.hxx, in preparation of using its OUStringConstExpr as a
blueprint for a corresponding OStringConstExpr in string.hxx

Change-Id: I3bf89133e9308dd56e2041a2a5ebb68145fdd0e6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142406
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 69575289f6f5..d7d529f55e3f 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -152,7 +152,7 @@ class OUStringConstExpr
 public:
 template constexpr OUStringConstExpr(OUStringLiteral 
const & literal):
 pData(const_cast()) {}
-
+
 // prevent mis-use
 template constexpr OUStringConstExpr(OUStringLiteral && 
literal)
 = delete;
@@ -3388,7 +3388,6 @@ inline std::basic_ostream & operator <<(
 return stream << OUString( std::move(concat) );
 }
 
-
 /// @endcond
 #endif
 


[Libreoffice-commits] core.git: include/rtl

2022-10-15 Thread Stephan Bergmann (via logerrit)
 include/rtl/stringconcat.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 1b9db6c99e5b5f4edb837756e50e949f0ef3a357
Author: Stephan Bergmann 
AuthorDate: Fri Oct 14 16:03:39 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Sat Oct 15 08:50:07 2022 +0200

Restrict StringNumberBase::toAsciiUpperCase to rvalues

Change-Id: I2cc4787d0db256337fe740e9cecb96ce7081bffc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141374
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx
index 24dabe15c0bb..4d4eccd60ba4 100644
--- a/include/rtl/stringconcat.hxx
+++ b/include/rtl/stringconcat.hxx
@@ -334,7 +334,7 @@ template  struct StringNumber
 // so implement that one also here, to avoid having to explicitly convert
 // to O(U)String in all such places
 const C* getStr() const SAL_RETURNS_NONNULL { return buf; }
-StringNumberBase&& toAsciiUpperCase()
+StringNumberBase&& toAsciiUpperCase() &&
 {
 if constexpr (sizeof(C) == sizeof(char))
 rtl_str_toAsciiUpperCase_WithLength(buf, length);


[Libreoffice-commits] core.git: include/rtl

2022-09-19 Thread Noel Grandin (via logerrit)
 include/rtl/ustring.hxx |5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

New commits:
commit 891d618bfdcf369119807d826e8ec6e3b112d73c
Author: Noel Grandin 
AuthorDate: Mon Sep 19 10:42:24 2022 +0200
Commit: Noel Grandin 
CommitDate: Mon Sep 19 13:03:04 2022 +0200

make OUString::operator=(OUString&&) a little faster

one function call instead of two, and this function is pretty hot

Change-Id: Ibb09ad9b930f337706fa392a1644077c82dbc61e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140140
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 8e29742b588d..c9067905a0a0 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -576,9 +576,8 @@ public:
 */
 OUString & operator=( OUString && str ) noexcept
 {
-rtl_uString_release( pData );
-pData = str.pData;
-str.pData = nullptr;
+std::swap(pData, str.pData);
+// rtl_uString_new will release any existing data before assigning 
empty
 rtl_uString_new(  );
 return *this;
 }


[Libreoffice-commits] core.git: include/rtl

2022-08-22 Thread Mike Kaganski (via logerrit)
 include/rtl/strbuf.hxx  |2 +-
 include/rtl/string.hxx  |3 +--
 include/rtl/ustrbuf.hxx |3 +--
 include/rtl/ustring.hxx |   15 +--
 4 files changed, 8 insertions(+), 15 deletions(-)

New commits:
commit 2b06b5caeaa336de52746869fa91adfa6895f811
Author: Mike Kaganski 
AuthorDate: Mon Aug 22 10:19:15 2022 +0300
Commit: Mike Kaganski 
CommitDate: Mon Aug 22 10:40:37 2022 +0200

Remove NULL-terminated requirement where not applicable

These functions take the string length instead, so may take
non-NULL-terminated strings.

Change-Id: I21dbfd97adec197ba52ae5f9e01340b44689805b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138658
Reviewed-by: Stephan Bergmann 
Tested-by: Jenkins

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 098e8b0bbc97..5917c1812e9c 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -394,7 +394,7 @@ public:
 
 The capacity
 is the amount of storage available for newly inserted
-characters. The real buffer size is 2 bytes longer, because
+characters. The real buffer size is 1 byte longer, because
 all strings are 0 terminated.
 
 @return  the current capacity of this string buffer.
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 837fa89bd2b4..9ae30586e549 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -697,8 +697,7 @@ public:
 
   The result is true if and only if second string
   represents the same sequence of characters as the first string.
-  The ASCII string must be NULL-terminated and must be greater or
-  equal as length.
+  The ASCII string must be greater or equal as length.
   This function can't be used for language specific comparison.
 
 
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 605fb1efb6d0..c5d6b2e9ee1b 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -756,8 +756,7 @@ public:
 Since this method is optimized for performance. the ASCII
 character values are not converted in any way. The caller
 has to make sure that all ASCII characters are in the
-allowed range between 0 and 127. The ASCII string must be
-NULL-terminated.
+allowed range between 0 and 127.
 
 Characters of the character array str are appended,
 in order, to the contents of this string buffer. The length of this
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 79ad75d8304d..8e29742b588d 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -1205,8 +1205,7 @@ public:
   Since this method is optimized for performance, the ASCII character
   values are not converted in any way. The caller has to make sure that
   all ASCII characters are in the allowed range between 0 and 127.
-  The ASCII string must be NULL-terminated and must be greater than
-  or equal to asciiStrLength.
+  The ASCII string must be greater than or equal to asciiStrLength.
   This function can't be used for language specific sorting.
 
   @paramasciiStrthe 8-Bit ASCII character string to be 
compared.
@@ -1250,8 +1249,7 @@ public:
   Since this method is optimized for performance, the ASCII character
   values are not converted in any way. The caller has to make sure that
   all ASCII characters are in the allowed range between 0 and 127.
-  The ASCII string must be NULL-terminated and must be greater than
-  or equal to asciiStrLength.
+  The ASCII string must be greater than or equal to asciiStrLength.
   This function can't be used for language specific comparison.
 
   @paramasciiStr the 8-Bit ASCII character string to be 
compared.
@@ -1325,8 +1323,7 @@ public:
   Since this method is optimized for performance, the ASCII character
   values are not converted in any way. The caller has to make sure that
   all ASCII characters are in the allowed range between 0 and 127.
-  The ASCII string must be NULL-terminated and must be greater than
-  or equal to asciiStrLength.
+  The ASCII string must be greater than or equal to asciiStrLength.
   This function can't be used for language specific comparison.
 
   @paramasciiStrthe 8-Bit ASCII character string to be 
compared.
@@ -1350,8 +1347,7 @@ public:
   Since this method is optimized for performance, the ASCII character
   values are not converted in any way. The caller has to make sure that
   all ASCII characters are in the allowed range between 0 and 127.
-  The ASCII string must be NULL-terminated and must be greater than or
-  equal to asciiStrLength.
+  The ASCII string must be greater than or equal to asciiStrLength.
   This function can't be used for language specific comparison.
 
   @paramasciiStrthe object (substring) to be compared.
@@ -1388,8 

[Libreoffice-commits] core.git: include/rtl

2022-08-22 Thread Noel Grandin (via logerrit)
 include/rtl/string.hxx  |   13 -
 include/rtl/ustring.hxx |   13 -
 2 files changed, 24 insertions(+), 2 deletions(-)

New commits:
commit db04b3e154a1fb8f32ef969bb3617e051329
Author: Noel Grandin 
AuthorDate: Sat Aug 20 10:57:19 2022 +0200
Commit: Noel Grandin 
CommitDate: Mon Aug 22 09:35:31 2022 +0200

return 64-bit hash for O[U]String

which gives better performance when putting strings into hashed
containers that expect good key distribution.
This hash implementation is the same one that Java uses.

Change-Id: Iae5cf3cd27309856acfa51781295f2e56c8e77db
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138574
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 0e3dad6926e8..837fa89bd2b4 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -2301,7 +2301,18 @@ template<>
 struct hash<::rtl::OString>
 {
 std::size_t operator()(::rtl::OString const & s) const
-{ return std::size_t(s.hashCode()); }
+{
+if constexpr (sizeof(std::size_t) == 8)
+{
+// return a hash that uses the full 64-bit range instead of a 
32-bit value
+size_t n = 0;
+for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
+n = 31 * n + s[i];
+return n;
+}
+else
+return std::size_t(s.hashCode());
+}
 };
 
 }
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index e6d3ed682932..79ad75d8304d 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -3547,7 +3547,18 @@ template<>
 struct hash<::rtl::OUString>
 {
 std::size_t operator()(::rtl::OUString const & s) const
-{ return std::size_t(s.hashCode()); }
+{
+if constexpr (sizeof(std::size_t) == 8)
+{
+// return a hash that uses the full 64-bit range instead of a 
32-bit value
+size_t n = 0;
+for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
+n = 31 * n + s[i];
+return n;
+}
+else
+return std::size_t(s.hashCode());
+}
 };
 
 }


[Libreoffice-commits] core.git: include/rtl vcl/inc vcl/source

2022-06-21 Thread Jan-Marek Glogowski (via logerrit)
 include/rtl/ustrbuf.hxx   |   15 +++
 vcl/inc/salframe.hxx  |1 +
 vcl/source/app/salvtables.cxx |   24 
 3 files changed, 40 insertions(+)

New commits:
commit bf35c2b7f4b9fa18e387e2ee8df518303696e13c
Author: Jan-Marek Glogowski 
AuthorDate: Mon Jun 13 03:53:54 2022 +0200
Commit: Jan-Marek Glogowski 
CommitDate: Tue Jun 21 13:39:40 2022 +0200

OUStringBuffer: add append via operator<<(T&&)

... and use it to implement SalFrame::DumpSetPosSize.

Change-Id: I82301f7e1f6641d6167c9577ce9ef44ef8067297
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135808
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski 

diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 8c8cc54f8f01..605fb1efb6d0 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -34,6 +34,7 @@
 #if defined LIBO_INTERNAL_ONLY
 #include 
 #include 
+#include 
 #endif
 
 #include "rtl/ustrbuf.h"
@@ -974,6 +975,20 @@ public:
 return pData->buffer + n;
 }
 
+#if defined LIBO_INTERNAL_ONLY
+/**
+   "Stream" operator to append a value to this OUStringBuffer.
+
+   @internal
+   @since LibreOffice 7.5
+ */
+template
+OUStringBuffer& operator<<(T&& rValue)
+{
+return append(std::forward(rValue));
+}
+#endif
+
 /**
 Inserts the string into this string buffer.
 
diff --git a/vcl/inc/salframe.hxx b/vcl/inc/salframe.hxx
index 45ed72956656..552d88eb2519 100644
--- a/vcl/inc/salframe.hxx
+++ b/vcl/inc/salframe.hxx
@@ -156,6 +156,7 @@ public:
 virtual voidSetMinClientSize( tools::Long nWidth, tools::Long 
nHeight ) = 0;
 virtual voidSetMaxClientSize( tools::Long nWidth, tools::Long 
nHeight ) = 0;
 virtual voidSetPosSize( tools::Long nX, tools::Long nY, 
tools::Long nWidth, tools::Long nHeight, sal_uInt16 nFlags ) = 0;
+static OUString DumpSetPosSize(tools::Long nX, tools::Long nY, tools::Long 
nWidth, tools::Long nHeight, sal_uInt16 nFlags);
 virtual voidGetClientSize( tools::Long& rWidth, tools::Long& 
rHeight ) = 0;
 virtual voidGetWorkArea( tools::Rectangle& rRect ) = 0;
 virtual SalFrame*   GetParent() const = 0;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index b6db52c8b87d..40c04421b8d5 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -111,6 +111,30 @@ void SalFrame::SetRepresentedURL(const OUString&)
 // currently this is Mac only functionality
 }
 
+OUString SalFrame::DumpSetPosSize(tools::Long nX, tools::Long nY, tools::Long 
nWidth,
+  tools::Long nHeight, sal_uInt16 nFlags)
+{
+// assuming the 4 integers normally don't have more then 4 digits, but 
might be negative
+OUStringBuffer aBuffer(4 * 5 + 5);
+if (nFlags & SAL_FRAME_POSSIZE_WIDTH)
+aBuffer << nWidth << "x";
+else
+aBuffer << "?x";
+if (nFlags & SAL_FRAME_POSSIZE_HEIGHT)
+aBuffer << nHeight << "@(";
+else
+aBuffer << "?@(";
+if (nFlags & SAL_FRAME_POSSIZE_X)
+aBuffer << nX << ",";
+else
+aBuffer << "?,";
+if (nFlags & SAL_FRAME_POSSIZE_Y)
+aBuffer << nY << ")";
+else
+aBuffer << "?)";
+return aBuffer.makeStringAndClear();
+}
+
 SalInstance::SalInstance(std::unique_ptr pMutex)
 : m_pYieldMutex(std::move(pMutex))
 {


[Libreoffice-commits] core.git: include/rtl

2022-05-29 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx |   20 
 1 file changed, 16 insertions(+), 4 deletions(-)

New commits:
commit 1959d451da06f501dd3446ebfe9c631b5400af26
Author: Stephan Bergmann 
AuthorDate: Sun May 29 16:51:55 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Sun May 29 18:38:44 2022 +0200

Improve some operator== involving OString,

avoiding creation of temporary OString instances

Change-Id: I27b4cb59b48b3ba40311a1f935a20250c8317d00
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135093
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index e99581cd6f94..0e3dad6926e8 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -1180,25 +1180,37 @@ public:
 template< typename T >
 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type 
operator==( const OString& rStr1, const T& value )
 {
-return rStr1.compareTo( value ) == 0;
+return
+rtl_str_compare_WithLength(
+rStr1.getStr(), rStr1.getLength(), value, 
rtl_str_getLength(value))
+== 0;
 }
 
 template< typename T >
 friend typename libreoffice_internal::NonConstCharArrayDetector< T, bool 
>::Type operator==( const OString& rStr1, T& value )
 {
-return rStr1.compareTo( value ) == 0;
+return
+rtl_str_compare_WithLength(
+rStr1.getStr(), rStr1.getLength(), value, 
rtl_str_getLength(value))
+== 0;
 }
 
 template< typename T >
 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type 
operator==( const T& value, const OString& rStr2 )
 {
-return rStr2.compareTo( value ) == 0;
+return
+rtl_str_compare_WithLength(
+value, rtl_str_getLength(value), rStr2.getStr(), 
rStr2.getLength())
+== 0;
 }
 
 template< typename T >
 friend typename libreoffice_internal::NonConstCharArrayDetector< T, bool 
>::Type operator==( T& value, const OString& rStr2 )
 {
-return rStr2.compareTo( value ) == 0;
+return
+rtl_str_compare_WithLength(
+value, rtl_str_getLength(value), rStr2.getStr(), 
rStr2.getLength())
+== 0;
 }
 
 /**


[Libreoffice-commits] core.git: include/rtl

2022-05-09 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx  |4 ++--
 include/rtl/ustring.hxx |4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 81d55a0a8b999c58b5b347abd6214d6571ed9923
Author: Stephan Bergmann 
AuthorDate: Mon May 9 14:02:26 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Mon May 9 17:55:16 2022 +0200

Revert "prevent using O[U]String::subView on temporaties"

This reverts commit 59059d00c29334414a26bf5452572433f5735489, as it 
effectively
did nothing, as rvalues can bind to `const &` just fine.
 "Acutally do prevent using
O[U]String::subView on temporaties" would have fixed that, but (a) it didn't
find any actual mis-uses and (b) rather would have required a handful of
legitimate cases to be dressed up with o3tl::temporary now, so is arguably 
not
worth it.

Change-Id: I923d0db2646dc8ea66d1b2a8b709ee2cd7a60ed4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134058
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index f64f2d651730..e99581cd6f94 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -1540,7 +1540,7 @@ public:
   @param beginIndex   the beginning index, inclusive.
   @returnthe specified substring.
 */
-SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex ) 
const &
+SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex ) 
const
 {
 assert(beginIndex >= 0);
 assert(beginIndex <= getLength());
@@ -1559,7 +1559,7 @@ public:
   @param countthe number of characters.
   @returnthe specified substring.
 */
-SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex, 
sal_Int32 count ) const &
+SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex, 
sal_Int32 count ) const
 {
 assert(beginIndex >= 0);
 assert(count >= 0);
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index b7cebaf90647..e6d3ed682932 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -2191,7 +2191,7 @@ public:
   @param beginIndex   the beginning index, inclusive.
   @returnthe specified substring.
 */
-SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex ) 
const &
+SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex ) 
const
 {
 assert(beginIndex >= 0);
 assert(beginIndex <= getLength());
@@ -2210,7 +2210,7 @@ public:
   @param countthe number of characters.
   @returnthe specified substring.
 */
-SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex, 
sal_Int32 count ) const &
+SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex, 
sal_Int32 count ) const
 {
 assert(beginIndex >= 0);
 assert(count >= 0);


[Libreoffice-commits] core.git: include/rtl

2022-05-03 Thread Caolán McNamara (via logerrit)
 include/rtl/ustring.hxx |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

New commits:
commit 4e1cf8411197b4c11a6c5d4728e047e6d46567b5
Author: Caolán McNamara 
AuthorDate: Mon May 2 20:29:05 2022 +0100
Commit: Caolán McNamara 
CommitDate: Tue May 3 09:46:23 2022 +0200

ofz#47198 Use-of-uninitialized-value

seen in ww8 filter with rName of length 0 in if 
(rName.startsWithIgnoreAsciiCase("Tms Rmn")

Change-Id: Ia8a20971161a44d62ead9bfcef59f86b007fd58b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133713
Tested-by: Caolán McNamara 
Reviewed-by: Caolán McNamara 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index ca061328d5a4..b7cebaf90647 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -1526,7 +1526,9 @@ public:
 assert(
 libreoffice_internal::ConstCharArrayDetector::isValid(literal));
 bool b
-= (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
+= (libreoffice_internal::ConstCharArrayDetector::length
+   <= sal_uInt32(pData->length))
+&& (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
pData->buffer,
libreoffice_internal::ConstCharArrayDetector::length,
libreoffice_internal::ConstCharArrayDetector::toPointer(


[Libreoffice-commits] core.git: include/rtl

2022-04-15 Thread Stephan Bergmann (via logerrit)
 include/rtl/strbuf.hxx  |3 +++
 include/rtl/ustrbuf.hxx |3 +++
 2 files changed, 6 insertions(+)

New commits:
commit 21121b0cba765958f38176ba17be85b6bc3bcb58
Author: Stephan Bergmann 
AuthorDate: Thu Apr 14 22:57:56 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Apr 15 09:49:53 2022 +0200

Also add C++20 char8_t overloads

Change-Id: I1c55ca09b9fd24927acce9f0e2e2d435f23a3e42
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133031
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 89301a088d34..098e8b0bbc97 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -122,6 +122,9 @@ public:
 explicit OStringBuffer(bool) = delete;
 explicit OStringBuffer(char) = delete;
 explicit OStringBuffer(wchar_t) = delete;
+#if defined __cpp_char8_t
+explicit OStringBuffer(char8_t) = delete;
+#endif
 explicit OStringBuffer(char16_t) = delete;
 explicit OStringBuffer(char32_t) = delete;
 #endif
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index bb1bb9cef366..8c8cc54f8f01 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -122,6 +122,9 @@ public:
 explicit OUStringBuffer(bool) = delete;
 explicit OUStringBuffer(char) = delete;
 explicit OUStringBuffer(wchar_t) = delete;
+#if defined __cpp_char8_t
+explicit OUStringBuffer(char8_t) = delete;
+#endif
 explicit OUStringBuffer(char16_t) = delete;
 explicit OUStringBuffer(char32_t) = delete;
 #endif


[Libreoffice-commits] core.git: include/rtl

2022-04-13 Thread Stephan Bergmann (via logerrit)
 include/rtl/strbuf.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 634990f32c354dd7690b6ae44b19a94c9f19ffc4
Author: Stephan Bergmann 
AuthorDate: Wed Apr 13 08:10:55 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Apr 13 09:47:11 2022 +0200

Fix copy/paste typo in comment

Change-Id: I90d350abefebf3545c47f9460627435b4a514e07
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132940
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 5c8080466365..7434b2f653a8 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -1068,7 +1068,7 @@ public:
 
 This function should be used with care.  After you have called this
 function, you may use the returned pInternalData and pInternalCapacity
-only as long as you make no other calls on this OUStringBuffer.
+only as long as you make no other calls on this OStringBuffer.
 
 @param pInternalData
 This output parameter receives a pointer to the internal data


[Libreoffice-commits] core.git: include/rtl

2022-04-08 Thread Noel Grandin (via logerrit)
 include/rtl/string.hxx  |4 ++--
 include/rtl/ustring.hxx |4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 59059d00c29334414a26bf5452572433f5735489
Author: Noel Grandin 
AuthorDate: Thu Apr 7 20:33:28 2022 +0200
Commit: Noel Grandin 
CommitDate: Fri Apr 8 08:43:34 2022 +0200

prevent using O[U]String::subView on temporaties

by making the method "const &"

Change-Id: I8b369ca1dd1f8d10832c85ccf3d890edb14e2c54
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132688
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index e99581cd6f94..f64f2d651730 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -1540,7 +1540,7 @@ public:
   @param beginIndex   the beginning index, inclusive.
   @returnthe specified substring.
 */
-SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex ) 
const
+SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex ) 
const &
 {
 assert(beginIndex >= 0);
 assert(beginIndex <= getLength());
@@ -1559,7 +1559,7 @@ public:
   @param countthe number of characters.
   @returnthe specified substring.
 */
-SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex, 
sal_Int32 count ) const
+SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex, 
sal_Int32 count ) const &
 {
 assert(beginIndex >= 0);
 assert(count >= 0);
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 1a6a1cae8990..c530f1702a81 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -2189,7 +2189,7 @@ public:
   @param beginIndex   the beginning index, inclusive.
   @returnthe specified substring.
 */
-SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex ) 
const
+SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex ) 
const &
 {
 assert(beginIndex >= 0);
 assert(beginIndex <= getLength());
@@ -2208,7 +2208,7 @@ public:
   @param countthe number of characters.
   @returnthe specified substring.
 */
-SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex, 
sal_Int32 count ) const
+SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex, 
sal_Int32 count ) const &
 {
 assert(beginIndex >= 0);
 assert(count >= 0);


[Libreoffice-commits] core.git: include/rtl sal/CppunitTest_sal_rtl.mk sal/qa

2022-03-31 Thread Stephan Bergmann (via logerrit)
 include/rtl/strbuf.hxx   |3 
 include/rtl/ustrbuf.hxx  |3 
 sal/CppunitTest_sal_rtl.mk   |1 
 sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx |8 ++
 sal/qa/rtl/strings/test_ostringbuffer.cxx|   56 +++
 5 files changed, 69 insertions(+), 2 deletions(-)

New commits:
commit ca832495ac83117bed6c334f3cc72d6a84d66a6c
Author: Stephan Bergmann 
AuthorDate: Thu Mar 31 09:30:24 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Thu Mar 31 18:52:48 2022 +0200

A string_view is not necessarily NUL-terminated

Regression introduced into LIBO_INTERNAL_ONLY code with
1da69081732c8a429840edaaf10cfb789ea68df8 "add string_view variants of 
methods to
O[U]StringBuffer".

And add some tests.  Assigning an OStringChar to an OStringBuffer also uses 
the
std::string_view assignment operator, so also test that with 
testOStringChar,
even though there it is relatively likely that the OStringChar temporary is
followed by null bytes, which could make the test happen to erroneously 
succeed.
But at least tools like ASan or Valgrind could catch that.  On the other 
hand,
assigning an OUStringChar to an OUStringBuffer does not use the
std::u16string_view assignment operator (and rather uses a
ConstCharArrayDetector-based one, which was similarly broken and has been 
fixed
in b66387574ef9c83cbfff622468496b6f0ac4d571 "Fix -Werror=array-bounds"), so
there's no test for that here.

Change-Id: I7cf10ee5ce0e4280a91d116cd82d4871a0f44af6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132363
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 52399b6da8b4..5c8080466365 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -277,7 +277,8 @@ public:
 if (n >= nCapacity) {
 ensureCapacity(n + 16); //TODO: check for overflow
 }
-std::memcpy(pData->buffer, string.data(), n + 1);
+std::memcpy(pData->buffer, string.data(), n);
+pData->buffer[n] = '\0';
 pData->length = n;
 return *this;
 }
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index fef71f98b329..fa8fa511071a 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -294,7 +294,8 @@ public:
 }
 std::memcpy(
 pData->buffer, string.data(),
-(n + 1) * sizeof (sal_Unicode));
+n * sizeof (sal_Unicode));
+pData->buffer[n] = '\0';
 pData->length = n;
 return *this;
 }
diff --git a/sal/CppunitTest_sal_rtl.mk b/sal/CppunitTest_sal_rtl.mk
index d5f11e49b6d1..2568d8dde70c 100644
--- a/sal/CppunitTest_sal_rtl.mk
+++ b/sal/CppunitTest_sal_rtl.mk
@@ -37,6 +37,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sal_rtl,\
sal/qa/rtl/strings/test_ostring \
sal/qa/rtl/strings/test_ostring_concat \
sal/qa/rtl/strings/test_ostring_stringliterals \
+   sal/qa/rtl/strings/test_ostringbuffer \
sal/qa/rtl/strings/test_oustring_compare \
sal/qa/rtl/strings/test_oustring_concat \
sal/qa/rtl/strings/test_oustring_convert \
diff --git a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx 
b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx
index da5a4634e94b..3c3f436ee5c0 100644
--- a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx
+++ b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx
@@ -9,6 +9,8 @@
 
 #include 
 
+#include 
+
 #include 
 #include 
 #include 
@@ -71,6 +73,12 @@ private:
 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), b4.getLength());
 CPPUNIT_ASSERT_EQUAL(u'a', b4.getStr()[0]);
 CPPUNIT_ASSERT_EQUAL(u'\0', b4.getStr()[1]);
+b4 = std::u16string_view(u"abc").substr(
+0, 2); // avoid the string_view accidentally being NUL-terminated
+CPPUNIT_ASSERT_EQUAL(sal_Int32(2), b4.getLength());
+CPPUNIT_ASSERT_EQUAL(u'a', b4.getStr()[0]);
+CPPUNIT_ASSERT_EQUAL(u'b', b4.getStr()[1]);
+CPPUNIT_ASSERT_EQUAL(u'\0', b4.getStr()[2]);
 }
 
 CPPUNIT_TEST_SUITE(Test);
diff --git a/sal/qa/rtl/strings/test_ostringbuffer.cxx 
b/sal/qa/rtl/strings/test_ostringbuffer.cxx
new file mode 100644
index ..292e24310b7b
--- /dev/null
+++ b/sal/qa/rtl/strings/test_ostringbuffer.cxx
@@ -0,0 +1,56 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * 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 
+
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+namespace
+{
+class 

[Libreoffice-commits] core.git: include/rtl sal/qa

2022-03-31 Thread Stephan Bergmann (via logerrit)
 include/rtl/stringutils.hxx  |4 
 include/rtl/ustrbuf.hxx  |6 +-
 sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx |5 +
 3 files changed, 14 insertions(+), 1 deletion(-)

New commits:
commit b66387574ef9c83cbfff622468496b6f0ac4d571
Author: Stephan Bergmann 
AuthorDate: Thu Mar 31 10:03:39 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Thu Mar 31 16:58:39 2022 +0200

Fix -Werror=array-bounds

> In file included from svtools/source/svrtf/parrtf.cxx:28:
> In member function ‘typename 
rtl::libreoffice_internal::ConstCharArrayDetector::TypeUtf16 rtl::OUStringBuffer::operator=(T&) [with T = 
const rtl::OUStringChar_]’,
> inlined from ‘virtual int SvRTFParser::GetNextToken_()’ at 
svtools/source/svrtf/parrtf.cxx:183:94:
> include/rtl/ustrbuf.hxx:352:20: error: array subscript ‘unsigned int[0]’ 
is partly outside array bounds of ‘rtl::OUStringChar [1]’ {aka ‘const 
rtl::OUStringChar_ [1]’} [-Werror=array-bounds]
>   352 | std::memcpy(
>   | ~~~^
>   353 | pData->buffer,
>   | ~~
>   354 | 
libreoffice_internal::ConstCharArrayDetector::toPointer(literal),
>   | 

>   355 | (n + 1) * sizeof (sal_Unicode)); //TODO: check for 
overflow
>   | ~~~
> svtools/source/svrtf/parrtf.cxx: In member function ‘virtual int 
SvRTFParser::GetNextToken_()’:
> svtools/source/svrtf/parrtf.cxx:183:94: note: object ‘’ of 
size 2
>   183 | aToken = OUStringChar( 
static_cast(nTokenValue) );
>   |   
   ^

as seen with recent GCC 12 trunk in an --enable-optimized build.

And add a test, even though it is relatively likely that the OUStringChar
temporary is followed by null bytes, which would make the test happen to
erroneously succeed.  But at least tools like ASan or Valgrind could catch 
that.

(For the corresponding OStringChar and OStringBuffer scenario, this issue 
does
not arise, as OStringChar is not covered by ConstCharArrayDetector, so the
correpsonding OStringBuffer assignment operator is OK memcpy'ing n+1 
elements.
There /are/ similar issues with string_view assignment operators for both
O[U]StringBuffer, which will be addressed in a later commit.)

Change-Id: Ia131d763aa5f8df45b9625f296408cc935df96ac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132354
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/stringutils.hxx b/include/rtl/stringutils.hxx
index f97b7917f266..be56408c52a8 100644
--- a/include/rtl/stringutils.hxx
+++ b/include/rtl/stringutils.hxx
@@ -118,6 +118,10 @@ There are 2 cases:
 would be automatically converted to the const variant, which is not wanted 
(not a string literal
 with known size of the content). In this case ConstCharArrayDetector is 
used to ensure the function
 is called only with const char[N] arguments. There's no other plain C 
string type overload.
+(Note that OUStringChar is also covered by ConstCharArrayDetector's 
TypeUtf16 check, but
+provides a pointer to a string that is not NUL-termianted, unlike the 
char16_t const[N] arrays
+normally covered by that check, and which are assumed to represent 
NUL-terminated string
+literals.)
 2) All plain C string types are wanted, and const char[N] needs to be handled 
differently.
 In this case const char[N] would match const char* argument type (not 
exactly sure why, but it's
 consistent in all of gcc, clang and msvc). Using a template with a 
reference to const of the type
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index d35200643e01..fef71f98b329 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -349,10 +349,14 @@ public:
 if (n >= nCapacity) {
 ensureCapacity(n + 16); //TODO: check for overflow
 }
+// For OUStringChar, which is covered by this template's 
ConstCharArrayDetector TypeUtf16
+// check, toPointer does not return a NUL-terminated string, so we 
can't just memcpy n+1
+// elements but rather need to add the terminating NUL manually:
 std::memcpy(
 pData->buffer,
 
libreoffice_internal::ConstCharArrayDetector::toPointer(literal),
-(n + 1) * sizeof (sal_Unicode)); //TODO: check for overflow
+n * sizeof (sal_Unicode));
+pData->buffer[n] = '\0';
 pData->length = n;
 return *this;
 }
diff --git a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx 
b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx
index 

[Libreoffice-commits] core.git: include/rtl sal/qa

2022-03-29 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx  |   19 +--
 include/rtl/ustring.hxx |   19 +--
 sal/qa/rtl/strings/test_ostring_stringliterals.cxx  |   19 +++
 sal/qa/rtl/strings/test_oustring_stringliterals.cxx |   16 
 4 files changed, 53 insertions(+), 20 deletions(-)

New commits:
commit bd94e9dfd0a4c67266e21baa9ec10a56850d093f
Author: Stephan Bergmann 
AuthorDate: Tue Mar 29 16:28:05 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Tue Mar 29 21:15:13 2022 +0200

Add back the opportunity to leave O[U]StringLiteral's buffer uninitialized

...once we have a C++20 baseline, which would render uses of the consteval
O[U]StringLiteral ctors ill-formed if we accidentally failed to write to 
all of
buffer's elements.  This had been broken (and the TODO comments had become
misleading) with 21584b304b21bfe6b99b6f29018c6b754ea28fc0 "make
OUString(OUStringLiteral) constructor constexpr" and
bca539e889d40e06cb3275442622cb075b2484a2 "make OString(OStringLiteral)
constructor constexpr".

Also add corresponding test code.

Change-Id: I2bc680282c717d403a681ff4b9396580c8382de1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132275
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 440f80900855..e99581cd6f94 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -135,18 +135,17 @@ private:
 static_assert(offsetof(OStringLiteral, str.buffer) == 
offsetof(OStringLiteral, more.buffer));
 }
 
+struct Data {
+Data() = default;
+
+oslInterlockedCount refCount = 0x4000; // SAL_STRING_STATIC_FLAG 
(sal/rtl/strimp.hxx)
+sal_Int32 length = N - 1;
+char buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2)
+};
+
 union {
 rtl_String str;
-struct {
-oslInterlockedCount refCount;
-sal_Int32 length;
-char buffer[N];
-} more =
-{
-0x4000, // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
-N - 1,
-{} //TODO: drop initialization for C++20 (P1331R2)
-};
+Data more = {};
 };
 };
 #endif
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 4d983a089f72..1a6a1cae8990 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -117,18 +117,17 @@ private:
 static_assert(offsetof(OUStringLiteral, str.buffer) == 
offsetof(OUStringLiteral, more.buffer));
 }
 
+struct Data {
+Data() = default;
+
+oslInterlockedCount refCount = 0x4000; // SAL_STRING_STATIC_FLAG 
(sal/rtl/strimp.hxx)
+sal_Int32 length = N - 1;
+sal_Unicode buffer[N] = {}; //TODO: drop initialization for C++20 
(P1331R2)
+};
+
 union {
 rtl_uString str;
-struct {
-oslInterlockedCount refCount;
-sal_Int32 length;
-sal_Unicode buffer[N];
-} more =
-{
-0x4000, // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
-N - 1,
-{} //TODO: drop initialization for C++20 (P1331R2)
-};
+Data more = {};
 };
 };
 
diff --git a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx 
b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
index e513d56a5d8f..ec0faec94f18 100644
--- a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
@@ -27,6 +27,7 @@ class StringLiterals: public CppUnit::TestFixture
 {
 private:
 void checkCtors();
+void checkConstexprCtor();
 void checkUsage();
 void checkNonConstUsage();
 void checkBuffer();
@@ -36,8 +37,12 @@ private:
 static const char bad5[];
 static char bad6[];
 
+// Check that OStringLiteral ctor is actually constexpr:
+static constexpr rtlunittest::OStringLiteral dummy{"dummy"};
+
 CPPUNIT_TEST_SUITE(StringLiterals);
 CPPUNIT_TEST(checkCtors);
+CPPUNIT_TEST(checkConstexprCtor);
 CPPUNIT_TEST(checkUsage);
 CPPUNIT_TEST(checkNonConstUsage);
 CPPUNIT_TEST(checkBuffer);
@@ -110,6 +115,20 @@ void test::ostring::StringLiterals::testcall( const char 
str[] )
 #endif
 }
 
+void test::ostring::StringLiterals::checkConstexprCtor()
+{
+#if __cplusplus >= 202002L
+static constinit
+#endif
+rtl::OString s(dummy);
+CPPUNIT_ASSERT_EQUAL(oslInterlockedCount(0x4000), s.pData->refCount);
+// SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
+CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength());
+CPPUNIT_ASSERT_EQUAL(rtl::OString("dummy"), s);
+CPPUNIT_ASSERT_EQUAL(
+static_cast(dummy.getStr()), static_cast(s.getStr()));
+}
+
 void test::ostring::StringLiterals::checkUsage()
 {
 // simply check that all string literal based calls work as expected
diff --git 

[Libreoffice-commits] core.git: include/rtl

2022-02-22 Thread Stephan Bergmann (via logerrit)
 include/rtl/character.hxx |   57 --
 1 file changed, 45 insertions(+), 12 deletions(-)

New commits:
commit 8187737a7844fe4669f80bf0e8ef0950148dc58f
Author: Stephan Bergmann 
AuthorDate: Tue Feb 22 13:32:04 2022 +0100
Commit: Stephan Bergmann 
CommitDate: Tue Feb 22 17:09:48 2022 +0100

Restrict the converting rtl::isAscii* overloads

...to types that can be converted to sal_uInt32 without loss

Change-Id: Iad83591c6b70bf5efe1b6b14bacf1b6e9a225295
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130348
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/character.hxx b/include/rtl/character.hxx
index 9585e16cafa4..5801063532da 100644
--- a/include/rtl/character.hxx
+++ b/include/rtl/character.hxx
@@ -31,6 +31,10 @@
 
 #include "sal/types.h"
 
+#if defined LIBO_INTERNAL_ONLY
+#include 
+#endif
+
 namespace rtl
 {
 /** Check for Unicode code point.
@@ -60,7 +64,12 @@ inline SAL_CONSTEXPR bool isAscii(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAscii(char) = delete;
 bool isAscii(signed char) = delete;
-template  inline constexpr bool isAscii(T code) { return 
isAscii(sal_uInt32(code)); }
+template 
+inline constexpr std::enable_if_t && sizeof(T) <= 
sizeof(sal_uInt32), bool>
+isAscii(T code)
+{
+return isAscii(sal_uInt32(code));
+}
 #endif
 
 /** Check for ASCII lower case character.
@@ -81,7 +90,9 @@ inline SAL_CONSTEXPR bool isAsciiLowerCase(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiLowerCase(char) = delete;
 bool isAsciiLowerCase(signed char) = delete;
-template  inline constexpr bool isAsciiLowerCase(T code)
+template 
+inline constexpr std::enable_if_t && sizeof(T) <= 
sizeof(sal_uInt32), bool>
+isAsciiLowerCase(T code)
 {
 return isAsciiLowerCase(sal_uInt32(code));
 }
@@ -105,7 +116,9 @@ inline SAL_CONSTEXPR bool isAsciiUpperCase(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiUpperCase(char) = delete;
 bool isAsciiUpperCase(signed char) = delete;
-template  inline constexpr bool isAsciiUpperCase(T code)
+template 
+inline constexpr std::enable_if_t && sizeof(T) <= 
sizeof(sal_uInt32), bool>
+isAsciiUpperCase(T code)
 {
 return isAsciiUpperCase(sal_uInt32(code));
 }
@@ -129,7 +142,9 @@ inline SAL_CONSTEXPR bool isAsciiAlpha(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiAlpha(char) = delete;
 bool isAsciiAlpha(signed char) = delete;
-template  inline constexpr bool isAsciiAlpha(T code)
+template 
+inline constexpr std::enable_if_t && sizeof(T) <= 
sizeof(sal_uInt32), bool>
+isAsciiAlpha(T code)
 {
 return isAsciiAlpha(sal_uInt32(code));
 }
@@ -153,7 +168,9 @@ inline SAL_CONSTEXPR bool isAsciiDigit(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiDigit(char) = delete;
 bool isAsciiDigit(signed char) = delete;
-template  inline constexpr bool isAsciiDigit(T code)
+template 
+inline constexpr std::enable_if_t && sizeof(T) <= 
sizeof(sal_uInt32), bool>
+isAsciiDigit(T code)
 {
 return isAsciiDigit(sal_uInt32(code));
 }
@@ -177,7 +194,9 @@ inline SAL_CONSTEXPR bool isAsciiAlphanumeric(sal_uInt32 
code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiAlphanumeric(char) = delete;
 bool isAsciiAlphanumeric(signed char) = delete;
-template  inline constexpr bool isAsciiAlphanumeric(T code)
+template 
+inline constexpr std::enable_if_t && sizeof(T) <= 
sizeof(sal_uInt32), bool>
+isAsciiAlphanumeric(T code)
 {
 return isAsciiAlphanumeric(sal_uInt32(code));
 }
@@ -201,7 +220,9 @@ inline SAL_CONSTEXPR bool isAsciiCanonicHexDigit(sal_uInt32 
code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiCanonicHexDigit(char) = delete;
 bool isAsciiCanonicHexDigit(signed char) = delete;
-template  inline constexpr bool isAsciiCanonicHexDigit(T code)
+template 
+inline constexpr std::enable_if_t && sizeof(T) <= 
sizeof(sal_uInt32), bool>
+isAsciiCanonicHexDigit(T code)
 {
 return isAsciiCanonicHexDigit(sal_uInt32(code));
 }
@@ -225,7 +246,9 @@ inline SAL_CONSTEXPR bool isAsciiHexDigit(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiHexDigit(char) = delete;
 bool isAsciiHexDigit(signed char) = delete;
-template  inline constexpr bool isAsciiHexDigit(T code)
+template 
+inline constexpr std::enable_if_t && sizeof(T) <= 
sizeof(sal_uInt32), bool>
+isAsciiHexDigit(T code)
 {
 return isAsciiHexDigit(sal_uInt32(code));
 }
@@ -248,7 +271,9 @@ inline SAL_CONSTEXPR bool isAsciiOctalDigit(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiOctalDigit(char) = delete;
 bool isAsciiOctalDigit(signed char) = delete;
-template  inline constexpr bool isAsciiOctalDigit(T code)
+template 
+inline constexpr std::enable_if_t && sizeof(T) <= 
sizeof(sal_uInt32), bool>
+isAsciiOctalDigit(T code)
 {
 return isAsciiOctalDigit(sal_uInt32(code));
 }
@@ -273,7 +298,9 @@ inline SAL_CONSTEXPR bool isAsciiWhiteSpace(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiWhiteSpace(char) = delete;
 bool 

[Libreoffice-commits] core.git: include/rtl winaccessibility/source

2022-02-08 Thread Stephan Bergmann (via logerrit)
 include/rtl/instance.hxx|4 ++--
 winaccessibility/source/UAccCOM/acccommon.h |3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

New commits:
commit 7a6786c570a1550d2353debd508fd31fbac8262b
Author: Stephan Bergmann 
AuthorDate: Tue Feb 8 07:53:37 2022 +0100
Commit: Stephan Bergmann 
CommitDate: Tue Feb 8 15:21:26 2022 +0100

loplugin:nullptr

Change-Id: I134ca6b0e69124739b734dfb49763da4284f7412
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129652
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/instance.hxx b/include/rtl/instance.hxx
index f14c87e2e2bd..0d7d8f3fca7a 100644
--- a/include/rtl/instance.hxx
+++ b/include/rtl/instance.hxx
@@ -275,7 +275,7 @@ public:
 static Inst * create(InstCtor aInstCtor, GuardCtor aGuardCtor)
 {
 #if defined _MSC_VER
-static Inst * m_pInstance = 0;
+static Inst * m_pInstance = NULL;
 #endif // _MSC_VER
 Inst * p = m_pInstance;
 if (!p)
@@ -300,7 +300,7 @@ public:
 DataCtor aDataCtor)
 {
 #if defined _MSC_VER
-static Inst * m_pInstance = 0;
+static Inst * m_pInstance = NULL;
 #endif // _MSC_VER
 Inst * p = m_pInstance;
 if (!p)
diff --git a/winaccessibility/source/UAccCOM/acccommon.h 
b/winaccessibility/source/UAccCOM/acccommon.h
index a14c26a84023..d2dffc5e60b8 100644
--- a/winaccessibility/source/UAccCOM/acccommon.h
+++ b/winaccessibility/source/UAccCOM/acccommon.h
@@ -61,7 +61,8 @@ enum DM_NIR {
 template HRESULT
 createInstance(REFIID iid, Ifc ** ppIfc)
 {
-return CComCreator< CComObject >::CreateInstance(0, iid, 
reinterpret_cast(ppIfc));
+return
+CComCreator< CComObject >::CreateInstance(nullptr, iid, 
reinterpret_cast(ppIfc));
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


[Libreoffice-commits] core.git: include/rtl

2021-11-22 Thread Noel Grandin (via logerrit)
 include/rtl/ustrbuf.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit c19b6a80da0ba15a53a599732c45faf0bd5a7f3f
Author: Noel Grandin 
AuthorDate: Mon Nov 22 14:13:30 2021 +0200
Commit: Noel Grandin 
CommitDate: Mon Nov 22 14:49:29 2021 +0100

loplugin:noexceptmove

Change-Id: I2ba1ebb161f4004b819fd106c090fefd8d8af8ea
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125658
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 115d529a0c53..85fe744e9ee1 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -270,7 +270,7 @@ public:
 /** Move assignment
  * @since LibreOffice 7.3
  */
-OUStringBuffer& operator = ( OUStringBuffer&& value )
+OUStringBuffer& operator = ( OUStringBuffer&& value ) noexcept
 {
 rtl_uString_release( pData );
 pData = value.pData;


[Libreoffice-commits] core.git: include/rtl tools/source

2021-11-22 Thread Noel Grandin (via logerrit)
 include/rtl/ustrbuf.hxx  |   16 
 tools/source/fsys/urlobj.cxx |2 +-
 2 files changed, 17 insertions(+), 1 deletion(-)

New commits:
commit a70bd820da49401e7c233ae254ce954954344d33
Author: Noel Grandin 
AuthorDate: Sun Nov 21 16:50:59 2021 +0200
Commit: Noel Grandin 
CommitDate: Mon Nov 22 12:19:59 2021 +0100

tdf#133835 speedup calc autofilter (8)

Add move operator to OUStringBuffer to avoid copy

Change-Id: Ifef326449d87aac79f4b1142db7a53faad427580
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125626
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 20afe57de7ff..115d529a0c53 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -266,6 +266,22 @@ public:
 return *this;
 }
 
+#if defined LIBO_INTERNAL_ONLY
+/** Move assignment
+ * @since LibreOffice 7.3
+ */
+OUStringBuffer& operator = ( OUStringBuffer&& value )
+{
+rtl_uString_release( pData );
+pData = value.pData;
+nCapacity = value.nCapacity;
+value.pData = nullptr;
+value.nCapacity = 0;
+rtl_uString_new(  );
+return *this;
+}
+#endif
+
 /** Assign from a string.
 
 @since LibreOffice 5.3
diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx
index d265111d2e2e..8babbf90b79f 100644
--- a/tools/source/fsys/urlobj.cxx
+++ b/tools/source/fsys/urlobj.cxx
@@ -1472,7 +1472,7 @@ bool INetURLObject::setAbsURIRef(OUString const & 
rTheAbsURIRef,
 return false;
 }
 
-m_aAbsURIRef = aSynAbsURIRef;
+m_aAbsURIRef = std::move(aSynAbsURIRef);
 
 return true;
 }


[Libreoffice-commits] core.git: include/rtl include/tools tools/source

2021-11-21 Thread Noel Grandin (via logerrit)
 include/rtl/ustring.hxx  |5 +
 include/tools/urlobj.hxx |2 
 tools/source/fsys/urlobj.cxx |  117 ++-
 3 files changed, 79 insertions(+), 45 deletions(-)

New commits:
commit dc2010964fb8d18d5c4fe96172ee082276a1e587
Author: Noel Grandin 
AuthorDate: Sat Nov 20 08:16:33 2021 +0200
Commit: Noel Grandin 
CommitDate: Sun Nov 21 15:47:25 2021 +0100

tdf#133835 speedup calc autofilter (5)

Tweak INetURLObject to reduce the number of
OUString and OUStringBuffer we create,
saves 5%

And add a asView() method to OUStringConstExpr,
to make it easier to pass to OUStringBuffer::insert

Change-Id: I115ec2398cfc8df39bd1efbbd5f0d5cc9712dba7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125600
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index e5b58be8c52d..e14549482f35 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -161,6 +161,11 @@ public:
 // no destructor necessary because we know we are pointing at a 
compile-time
 // constant OUStringLiteral, which bypasses ref-counting.
 
+/**
+  make it easier to pass to OUStringBuffer and similar without 
casting/converting
+*/
+constexpr std::u16string_view asView() const { return {pData->buffer, 
static_cast(pData->length)}; }
+
 inline operator const OUString&() const;
 
 private:
diff --git a/include/tools/urlobj.hxx b/include/tools/urlobj.hxx
index ede630b7ea7b..8049e165d7a0 100644
--- a/include/tools/urlobj.hxx
+++ b/include/tools/urlobj.hxx
@@ -404,7 +404,7 @@ public:
 
 @return  The protocol name of URLs of the given scheme.
  */
-static OUString GetSchemeName(INetProtocol eTheScheme);
+static const OUString & GetSchemeName(INetProtocol eTheScheme);
 
 static INetProtocol CompareProtocolScheme(OUString const &
   rTheAbsURIRef);
diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx
index 8b2882b06b32..9a5a82ceb632 100644
--- a/tools/source/fsys/urlobj.cxx
+++ b/tools/source/fsys/urlobj.cxx
@@ -290,7 +290,7 @@ int INetURLObject::SubString::compare(SubString const & 
rOther,
 
 struct INetURLObject::SchemeInfo
 {
-char const * m_pScheme;
+rtl::OUStringConstExpr m_sScheme;
 char const * m_pPrefix;
 bool m_bAuthority;
 bool m_bUser;
@@ -316,91 +316,120 @@ struct INetURLObject::PrefixInfo
 inline INetURLObject::SchemeInfo const &
 INetURLObject::getSchemeInfo(INetProtocol eTheScheme)
 {
+static constexpr OUStringLiteral EMPTY = u"";
+static constexpr OUStringLiteral FTP = u"ftp";
+static constexpr OUStringLiteral HTTP = u"http";
+static constexpr OUStringLiteral FILE1 = u"file"; // because FILE is 
already defined
+static constexpr OUStringLiteral MAILTO = u"mailto";
+static constexpr OUStringLiteral VND_WEBDAV = u"vnd.sun.star.webdav";
+static constexpr OUStringLiteral PRIVATE = u"private";
+static constexpr OUStringLiteral VND_HELP = u"vnd.sun.star.help";
+static constexpr OUStringLiteral HTTPS = u"https";
+static constexpr OUStringLiteral SLOT = u"slot";
+static constexpr OUStringLiteral MACRO = u"macro";
+static constexpr OUStringLiteral JAVASCRIPT = u"javascript";
+static constexpr OUStringLiteral DATA = u"data";
+static constexpr OUStringLiteral CID = u"cid";
+static constexpr OUStringLiteral VND_HIER = u"vnd.sun.star.hier";
+static constexpr OUStringLiteral UNO = u".uno";
+static constexpr OUStringLiteral COMPONENT = u".component";
+static constexpr OUStringLiteral VND_PKG = u"vnd.sun.star.pkg";
+static constexpr OUStringLiteral LDAP = u"ldap";
+static constexpr OUStringLiteral DB = u"db";
+static constexpr OUStringLiteral VND_CMD = u"vnd.sun.star.cmd";
+static constexpr OUStringLiteral TELNET = u"telnet";
+static constexpr OUStringLiteral VND_EXPAND = u"vnd.sun.star.expand";
+static constexpr OUStringLiteral VND_TDOC = u"vnd.sun.star.tdoc";
+static constexpr OUStringLiteral SMB = u"smb";
+static constexpr OUStringLiteral HID = u"hid";
+static constexpr OUStringLiteral SFTP = u"sftp";
+static constexpr OUStringLiteral VND_CMIS = u"vnd.libreoffice.cmis";
+
 static o3tl::enumarray const map = {
 SchemeInfo{
-"", "", false, false, false, false, false, false, false, false},
+EMPTY, "", false, false, false, false, false, false, false, false},
 SchemeInfo{
-"ftp", "ftp://;, true, true, false, true, true, true, true,
+FTP, "ftp://;, true, true, false, true, true, true, true,
 false},
 SchemeInfo{
-"http", "http://;, true, false, false, false, true, true, true,
+HTTP, "http://;, true, false, false, false, true, true, true,
 true},
 SchemeInfo{
-"file", "file://", true, false, false, 

[Libreoffice-commits] core.git: include/rtl

2021-11-17 Thread Mike Kaganski (via logerrit)
 include/rtl/math.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit a664d4d44ce66db8d60d8c0ebf8bb793ecf2c462
Author: Mike Kaganski 
AuthorDate: Wed Nov 17 10:35:57 2021 +0200
Commit: Mike Kaganski 
CommitDate: Wed Nov 17 11:35:07 2021 +0100

Fix the calculated constant

rtl::math::isValidArcArg's comment talks about 2^64 = 1.844e19; but
the calculation resulted in 2^63.

Unfortunately we can't use C++17 hex-exponent notation in published
API header.

Change-Id: I1dd6e754431ad028982623ff5de4c6329fd6c2ad
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125348
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/rtl/math.hxx b/include/rtl/math.hxx
index d67d4aa75a4a..7da30df6832b 100644
--- a/include/rtl/math.hxx
+++ b/include/rtl/math.hxx
@@ -431,7 +431,7 @@ inline bool isValidArcArg(double d)
 return fabs(d)
 <= (static_cast< double >(static_cast< unsigned long >(0x8000))
 * static_cast< double >(static_cast< unsigned long >(0x8000))
-* 2);
+* 4);
 }
 
 /** Safe sin(), returns NAN if not valid.


[Libreoffice-commits] core.git: include/rtl

2021-11-15 Thread Noel Grandin (via logerrit)
 include/rtl/ustring.hxx |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

New commits:
commit fe65c692cfbf128d55c75207f6d1452713fd72f6
Author: Noel Grandin 
AuthorDate: Mon Nov 15 15:56:05 2021 +0200
Commit: Noel Grandin 
CommitDate: Mon Nov 15 20:58:51 2021 +0100

OUStringConstExpr should convert to 'const OUString&'

to avoid creating unnecessary temporaries

Change-Id: I222789a4ffba67eaf7e297ecb2a91c3da95f5499
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125249
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 6cf92e1d3599..e5b58be8c52d 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -161,7 +161,7 @@ public:
 // no destructor necessary because we know we are pointing at a 
compile-time
 // constant OUStringLiteral, which bypasses ref-counting.
 
-inline operator OUString() const;
+inline operator const OUString&() const;
 
 private:
 rtl_uString* pData;
@@ -3299,7 +3299,7 @@ private:
 
 #if defined LIBO_INTERNAL_ONLY
 // Can only define this after we define OUString
-inline OUStringConstExpr::operator OUString() const { return 
OUString::unacquired(); }
+inline OUStringConstExpr::operator const OUString &() const { return 
OUString::unacquired(); }
 #endif
 
 #if defined LIBO_INTERNAL_ONLY


[Libreoffice-commits] core.git: include/rtl sal/qa

2021-11-11 Thread Stephan Bergmann (via logerrit)
 include/rtl/ustring.hxx |  107 
 sal/qa/rtl/strings/test_oustring_stringliterals.cxx |   10 +
 2 files changed, 6 insertions(+), 111 deletions(-)

New commits:
commit 1ef0261539ca6ee8ad9f43d91536c9caa4f7ea53
Author: Stephan Bergmann 
AuthorDate: Thu Nov 11 08:04:02 2021 +0100
Commit: Stephan Bergmann 
CommitDate: Thu Nov 11 10:01:39 2021 +0100

Drop the OUString vs. OUStringLiteral comparison operator overloads

...which can be subsumed by their OUString vs. OUString counterparts now 
that
conversion from OUStringLiteral to OUString is cheap since
e6dfaf9f44f9939abc338c83b3024108431d0f69 "Turn OUStringLiteral into a
consteval'ed, static-refcound rtl_uString".  (The only place that needed
adaption was the dubious use of temporary OUStringLiteral instances in
sal/qa/rtl/strings/test_oustring_stringliterals.cxx, which now caused 
"error:
conversion function from 'rtlunittest::OUStringLiteral<6>' to
'const rtlunittest::OUString' invokes a deleted function".)

Change-Id: I4f0f96efa2d5331ed5cbc9a29bdfdf3c0f4148a7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125020
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 9a893d3764af..1a5ff2d97d6c 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -1845,113 +1845,6 @@ public:
 }
 #endif
 
-#if defined LIBO_INTERNAL_ONLY
-/// @cond INTERNAL
-
-/* Comparison between OUString and OUStringLiteral.
-
-   @since LibreOffice 5.0
-*/
-
-template
-friend bool operator ==(OUString const & lhs, OUStringLiteral const & 
rhs) {
-return
-rtl_ustr_reverseCompare_WithLength(
-lhs.pData->buffer, lhs.pData->length, rhs.getStr(), 
rhs.getLength())
-== 0;
-}
-
-template
-friend bool operator !=(OUString const & lhs, OUStringLiteral const & 
rhs) {
-return
-rtl_ustr_reverseCompare_WithLength(
-lhs.pData->buffer, lhs.pData->length, rhs.getStr(), 
rhs.getLength())
-!= 0;
-}
-
-template
-friend bool operator <(OUString const & lhs, OUStringLiteral const & 
rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.pData->buffer, lhs.pData->length, rhs.getStr(), 
rhs.getLength()))
-< 0;
-}
-
-template
-friend bool operator <=(OUString const & lhs, OUStringLiteral const & 
rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.pData->buffer, lhs.pData->length, rhs.getStr(), 
rhs.getLength()))
-<= 0;
-}
-
-template
-friend bool operator >(OUString const & lhs, OUStringLiteral const & 
rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.pData->buffer, lhs.pData->length, rhs.getStr(), 
rhs.getLength()))
-> 0;
-}
-
-template
-friend bool operator >=(OUString const & lhs, OUStringLiteral const & 
rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.pData->buffer, lhs.pData->length, rhs.getStr(), 
rhs.getLength()))
->= 0;
-}
-
-template
-friend bool operator ==(OUStringLiteral const & lhs, OUString const & 
rhs) {
-return
-rtl_ustr_reverseCompare_WithLength(
-lhs.getStr(), lhs.getLength(), rhs.pData->buffer, 
rhs.pData->length)
-== 0;
-}
-
-template
-friend bool operator !=(OUStringLiteral const & lhs, OUString const & 
rhs) {
-return
-rtl_ustr_reverseCompare_WithLength(
-lhs.getStr(), lhs.getLength(), rhs.pData->buffer, 
rhs.pData->length)
-!= 0;
-}
-
-template
-friend bool operator <(OUStringLiteral const & lhs, OUString const & 
rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.getStr(), lhs.getLength(), rhs.pData->buffer, 
rhs.pData->length))
-< 0;
-}
-
-template
-friend bool operator <=(OUStringLiteral const & lhs, OUString const & 
rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.getStr(), lhs.getLength(), rhs.pData->buffer, 
rhs.pData->length))
-<= 0;
-}
-
-template
-friend bool operator >(OUStringLiteral const & lhs, OUString const & 
rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.getStr(), lhs.getLength(), rhs.pData->buffer, 
rhs.pData->length))
-> 0;
-}
-
-template
-friend bool operator >=(OUStringLiteral const & lhs, OUString const & 
rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.getStr(), lhs.getLength(), rhs.pData->buffer, 
rhs.pData->length))
->= 0;
-}
-
-/// @endcond
-#endif
-
 /**
   Returns a hashcode for this string.
 
diff --git 

[Libreoffice-commits] core.git: include/rtl sfx2/source

2021-10-26 Thread Stephan Bergmann (via logerrit)
 include/rtl/ustrbuf.hxx  |   48 ---
 sfx2/source/appl/newhelp.cxx |2 -
 2 files changed, 1 insertion(+), 49 deletions(-)

New commits:
commit 3fd9f90cfa620d7148d969a41df86da9e26e43f7
Author: Stephan Bergmann 
AuthorDate: Tue Oct 26 10:53:53 2021 +0200
Commit: Stephan Bergmann 
CommitDate: Tue Oct 26 22:38:04 2021 +0200

Remove OUStringBuffer member function overloads for OUStringLiteral

...which are already adequately covered by overloads for OUString and the
OUStringLiteral-to-OUString implicit conversion that became cheap in
e6dfaf9f44f9939abc338c83b3024108431d0f69 "Turn OUStringLiteral into a
consteval'ed, static-refcound rtl_uString".

The only place where the removal of the ctor overload caused an issue for 
copy-
initialization (in sfx2/source/appl/newhelp.cxx) could easily be rewritten 
using
direct-initialization.

Change-Id: I458fb80eebabf981633f3437e7e967caa4c50a5b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124176
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 2b8288b26b1e..20afe57de7ff 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -188,13 +188,6 @@ public:
 
libreoffice_internal::ConstCharArrayDetector::toPointer(literal),
 libreoffice_internal::ConstCharArrayDetector::length);
 }
-
-/** @overload @since LibreOffice 5.4 */
-template OUStringBuffer(OUStringLiteral const & literal):
-pData(nullptr), nCapacity(literal.getLength() + 16) //TODO: check for 
overflow
-{
-rtl_uStringbuffer_newFromStr_WithLength(, literal.getStr(), 
literal.getLength());
-}
 #endif
 
 #if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
@@ -347,19 +340,6 @@ public:
 pData->length = n;
 return *this;
 }
-
-/** @overload @since LibreOffice 5.4 */
-template OUStringBuffer & operator =(OUStringLiteral 
const & literal) {
-sal_Int32 const n = literal.getLength();
-if (n >= nCapacity) {
-ensureCapacity(n + 16); //TODO: check for overflow
-}
-std::memcpy(
-pData->buffer, literal.getStr(),
-(n + 1) * sizeof (sal_Unicode)); //TODO: check for overflow
-pData->length = n;
-return *this;
-}
 #endif
 
 #if defined LIBO_INTERNAL_ONLY
@@ -693,11 +673,6 @@ public:
 
libreoffice_internal::ConstCharArrayDetector::toPointer(literal),
 libreoffice_internal::ConstCharArrayDetector::length);
 }
-
-/** @overload @since LibreOffice 5.4 */
-template OUStringBuffer & append(OUStringLiteral const & 
literal) {
-return append(literal.getStr(), literal.getLength());
-}
 #endif
 
 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
@@ -1078,12 +1053,6 @@ public:
 
libreoffice_internal::ConstCharArrayDetector::toPointer(literal),
 libreoffice_internal::ConstCharArrayDetector::length);
 }
-
-/** @overload @since LibreOffice 5.4 */
-template
-OUStringBuffer & insert(sal_Int32 offset, OUStringLiteral const & 
literal) {
-return insert(offset, literal.getStr(), literal.getLength());
-}
 #endif
 
 /**
@@ -1498,17 +1467,6 @@ public:
 libreoffice_internal::ConstCharArrayDetector::length);
 return n < 0 ? n : n + fromIndex;
 }
-
-/** @overload @since LibreOffice 5.4 */
-template
-sal_Int32 indexOf(OUStringLiteral const & literal, sal_Int32 fromIndex 
= 0)
-const
-{
-sal_Int32 n = rtl_ustr_indexOfStr_WithLength(
-pData->buffer + fromIndex, pData->length - fromIndex, 
literal.getStr(),
-literal.getLength());
-return n < 0 ? n : n + fromIndex;
-}
 #endif
 
 /**
@@ -1604,12 +1562,6 @@ public:
 
libreoffice_internal::ConstCharArrayDetector::toPointer(literal),
 libreoffice_internal::ConstCharArrayDetector::length);
 }
-
-/** @overload @since LibreOffice 5.4 */
-template sal_Int32 lastIndexOf(OUStringLiteral const & 
literal) const {
-return rtl_ustr_lastIndexOfStr_WithLength(
-pData->buffer, pData->length, literal.getStr(), 
literal.getLength());
-}
 #endif
 
 /**
diff --git a/sfx2/source/appl/newhelp.cxx b/sfx2/source/appl/newhelp.cxx
index 92007f02afcf..5d0e582b03a6 100644
--- a/sfx2/source/appl/newhelp.cxx
+++ b/sfx2/source/appl/newhelp.cxx
@@ -558,7 +558,7 @@ void IndexTabPage_Impl::InitializeIndex()
 
 try
 {
-OUStringBuffer aURL = HELP_URL;
+OUStringBuffer aURL(HELP_URL);
 aURL.append(sFactory);
 AppendConfigToken(aURL, true);
 


[Libreoffice-commits] core.git: include/rtl

2021-10-10 Thread Mike Kaganski (via logerrit)
 include/rtl/ustring.hxx |   10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

New commits:
commit 782836ec8b736e5110b44016be8f73b068444911
Author: Mike Kaganski 
AuthorDate: Sun Oct 10 22:39:36 2021 +0200
Commit: Mike Kaganski 
CommitDate: Mon Oct 11 00:17:26 2021 +0200

Simplify one matchIgnoreAsciiCase overload

Change-Id: I982a5fd893b94085d30aeb595640d46cac4acdf3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123169
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 5fbf00d64a6d..e092ff6370d7 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -1089,13 +1089,9 @@ public:
 {
 assert(
 libreoffice_internal::ConstCharArrayDetector::isValid(literal));
-return
-rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength(
-pData->buffer+fromIndex, pData->length-fromIndex,
-libreoffice_internal::ConstCharArrayDetector::toPointer(
-literal),
-libreoffice_internal::ConstCharArrayDetector::length)
-== 0;
+return matchIgnoreAsciiCaseAsciiL(
+
libreoffice_internal::ConstCharArrayDetector::toPointer(literal),
+libreoffice_internal::ConstCharArrayDetector::length, 
fromIndex);
 }
 
 /**


[Libreoffice-commits] core.git: include/rtl

2021-07-21 Thread Noel Grandin (via logerrit)
 include/rtl/string.h  |5 ++---
 include/rtl/ustring.h |5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)

New commits:
commit a4fafab70dccd4df47166428b6e05d52d9bbdf3f
Author: Noel Grandin 
AuthorDate: Wed Jul 21 15:52:59 2021 +0200
Commit: Noel Grandin 
CommitDate: Wed Jul 21 18:50:43 2021 +0200

improve the comments of the number conversion functions

For the
rtl_str_to_WithLength
category of functions, the string does not need to be null-terminated

Change-Id: I1971c8c10b760743633523e6f680366eafdfc685
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119325
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/string.h b/include/rtl/string.h
index d29caf93a718..e0d751f18bd3 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -789,11 +789,10 @@ SAL_DLLPUBLIC sal_Int64 SAL_CALL rtl_str_toInt64(
 
 /** Interpret a string as a long integer.
 
-This function cannot be used for language-specific conversion.  The string
-must be null-terminated.
+This function cannot be used for language-specific conversion.
 
 @param str
-a null-terminated string.
+a string.
 
 @param radix
 the radix.  Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h
index 3caca28d2f8a..b4990fec12eb 100644
--- a/include/rtl/ustring.h
+++ b/include/rtl/ustring.h
@@ -1119,11 +1119,10 @@ SAL_DLLPUBLIC sal_Int64 SAL_CALL rtl_ustr_toInt64(
 
 /** Interpret a string as a long integer.
 
-This function cannot be used for language-specific conversion.  The string
-must be null-terminated.
+This function cannot be used for language-specific conversion.
 
 @param str
-a null-terminated string.
+a string.
 
 @param radix
 the radix.  Must be between RTL_USTR_MIN_RADIX (2) and RTL_USTR_MAX_RADIX
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl sal/rtl sal/util sax/source

2021-07-21 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.h |   20 
 sal/rtl/string.cxx   |8 
 sal/util/sal.map |5 -
 sax/source/tools/fastattribs.cxx |4 +++-
 4 files changed, 3 insertions(+), 34 deletions(-)

New commits:
commit 99a1290b3f2c8584db0a33fe48adf93dccce3a92
Author: Stephan Bergmann 
AuthorDate: Wed Jul 21 09:42:47 2021 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Jul 21 15:38:03 2021 +0200

Use existing rtl_math_stringToDouble

...like it is also already done in LineParser::readDouble in
sdext/source/pdfimport/wrapper/wrapper.cxx (esp. since the code should be
changed to use C++17 std::from_chars once that is available in all our
baselines), reverting again the introduction of rtl_str_toDouble_WithLength 
in
b1df9c67349cf4cc5be4128d797aefb87f50e38f "[API CHANGE] reduce cost of 
numeric
conversion"

Change-Id: If7e3a15649f80093d3407157412fd3deb3a38b12
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119318
Reviewed-by: Noel Grandin 
Reviewed-by: Stephan Bergmann 
Tested-by: Jenkins

diff --git a/include/rtl/string.h b/include/rtl/string.h
index 155c1d46126c..d29caf93a718 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -863,26 +863,6 @@ SAL_DLLPUBLIC float SAL_CALL rtl_str_toFloat(
 SAL_DLLPUBLIC double SAL_CALL rtl_str_toDouble(
 const char * str ) SAL_THROW_EXTERN_C();
 
-/** Interpret a string as a double.
-
-This function cannot be used for language-specific conversion.  The string
-must be null-terminated.
-
-@param str
-a null-terminated string.
-
-@param nStrLength
-number of chars to process
-
-@return
-the double value represented by the string, or 0.0 if the string does not
-represent a double.
-
-@since LibreOffice 7.3
- */
-SAL_DLLPUBLIC double SAL_CALL rtl_str_toDouble_WithLength(
-const char * str, sal_Int32 nStrLength ) SAL_THROW_EXTERN_C();
-
 /* === */
 
 #ifdef _WIN32
diff --git a/sal/rtl/string.cxx b/sal/rtl/string.cxx
index 660f22552b0c..94be8029032a 100644
--- a/sal/rtl/string.cxx
+++ b/sal/rtl/string.cxx
@@ -110,14 +110,6 @@ double SAL_CALL rtl_str_toDouble(char const * pStr) 
SAL_THROW_EXTERN_C()
nullptr, nullptr);
 }
 
-double SAL_CALL rtl_str_toDouble_WithLength(const char* pStr,
-  sal_Int32 nStrLength) 
SAL_THROW_EXTERN_C()
-{
-assert(pStr);
-return rtl_math_stringToDouble(pStr, pStr + nStrLength, '.', 0,
-   nullptr, nullptr);
-}
-
 /* === */
 
 static int rtl_ImplGetFastUTF8ByteLen( const sal_Unicode* pStr, sal_Int32 nLen 
)
diff --git a/sal/util/sal.map b/sal/util/sal.map
index e33dde55b8da..49efb2a436cd 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -755,11 +755,6 @@ PRIVATE_1.7 { # LibreOffice 7.1
 rtl_uString_newReplaceAllFromIndexUtf16LUtf16L;
 } PRIVATE_1.5;
 
-PRIVATE_1.8 { # LibreOffice 7.3
-global:
-rtl_str_toDouble_WithLength;
-} PRIVATE_1.7;
-
 PRIVATE_textenc.1 { # LibreOffice 3.6
 global:
 _ZN3sal6detail7textenc20convertCharToUnicode*;
diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx
index 2512f6296aee..9bf4a3f4ae6e 100644
--- a/sax/source/tools/fastattribs.cxx
+++ b/sax/source/tools/fastattribs.cxx
@@ -20,6 +20,7 @@
 #include 
 
 #include 
+#include 
 #include 
 
 using namespace ::com::sun::star::uno;
@@ -221,7 +222,8 @@ bool FastAttributeList::getAsDouble( sal_Int32 nToken, 
double ) const
 for (size_t i = 0; i < maAttributeTokens.size(); ++i)
 if (maAttributeTokens[i] == nToken)
 {
-rDouble = rtl_str_toDouble_WithLength( getFastAttributeValue(i),  
AttributeValueLength(i) );
+auto const p = getFastAttributeValue(i);
+rDouble = rtl_math_stringToDouble( p,  p + 
AttributeValueLength(i), '.', 0, nullptr, nullptr );
 return true;
 }
 return false;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl sal/rtl sal/util sax/source

2021-07-21 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.h |   25 -
 sal/rtl/string.cxx   |6 --
 sal/util/sal.map |1 -
 sax/source/tools/fastattribs.cxx |   12 ++--
 4 files changed, 10 insertions(+), 34 deletions(-)

New commits:
commit 9230c189ebc5bcfd6303bfa7eebcd35488037d00
Author: Stephan Bergmann 
AuthorDate: Wed Jul 21 09:11:40 2021 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Jul 21 13:20:18 2021 +0200

Use existing rtl_str_toInt64_WithLength

...like it is also already done in LineParser::readInt32 in
sdext/source/pdfimport/wrapper/wrapper.cxx (esp. since the code should be
changed to use C++17 std::from_chars once that is available in all our
baselines), reverting again the introduction of rtl_str_toInt32_WithLength 
in
b1df9c67349cf4cc5be4128d797aefb87f50e38f "[API CHANGE] reduce cost of 
numeric
conversion"

Change-Id: I2789f8ec55c8d89150d1c68e6b353a1d2e1d1703
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119301
Reviewed-by: Noel Grandin 
Reviewed-by: Stephan Bergmann 
Tested-by: Jenkins

diff --git a/include/rtl/string.h b/include/rtl/string.h
index 62fc7ecfb2d0..155c1d46126c 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -747,31 +747,6 @@ SAL_DLLPUBLIC sal_Bool SAL_CALL rtl_str_toBoolean(
 SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32(
 const char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C();
 
-/** Interpret a string as a integer.
-
-This function cannot be used for language-specific conversion.  The string
-must be null-terminated.
-
-@param str
-a null-terminated string.
-
-@param radix
-the radix.  Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
-(36), inclusive.
-
-@param nStrLength
-number of chars to process
-
-@return
-the integer value represented by the string, or 0 if the string does
-not represent a integer.
-
-@internal
-@since LibreOffice 7.3
-*/
-SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32_WithLength(
-const char * str, sal_Int16 radix, sal_Int32 nStrLength ) 
SAL_THROW_EXTERN_C();
-
 /** Interpret a string as an unsigned integer.
 
 This function cannot be used for language-specific conversion.  The string
diff --git a/sal/rtl/string.cxx b/sal/rtl/string.cxx
index 6fc2df75698d..660f22552b0c 100644
--- a/sal/rtl/string.cxx
+++ b/sal/rtl/string.cxx
@@ -567,12 +567,6 @@ sal_Int32 SAL_CALL rtl_str_toInt32(const char* pStr, 
sal_Int16 nRadix) SAL_THROW
 return rtl::str::toInt32(pStr, nRadix);
 }
 
-sal_Int32 SAL_CALL rtl_str_toInt32_WithLength(const char* pStr, sal_Int16 
nRadix,
-  sal_Int32 nStrLength) 
SAL_THROW_EXTERN_C()
-{
-return rtl::str::toInt32_WithLength(pStr, nRadix, nStrLength);
-}
-
 sal_Int64 SAL_CALL rtl_str_toInt64(const char* pStr, sal_Int16 nRadix) 
SAL_THROW_EXTERN_C()
 {
 return rtl::str::toInt64(pStr, nRadix);
diff --git a/sal/util/sal.map b/sal/util/sal.map
index e2339bdc13ac..e33dde55b8da 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -757,7 +757,6 @@ PRIVATE_1.7 { # LibreOffice 7.1
 
 PRIVATE_1.8 { # LibreOffice 7.3
 global:
-rtl_str_toInt32_WithLength;
 rtl_str_toDouble_WithLength;
 } PRIVATE_1.7;
 
diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx
index 9cec32318108..2512f6296aee 100644
--- a/sax/source/tools/fastattribs.cxx
+++ b/sax/source/tools/fastattribs.cxx
@@ -196,7 +196,11 @@ bool FastAttributeList::getAsInteger( sal_Int32 nToken, 
sal_Int32 ) const
 for (size_t i = 0; i < maAttributeTokens.size(); ++i)
 if (maAttributeTokens[i] == nToken)
 {
-rInt = rtl_str_toInt32_WithLength( getFastAttributeValue(i), 10, 
AttributeValueLength(i) );
+sal_Int64 n = rtl_str_toInt64_WithLength( 
getFastAttributeValue(i), 10, AttributeValueLength(i) );
+if (n < SAL_MIN_INT32 || n > SAL_MAX_INT32) {
+n = 0;
+}
+rInt = n;
 return true;
 }
 return false;
@@ -204,7 +208,11 @@ bool FastAttributeList::getAsInteger( sal_Int32 nToken, 
sal_Int32 ) const
 
 sal_Int32 FastAttributeList::getAsIntegerByIndex( sal_Int32 nTokenIndex ) const
 {
-return rtl_str_toInt32_WithLength( getFastAttributeValue(nTokenIndex), 10, 
AttributeValueLength(nTokenIndex) );
+sal_Int64 n = rtl_str_toInt64_WithLength( 
getFastAttributeValue(nTokenIndex), 10, AttributeValueLength(nTokenIndex) );
+if (n < SAL_MIN_INT32 || n > SAL_MAX_INT32) {
+n = 0;
+}
+return n;
 }
 
 bool FastAttributeList::getAsDouble( sal_Int32 nToken, double ) const
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2021-07-19 Thread Mike Kaganski (via logerrit)
 include/rtl/string.hxx  |1 +
 include/rtl/ustring.hxx |1 +
 2 files changed, 2 insertions(+)

New commits:
commit e1af6fefa0f0b919ccdacc9edfbae034e6347d46
Author: Mike Kaganski 
AuthorDate: Mon Jul 19 21:11:51 2021 +0200
Commit: Mike Kaganski 
CommitDate: Mon Jul 19 22:47:36 2021 +0200

offsetof is only guaranteed to work with standard layout types

Change-Id: If9ba41a219d3c3b5bff838104b9a0df53030b8f5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119181
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index f80dd7410da7..1f3120e7b4e5 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -129,6 +129,7 @@ private:
 static constexpr void assertLayout() {
 // These static_asserts verifying the layout compatibility with 
rtl_String cannot be class
 // member declarations, as offsetof requires a complete type, so defer 
them to here:
+static_assert(std::is_standard_layout_v);
 static_assert(offsetof(OStringLiteral, str.refCount) == 
offsetof(OStringLiteral, more.refCount));
 static_assert(offsetof(OStringLiteral, str.length) == 
offsetof(OStringLiteral, more.length));
 static_assert(offsetof(OStringLiteral, str.buffer) == 
offsetof(OStringLiteral, more.buffer));
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 2699c09ac03f..96bb504f77a8 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -110,6 +110,7 @@ private:
 static constexpr void assertLayout() {
 // These static_asserts verifying the layout compatibility with 
rtl_uString cannot be class
 // member declarations, as offsetof requires a complete type, so defer 
them to here:
+static_assert(std::is_standard_layout_v);
 static_assert(offsetof(OUStringLiteral, str.refCount) == 
offsetof(OUStringLiteral, more.refCount));
 static_assert(offsetof(OUStringLiteral, str.length) == 
offsetof(OUStringLiteral, more.length));
 static_assert(offsetof(OUStringLiteral, str.buffer) == 
offsetof(OUStringLiteral, more.buffer));
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl sal/rtl sal/util sax/source

2021-07-17 Thread Noel Grandin (via logerrit)
 include/rtl/string.h |   45 +++
 sal/rtl/string.cxx   |   14 
 sal/rtl/strtmpl.hxx  |   10 
 sal/util/sal.map |6 +
 sax/source/tools/fastattribs.cxx |6 ++---
 5 files changed, 78 insertions(+), 3 deletions(-)

New commits:
commit b1df9c67349cf4cc5be4128d797aefb87f50e38f
Author: Noel Grandin 
AuthorDate: Fri Jul 16 14:48:25 2021 +0200
Commit: Noel Grandin 
CommitDate: Sat Jul 17 09:12:26 2021 +0200

[API CHANGE] reduce cost of numeric conversion

on a hot path, since we already know the length of these strings.

Which requires adding some new variants of our string conversion
functions

Change-Id: I1877f8f3c72934c07f14eec7e73bbe8d7b0f1808
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119065
Tested-by: Noel Grandin 
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/string.h b/include/rtl/string.h
index d29caf93a718..62fc7ecfb2d0 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -747,6 +747,31 @@ SAL_DLLPUBLIC sal_Bool SAL_CALL rtl_str_toBoolean(
 SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32(
 const char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C();
 
+/** Interpret a string as a integer.
+
+This function cannot be used for language-specific conversion.  The string
+must be null-terminated.
+
+@param str
+a null-terminated string.
+
+@param radix
+the radix.  Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
+(36), inclusive.
+
+@param nStrLength
+number of chars to process
+
+@return
+the integer value represented by the string, or 0 if the string does
+not represent a integer.
+
+@internal
+@since LibreOffice 7.3
+*/
+SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32_WithLength(
+const char * str, sal_Int16 radix, sal_Int32 nStrLength ) 
SAL_THROW_EXTERN_C();
+
 /** Interpret a string as an unsigned integer.
 
 This function cannot be used for language-specific conversion.  The string
@@ -863,6 +888,26 @@ SAL_DLLPUBLIC float SAL_CALL rtl_str_toFloat(
 SAL_DLLPUBLIC double SAL_CALL rtl_str_toDouble(
 const char * str ) SAL_THROW_EXTERN_C();
 
+/** Interpret a string as a double.
+
+This function cannot be used for language-specific conversion.  The string
+must be null-terminated.
+
+@param str
+a null-terminated string.
+
+@param nStrLength
+number of chars to process
+
+@return
+the double value represented by the string, or 0.0 if the string does not
+represent a double.
+
+@since LibreOffice 7.3
+ */
+SAL_DLLPUBLIC double SAL_CALL rtl_str_toDouble_WithLength(
+const char * str, sal_Int32 nStrLength ) SAL_THROW_EXTERN_C();
+
 /* === */
 
 #ifdef _WIN32
diff --git a/sal/rtl/string.cxx b/sal/rtl/string.cxx
index 94be8029032a..6fc2df75698d 100644
--- a/sal/rtl/string.cxx
+++ b/sal/rtl/string.cxx
@@ -110,6 +110,14 @@ double SAL_CALL rtl_str_toDouble(char const * pStr) 
SAL_THROW_EXTERN_C()
nullptr, nullptr);
 }
 
+double SAL_CALL rtl_str_toDouble_WithLength(const char* pStr,
+  sal_Int32 nStrLength) 
SAL_THROW_EXTERN_C()
+{
+assert(pStr);
+return rtl_math_stringToDouble(pStr, pStr + nStrLength, '.', 0,
+   nullptr, nullptr);
+}
+
 /* === */
 
 static int rtl_ImplGetFastUTF8ByteLen( const sal_Unicode* pStr, sal_Int32 nLen 
)
@@ -559,6 +567,12 @@ sal_Int32 SAL_CALL rtl_str_toInt32(const char* pStr, 
sal_Int16 nRadix) SAL_THROW
 return rtl::str::toInt32(pStr, nRadix);
 }
 
+sal_Int32 SAL_CALL rtl_str_toInt32_WithLength(const char* pStr, sal_Int16 
nRadix,
+  sal_Int32 nStrLength) 
SAL_THROW_EXTERN_C()
+{
+return rtl::str::toInt32_WithLength(pStr, nRadix, nStrLength);
+}
+
 sal_Int64 SAL_CALL rtl_str_toInt64(const char* pStr, sal_Int16 nRadix) 
SAL_THROW_EXTERN_C()
 {
 return rtl::str::toInt64(pStr, nRadix);
diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx
index 094a1cc1f2ab..493184f92efa 100644
--- a/sal/rtl/strtmpl.hxx
+++ b/sal/rtl/strtmpl.hxx
@@ -913,6 +913,16 @@ sal_Int32 toInt32 ( const 
IMPL_RTL_STRCODE* pStr,
 return toInt_WithLength(pStr, nRadix, 
getLength(pStr));
 }
 
+template 
+sal_Int32 toInt32_WithLength  ( const IMPL_RTL_STRCODE* pStr,
+sal_Int16 nRadix,
+sal_Int32 nStrLength)
+
+{
+assert(pStr);
+return toInt_WithLength(pStr, nRadix, nStrLength);
+}
+
 template 
 sal_Int64 toInt64 ( const IMPL_RTL_STRCODE* pStr,
 sal_Int16 

[Libreoffice-commits] core.git: include/rtl sal/rtl sal/util sdext/source

2021-05-18 Thread Noel Grandin (via logerrit)
 include/rtl/string.h   |   51 +++--
 include/rtl/string.hxx |2 -
 sal/rtl/string.cxx |5 --
 sal/rtl/strtmpl.hxx|9 -
 sal/util/sal.map   |3 -
 sdext/source/pdfimport/wrapper/wrapper.cxx |   10 -
 6 files changed, 16 insertions(+), 64 deletions(-)

New commits:
commit 7462343cb9c7a61cd28c7eae245f21b6bfc56b40
Author: Noel Grandin 
AuthorDate: Mon May 17 15:17:13 2021 +0200
Commit: Noel Grandin 
CommitDate: Tue May 18 12:58:55 2021 +0200

update "add OString::getTokenView"

update
commit 3669d4ec43a6aa2d410d8351d631548db45a5302
Date:   Fri May 14 15:51:38 2021 +0200
add OString::getTokenView (tdf#42374 related)
with suggested changes from gerrit review

Change-Id: I861d960deaa010740a4aa964e402c4c76a85cbc7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115706
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/string.h b/include/rtl/string.h
index c0f724245d9e..c86468c7f302 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -747,31 +747,6 @@ SAL_DLLPUBLIC sal_Bool SAL_CALL rtl_str_toBoolean(
 SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32(
 const char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C();
 
-/** Interpret a string as an integer.
-
-This function cannot be used for language-specific conversion.  The string
-must be null-terminated.
-
-@param str
-a null-terminated string.
-
-@param radix
-the radix.  Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
-(36), inclusive.
-
-@param len
-the length of the character array.
-
-@return
-the integer value represented by the string, or 0 if the string does not
-represent an integer.
-
-@since LibreOffice 7.2
-@internal
- */
-SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32_WithLength(
-const char * str, sal_Int16 radix, sal_Int32 nStrLength ) 
SAL_THROW_EXTERN_C();
-
 /** Interpret a string as an unsigned integer.
 
 This function cannot be used for language-specific conversion.  The string
@@ -1289,7 +1264,7 @@ SAL_DLLPUBLIC void SAL_CALL rtl_string_newTrim(
 
 /** Create a new string by extracting a single token from another string.
 
-Starting at index, the token's next token is searched for.  If there is no
+Starting at index, the next token is searched for.  If there is no
 such token, the result is an empty string.  Otherwise, all characters from
 the start of that token and up to, but not including the next occurrence
 of cTok make up the resulting token.  The return value is the position of
@@ -1334,33 +1309,19 @@ SAL_DLLPUBLIC void SAL_CALL rtl_string_newTrim(
 SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_string_getToken(
 rtl_String ** newStr , rtl_String * str, sal_Int32 token, char cTok, 
sal_Int32 idx ) SAL_THROW_EXTERN_C();
 
+/** @cond INTERNAL */
 /** Create a new string by extracting a single token from another string.
 
-Starting at index, the token's next token is searched for.  If there is no
+Starting at index, the next token is searched for.  If there is no
 such token, the result is an empty string.  Otherwise, all characters from
 the start of that token and up to, but not including the next occurrence
 of cTok make up the resulting token.  The return value is the position of
 the next token, or -1 if no more tokens follow.
 
-Example code could look like
-  rtl_String * pToken = NULL;
-  sal_Int32 nIndex = 0;
-  do
-  {
-  ...
-  nIndex = rtl_string_getToken(, pStr, 0, ';', nIndex);
-  ...
-  }
-  while (nIndex >= 0);
-
-The new string does not necessarily have a reference count of 1, so it
-must not be modified without checking the reference count.  This function
-does not handle out-of-memory conditions.
+This function does not handle out-of-memory conditions.
 
 @param ppViewStr
-pointer to the start of the token.  The pointed-to data must be null or a 
valid
-string.  If either token or index is negative, nullptr is stored in
-newStr (and -1 is returned).
+pointer to the start of the token.
 
 @param pViewLength
 length of the token.
@@ -1382,10 +1343,10 @@ SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_string_getToken(
 the index of the next token, or -1 if no more tokens follow.
 
 @since LibreOffice 7.2
-@internal
  */
 SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_string_getTokenView(
 const char ** ppViewStr , sal_Int32* pViewLength, rtl_String * str, 
sal_Int32 token, char cTok, sal_Int32 idx ) SAL_THROW_EXTERN_C();
+/** @endcond */
 
 /* === */
 
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index c16519fa14df..3fc461de0c2c 100644
--- a/include/rtl/string.hxx
+++ 

[Libreoffice-commits] core.git: include/rtl sal/rtl sal/util sdext/source

2021-05-15 Thread Noel Grandin (via logerrit)
 include/rtl/string.h   |   78 +
 include/rtl/string.hxx |9 +++
 sal/rtl/string.cxx |   10 +++
 sal/rtl/strtmpl.hxx|   76 
 sal/util/sal.map   |8 ++
 sdext/source/pdfimport/wrapper/wrapper.cxx |   31 +++
 6 files changed, 199 insertions(+), 13 deletions(-)

New commits:
commit 3669d4ec43a6aa2d410d8351d631548db45a5302
Author: Noel Grandin 
AuthorDate: Fri May 14 15:51:38 2021 +0200
Commit: Noel Grandin 
CommitDate: Sat May 15 11:21:59 2021 +0200

add OString::getTokenView (tdf#42374 related)

small improvement to PDF import

no need to construct temporary string objects when we are just to
going to convert them into int/double.
So use a view and convert the data through the view.

Change-Id: I824fe88bf17142b48fe6032e10c0f3a111927e96
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115616
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/string.h b/include/rtl/string.h
index bfbb45057fd9..c0f724245d9e 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -747,6 +747,31 @@ SAL_DLLPUBLIC sal_Bool SAL_CALL rtl_str_toBoolean(
 SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32(
 const char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C();
 
+/** Interpret a string as an integer.
+
+This function cannot be used for language-specific conversion.  The string
+must be null-terminated.
+
+@param str
+a null-terminated string.
+
+@param radix
+the radix.  Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
+(36), inclusive.
+
+@param len
+the length of the character array.
+
+@return
+the integer value represented by the string, or 0 if the string does not
+represent an integer.
+
+@since LibreOffice 7.2
+@internal
+ */
+SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32_WithLength(
+const char * str, sal_Int16 radix, sal_Int32 nStrLength ) 
SAL_THROW_EXTERN_C();
+
 /** Interpret a string as an unsigned integer.
 
 This function cannot be used for language-specific conversion.  The string
@@ -1309,6 +1334,59 @@ SAL_DLLPUBLIC void SAL_CALL rtl_string_newTrim(
 SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_string_getToken(
 rtl_String ** newStr , rtl_String * str, sal_Int32 token, char cTok, 
sal_Int32 idx ) SAL_THROW_EXTERN_C();
 
+/** Create a new string by extracting a single token from another string.
+
+Starting at index, the token's next token is searched for.  If there is no
+such token, the result is an empty string.  Otherwise, all characters from
+the start of that token and up to, but not including the next occurrence
+of cTok make up the resulting token.  The return value is the position of
+the next token, or -1 if no more tokens follow.
+
+Example code could look like
+  rtl_String * pToken = NULL;
+  sal_Int32 nIndex = 0;
+  do
+  {
+  ...
+  nIndex = rtl_string_getToken(, pStr, 0, ';', nIndex);
+  ...
+  }
+  while (nIndex >= 0);
+
+The new string does not necessarily have a reference count of 1, so it
+must not be modified without checking the reference count.  This function
+does not handle out-of-memory conditions.
+
+@param ppViewStr
+pointer to the start of the token.  The pointed-to data must be null or a 
valid
+string.  If either token or index is negative, nullptr is stored in
+newStr (and -1 is returned).
+
+@param pViewLength
+length of the token.
+
+@param str
+a valid string.
+
+@param token
+the number of the token to return, starting at index.
+
+@param cTok
+the character that separates the tokens.
+
+@param idx
+the position at which searching for the token starts.  Must not be greater
+than the length of str.
+
+@return
+the index of the next token, or -1 if no more tokens follow.
+
+@since LibreOffice 7.2
+@internal
+ */
+SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_string_getTokenView(
+const char ** ppViewStr , sal_Int32* pViewLength, rtl_String * str, 
sal_Int32 token, char cTok, sal_Int32 idx ) SAL_THROW_EXTERN_C();
+
 /* === */
 
 /** Supply an ASCII string literal together with its length.
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index f80dd7410da7..c16519fa14df 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -1765,6 +1765,15 @@ public:
 index = rtl_string_getToken( , pData, token, cTok, index );
 return OString( pNew, SAL_NO_ACQUIRE );
 }
+#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
+std::string_view getTokenView( sal_Int32 token, char cTok, sal_Int32& 
index ) const
+{
+const char* pViewData = nullptr;
+sal_Int32 nViewLength = 

[Libreoffice-commits] core.git: include/rtl

2021-05-12 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx |   54 -
 1 file changed, 45 insertions(+), 9 deletions(-)

New commits:
commit ad48b2b02f83eed41fb1eb8d16de7e804156fcf1
Author: Stephan Bergmann 
AuthorDate: Wed May 12 07:31:20 2021 +0200
Commit: Stephan Bergmann 
CommitDate: Wed May 12 09:23:36 2021 +0200

Optimized OString operator += overloads

...similar to how OUString got an operator += overload for 
std::u16string_view
with c927aab29ebfff1ce3ac0b2f27ae343025a9890c "Make the OUString ctors 
taking
raw sal_Unicode pointer/non-const array explicit".  In this case, though, 
we can
easily add enough overloads (which forward to the one taking 
std::string_view)
to avoid any ambiguities at call sites.

We had left this out in the past as there is no suitable 
rtl_string_newConcat*
function to use in the implementation, but we already had inline 
implementations
of OStringConcat/OStringNumber overloads, so stick to that pattern here 
with the
new std::string_view overload.

Change-Id: I329036ea2b62cb921b4dbc1eef7c45a9cdb56e13
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115452
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index a6812cc7c7df..f80dd7410da7 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -480,6 +480,50 @@ public:
 void operator+=(OString const &) && = delete;
 #endif
 
+#if defined LIBO_INTERNAL_ONLY
+template typename libreoffice_internal::CharPtrDetector::Type
+operator +=(T const & value) & { return operator 
+=(std::string_view(value)); }
+template typename libreoffice_internal::CharPtrDetector::Type
+operator +=(T const &) && = delete;
+
+template
+typename libreoffice_internal::NonConstCharArrayDetector::Type
+operator +=(T & value) & { return operator +=(std::string_view(value)); }
+template
+typename libreoffice_internal::NonConstCharArrayDetector::Type operator +=(T &) &&
+= delete;
+
+template typename 
libreoffice_internal::ConstCharArrayDetector::Type
+operator +=(T & literal) & {
+
assert(libreoffice_internal::ConstCharArrayDetector::isValid(literal));
+return operator +=(
+std::string_view(
+
libreoffice_internal::ConstCharArrayDetector::toPointer(literal),
+libreoffice_internal::ConstCharArrayDetector::length));
+}
+template typename 
libreoffice_internal::ConstCharArrayDetector::Type
+operator +=(T &) && = delete;
+
+template OString & operator +=(OStringLiteral const & 
literal) &
+{ return operator +=(std::string_view(literal.getStr(), 
literal.getLength())); }
+template void operator +=(OStringLiteral const &) && = 
delete;
+
+OString & operator +=(std::string_view sv) & {
+if (sv.empty()) {
+return *this;
+}
+if (sv.size() > sal_uInt32(std::numeric_limits::max() - 
pData->length)) {
+throw std::bad_alloc();
+}
+auto const l = pData->length + sv.size();
+rtl_string_ensureCapacity(, l);
+*addDataHelper(pData->buffer + pData->length, sv.data(), sv.size()) = 
'\0';
+pData->length = l;
+return *this;
+}
+void operator +=(std::string_view) && = delete;
+#endif
+
 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
 /**
  @overload
@@ -506,15 +550,7 @@ public:
 */
 template< typename T >
 OString& operator+=( OStringNumber< T >&& n ) & {
-sal_Int32 l = n.length;
-if( l == 0 )
-return *this;
-l += pData->length;
-rtl_string_ensureCapacity( , l );
-char* end = addDataHelper( pData->buffer + pData->length, n.buf, 
n.length );
-*end = '\0';
-pData->length = l;
-return *this;
+return operator +=(std::string_view(n.buf, n.length));
 }
 template void operator +=(
 OStringNumber &&) && = delete;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2021-04-23 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx |6 --
 1 file changed, 6 deletions(-)

New commits:
commit 9eba8aa38db3a0dc2f7dfaf24a003c16418aef18
Author: Stephan Bergmann 
AuthorDate: Fri Apr 23 11:18:56 2021 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Apr 23 13:27:11 2021 +0200

Remove dubious #pragma pack

...that were introduced with bca539e889d40e06cb3275442622cb075b2484a2 "make
OString(OStringLiteral) constructor constexpr", apparently to mimic the
corresponding #pragma pack for rtl_String in include/rtl/string.h.  But 
neither
of them appear to have any value:  All struct member types involved
(oslInterlockedCount aka sal_Int32, sal_Int32 itself, and char) have size < 
8,
so the member alignment ("on a boundary that's either a multiple of [the 
pragma
pack value], or a multiple of the size of the member, whichever is smaller",
according to
) is 
not
affected.  And neither are alignof(rtl_String) and 
alignof(OStringLiteral)
affected, which remain e.g. 4 on x86-64.  (And prior to
bca539e889d40e06cb3275442622cb075b2484a2, OStringLiteral did not have any 
pragma
pack cargo cult, but which did not cause OStringLiteral::assertLayout to 
fail,
or raise any other documented issues.)

So remove the pragma pack cargo cult again at least from OStringLiteral.  
(And
leave potential removal from rtl_String for another commit.)

(This is similar to the corresponding 
f62cb40bdfaf41cf8e989640f9be79f652f30914
"Remove dubious #pragma pack" for OUStringLiteral.)

Change-Id: I7808837a667bca717aa2e3abfdf9cb16268789ec
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114535
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 98abce8fca53..a6812cc7c7df 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -134,9 +134,6 @@ private:
 static_assert(offsetof(OStringLiteral, str.buffer) == 
offsetof(OStringLiteral, more.buffer));
 }
 
-#if defined(_WIN32)
-#pragma pack(push, 8)
-#endif
 union {
 rtl_String str;
 struct {
@@ -150,9 +147,6 @@ private:
 {} //TODO: drop initialization for C++20 (P1331R2)
 };
 };
-#if defined(_WIN32)
-#pragma pack(pop)
-#endif
 };
 #endif
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2021-04-23 Thread Noel Grandin (via logerrit)
 include/rtl/string.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 983c1146ac80c038feae653e8e3752a72171d6cb
Author: Noel Grandin 
AuthorDate: Fri Apr 23 09:15:23 2021 +0200
Commit: Noel Grandin 
CommitDate: Fri Apr 23 11:31:43 2021 +0200

actually make OString(OStringLiteral) constructor constexpr

doh! forgot the most important part in
commit bca539e889d40e06cb3275442622cb075b2484a2
make OString(OStringLiteral) constructor constexpr

Change-Id: I0c13b3b8f33f643fa72c11d8596bab70e863a879
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114529
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 348a08055d50..98abce8fca53 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -337,7 +337,7 @@ public:
 
   @since LibreOffice 7.1
 */
-template OString(OStringLiteral const & literal):
+template constexpr OString(OStringLiteral const & 
literal):
 pData(const_cast()) {}
 template OString(OStringLiteral &&) = delete;
 /// @endcond
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2021-04-23 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 7ded81e407f9218e19f2f5cdd8e1372ab6edf142
Author: Stephan Bergmann 
AuthorDate: Fri Apr 23 08:26:24 2021 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Apr 23 10:07:54 2021 +0200

Fix --with-latest-c++ build

...after bca539e889d40e06cb3275442622cb075b2484a2 "make 
OString(OStringLiteral)
constructor constexpr"

Change-Id: I5be28505f0222bbd4d10c7aa5233bd7346136de7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114528
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 321255a1040b..348a08055d50 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -114,7 +114,7 @@ public:
 assert(literal[N - 1] == '\0');
 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
 for (std::size_t i = 0; i != N; ++i) {
-buffer[i] = literal[i];
+more.buffer[i] = literal[i];
 }
 }
 #endif
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2021-04-23 Thread Stephan Bergmann (via logerrit)
 include/rtl/ustring.hxx |6 --
 1 file changed, 6 deletions(-)

New commits:
commit f62cb40bdfaf41cf8e989640f9be79f652f30914
Author: Stephan Bergmann 
AuthorDate: Thu Apr 22 14:49:06 2021 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Apr 23 08:10:55 2021 +0200

Remove dubious #pragma pack

...that were introduced with 21584b304b21bfe6b99b6f29018c6b754ea28fc0 "make
OUString(OUStringLiteral) constructor constexpr", apparently to mimic the
corresponding #pragma pack for rtl_uString in include/rtl/ustring.h.  But
neither of them appear to have any value:  All struct member types involved
(oslInterlockedCount aka sal_Int32, sal_Int32 itself, and sal_Unicode) have 
size
<= 4, so the member alignment ("on a boundary that's either a multiple of 
[the
pragma pack value], or a multiple of the size of the member, whichever is
smaller", according to
) is 
not
affected.  And neither are alignof(rtl_uString) and 
alignof(OUStringLiteral)
affected, which remain e.g. 4 on x86-64.  (And prior to
21584b304b21bfe6b99b6f29018c6b754ea28fc0, OUStringLiteral did not have any
pragma pack cargo cult, but which did not cause 
OUStringLiteral::assertLayout to
fail, or raise any other documented issues.)

So remove the pragma pack cargo cult again at least from OUStringLiteral.  
(And
leave potential removal from rtl_uString for another commit.)

Change-Id: I1a3626f0db1a0413ff792bd00ebaf76e4249b13f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114484
Reviewed-by: Noel Grandin 
Reviewed-by: Stephan Bergmann 
Tested-by: Jenkins

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index e1ae2d38f2d9..2699c09ac03f 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -115,9 +115,6 @@ private:
 static_assert(offsetof(OUStringLiteral, str.buffer) == 
offsetof(OUStringLiteral, more.buffer));
 }
 
-#if defined(_WIN32)
-#pragma pack(push, 4)
-#endif
 union {
 rtl_uString str;
 struct {
@@ -131,9 +128,6 @@ private:
 {} //TODO: drop initialization for C++20 (P1331R2)
 };
 };
-#if defined(_WIN32)
-#pragma pack(pop)
-#endif
 };
 
 #if defined RTL_STRING_UNITTEST
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2021-04-22 Thread Noel Grandin (via logerrit)
 include/rtl/string.hxx |   51 -
 1 file changed, 30 insertions(+), 21 deletions(-)

New commits:
commit bca539e889d40e06cb3275442622cb075b2484a2
Author: Noel Grandin 
AuthorDate: Thu Apr 22 14:47:27 2021 +0200
Commit: Noel Grandin 
CommitDate: Thu Apr 22 18:38:34 2021 +0200

make OString(OStringLiteral) constructor constexpr

i.e. a copy of
   commit 21584b304b21bfe6b99b6f29018c6b754ea28fc0
   make OUString(OUStringLiteral) constructor constexpr

Change-Id: If5b0c2b896f8a730d01a076d3eb9161ad628979b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114480
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index def5d2b8b141..321255a1040b 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -86,6 +86,7 @@ This class is not part of public API and is meant to be used 
only in LibreOffice
 template class SAL_WARN_UNUSED OStringLiteral {
 static_assert(N != 0);
 static_assert(N - 1 <= std::numeric_limits::max(), "literal too 
long");
+friend class OString;
 
 public:
 #if HAVE_CPP_CONSTEVAL
@@ -98,7 +99,7 @@ public:
 assert(literal[N - 1] == '\0');
 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
 for (std::size_t i = 0; i != N; ++i) {
-buffer[i] = literal[i];
+more.buffer[i] = literal[i];
 }
 }
 
@@ -118,32 +119,40 @@ public:
 }
 #endif
 
-constexpr sal_Int32 getLength() const { return length; }
+constexpr sal_Int32 getLength() const { return more.length; }
 
-constexpr char const * getStr() const SAL_RETURNS_NONNULL { return buffer; 
}
+constexpr char const * getStr() const SAL_RETURNS_NONNULL { return 
more.buffer; }
 
-constexpr operator std::string_view() const { return {buffer, 
sal_uInt32(length)}; }
+constexpr operator std::string_view() const { return {more.buffer, 
sal_uInt32(more.length)}; }
 
 private:
 static constexpr void assertLayout() {
 // These static_asserts verifying the layout compatibility with 
rtl_String cannot be class
 // member declarations, as offsetof requires a complete type, so defer 
them to here:
-static_assert(offsetof(OStringLiteral, refCount) == 
offsetof(rtl_String, refCount));
-static_assert(
-std::is_same_v);
-static_assert(offsetof(OStringLiteral, length) == offsetof(rtl_String, 
length));
-static_assert(std::is_same_v);
-static_assert(offsetof(OStringLiteral, buffer) == offsetof(rtl_String, 
buffer));
-static_assert(
-std::is_same_v<
-std::remove_extent_t,
-std::remove_extent_t>);
-}
-
-// Same layout as rtl_String (include/rtl/string.h):
-oslInterlockedCount refCount = 0x4000; // SAL_STRING_STATIC_FLAG 
(sal/rtl/strimp.hxx)
-sal_Int32 length = N - 1;
-char buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2)
+static_assert(offsetof(OStringLiteral, str.refCount) == 
offsetof(OStringLiteral, more.refCount));
+static_assert(offsetof(OStringLiteral, str.length) == 
offsetof(OStringLiteral, more.length));
+static_assert(offsetof(OStringLiteral, str.buffer) == 
offsetof(OStringLiteral, more.buffer));
+}
+
+#if defined(_WIN32)
+#pragma pack(push, 8)
+#endif
+union {
+rtl_String str;
+struct {
+oslInterlockedCount refCount;
+sal_Int32 length;
+char buffer[N];
+} more =
+{
+0x4000, // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
+N - 1,
+{} //TODO: drop initialization for C++20 (P1331R2)
+};
+};
+#if defined(_WIN32)
+#pragma pack(pop)
+#endif
 };
 #endif
 
@@ -329,7 +338,7 @@ public:
   @since LibreOffice 7.1
 */
 template OString(OStringLiteral const & literal):
-pData(const_cast(reinterpret_cast())) {}
+pData(const_cast()) {}
 template OString(OStringLiteral &&) = delete;
 /// @endcond
 #endif
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2021-04-21 Thread Noel Grandin (via logerrit)
 include/rtl/strbuf.hxx  |4 
 include/rtl/ustrbuf.hxx |5 +
 2 files changed, 9 insertions(+)

New commits:
commit 967da14b48035f5acdd8a604a5c33cc6fe37035a
Author: Noel Grandin 
AuthorDate: Wed Apr 21 11:56:40 2021 +0200
Commit: Noel Grandin 
CommitDate: Wed Apr 21 17:58:54 2021 +0200

string_view conversion operator for O[U]StringBuffer

which will be useful in an upcoming change of mine, so I don't need to
construct a temporary from a buffer

Change-Id: I1737a725ac5792b7d866d7f2b4c9f9ff7b50dffe
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114397
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 5bdf072a..a238f305fa07 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -248,6 +248,10 @@ public:
 {}
 #endif
 
+#if defined LIBO_INTERNAL_ONLY
+operator std::string_view() const { return {getStr(), 
sal_uInt32(getLength())}; }
+#endif
+
 /** Assign to this a copy of value.
  */
 OStringBuffer& operator = ( const OStringBuffer& value )
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 170b76908dff..65762d53960d 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -253,6 +253,11 @@ public:
 rtl_uStringbuffer_newFromStr_WithLength( , n.buf, n.length );
 }
 #endif
+
+#if defined LIBO_INTERNAL_ONLY
+operator std::u16string_view() const { return {getStr(), 
sal_uInt32(getLength())}; }
+#endif
+
 /** Assign to this a copy of value.
  */
 OUStringBuffer& operator = ( const OUStringBuffer& value )
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2021-04-20 Thread Noel Grandin (via logerrit)
 include/rtl/ustring.hxx |   52 
 1 file changed, 31 insertions(+), 21 deletions(-)

New commits:
commit 21584b304b21bfe6b99b6f29018c6b754ea28fc0
Author: Noel Grandin 
AuthorDate: Mon Apr 19 11:41:47 2021 +0200
Commit: Noel Grandin 
CommitDate: Tue Apr 20 15:30:50 2021 +0200

make OUString(OUStringLiteral) constructor constexpr

with the intent that we can declare
static const OUStringLiteral FOO = "bar";
static const struct {
  OUString s;
} xxx = { FOO };
and have the xxx laid out at compile time.

Kudos to mikekaganski for coming up with the idea of using
the rtl_uString struct inside OUStringLiteral.

We are using a union to defeat the array bounds checking
that the compiler does when it evaluates constexpr values,
so this might be brittle.

Change-Id: I9a6247a17afab2eb28df139d532a8d864c49cd62
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114196
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index bb3390c19985..e1ae2d38f2d9 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -83,6 +83,7 @@ This class is not part of public API and is meant to be used 
only in LibreOffice
 template class SAL_WARN_UNUSED OUStringLiteral {
 static_assert(N != 0);
 static_assert(N - 1 <= std::numeric_limits::max(), "literal too 
long");
+friend class OUString;
 
 public:
 #if HAVE_CPP_CONSTEVAL
@@ -95,35 +96,44 @@ public:
 assert(literal[N - 1] == '\0');
 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
 for (std::size_t i = 0; i != N; ++i) {
-buffer[i] = literal[i];
+more.buffer[i] = literal[i];
 }
 }
 
-constexpr sal_Int32 getLength() const { return length; }
+constexpr sal_Int32 getLength() const { return more.length; }
 
-constexpr sal_Unicode const * getStr() const SAL_RETURNS_NONNULL { return 
buffer; }
+constexpr sal_Unicode const * getStr() const SAL_RETURNS_NONNULL { return 
more.buffer; }
 
-constexpr operator std::u16string_view() const { return {buffer, 
sal_uInt32(length)}; }
+constexpr operator std::u16string_view() const { return {more.buffer, 
sal_uInt32(more.length)}; }
 
 private:
 static constexpr void assertLayout() {
 // These static_asserts verifying the layout compatibility with 
rtl_uString cannot be class
 // member declarations, as offsetof requires a complete type, so defer 
them to here:
-static_assert(offsetof(OUStringLiteral, refCount) == 
offsetof(rtl_uString, refCount));
-static_assert(std::is_same_v);
-static_assert(offsetof(OUStringLiteral, length) == 
offsetof(rtl_uString, length));
-static_assert(std::is_same_v);
-static_assert(offsetof(OUStringLiteral, buffer) == 
offsetof(rtl_uString, buffer));
-static_assert(
-std::is_same_v<
-std::remove_extent_t,
-std::remove_extent_t>);
-}
-
-// Same layout as rtl_uString (include/rtl/ustring.h):
-oslInterlockedCount refCount = 0x4000; // SAL_STRING_STATIC_FLAG 
(sal/rtl/strimp.hxx)
-sal_Int32 length = N - 1;
-sal_Unicode buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2)
+static_assert(offsetof(OUStringLiteral, str.refCount) == 
offsetof(OUStringLiteral, more.refCount));
+static_assert(offsetof(OUStringLiteral, str.length) == 
offsetof(OUStringLiteral, more.length));
+static_assert(offsetof(OUStringLiteral, str.buffer) == 
offsetof(OUStringLiteral, more.buffer));
+}
+
+#if defined(_WIN32)
+#pragma pack(push, 4)
+#endif
+union {
+rtl_uString str;
+struct {
+oslInterlockedCount refCount;
+sal_Int32 length;
+sal_Unicode buffer[N];
+} more =
+{
+0x4000, // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
+N - 1,
+{} //TODO: drop initialization for C++20 (P1331R2)
+};
+};
+#if defined(_WIN32)
+#pragma pack(pop)
+#endif
 };
 
 #if defined RTL_STRING_UNITTEST
@@ -385,8 +395,8 @@ public:
 
   @since LibreOffice 5.0
 */
-template OUString(OUStringLiteral const & literal):
-pData(const_cast(reinterpret_cast())) {}
+template constexpr OUString(OUStringLiteral const & 
literal):
+pData(const_cast()) {}
 template OUString(OUStringLiteral &&) = delete;
 /// @endcond
 #endif
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2021-03-15 Thread Stephan Bergmann (via logerrit)
 include/rtl/stringconcat.hxx |2 +-
 include/rtl/ustrbuf.hxx  |1 -
 include/rtl/ustring.hxx  |1 -
 3 files changed, 1 insertion(+), 3 deletions(-)

New commits:
commit 5d83d14ef8e3a149f2dbcddc18a70edda021fbfe
Author: Stephan Bergmann 
AuthorDate: Fri Mar 12 16:04:19 2021 +0100
Commit: Stephan Bergmann 
CommitDate: Mon Mar 15 09:25:27 2021 +0100

Clarify that rtl::ToStringHelper::length must be precise

d87f5d30879aca73fff271c254589fc41a91fdd0 "support for fast O(U)String
concatenation using operator+", introducing rtl::ToStringHelper, had 
intended
that length can return an optimistic maximum value if the exact value 
cannot be
determined (e.g., when creating the textual representation of a numerical 
value
only on the fly, not upfront), witness the comments removed now, but never 
made
use of that, always returning precise values from the various
rtl::ToStringHelper::length specializations.

And then cbe3b2fe0b9d745e22a2bf436ce55141b15f9502 "Avoid conversion warning 
in
O[U]String[Buffer] constructors", not being aware that length could
theoretically return an imprecise value, made certain code rely on it always
returning a precise value.

So clarify the status quo, that length always returns a precise value.  (See
also the discussion in the comments of abandoned
 "Drop obsolete comments".)

Change-Id: I7dc72e9e15304779cc4d2edc01331959b6fbe869
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112397
Reviewed-by: Luboš Luňák 
Reviewed-by: Stephan Bergmann 
Tested-by: Jenkins

diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx
index 7f55d6c3473d..554fdd3f4403 100644
--- a/include/rtl/stringconcat.hxx
+++ b/include/rtl/stringconcat.hxx
@@ -59,7 +59,7 @@ Helper class for converting a given type to a string 
representation.
 template< typename T >
 struct ToStringHelper
 {
-/// Return length of the string representation of the given object (if not 
known exactly, it needs to be the maximum).
+/// Return length of the string representation of the given object.
 static std::size_t length( const T& );
 /// Add 8-bit representation of the given object to the given buffer and 
return position right after the added data.
 static char* addData( char* buffer, const T& ) SAL_RETURNS_NONNULL;
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index f1f2521a8ae5..170b76908dff 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -239,7 +239,6 @@ public:
 sal_Unicode* end = c.addData( pData->buffer );
 *end = '\0';
 pData->length = l;
-// TODO realloc in case pData->>length is noticeably smaller than l ?
 }
 
 /**
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 597a56832ad5..bb3390c19985 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -457,7 +457,6 @@ public:
 sal_Unicode* end = c.addData( pData->buffer );
 pData->length = l;
 *end = '\0';
-// TODO realloc in case pData->length is noticeably smaller than l?
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2021-02-12 Thread Noel (via logerrit)
 include/rtl/ref.hxx |   12 
 1 file changed, 12 insertions(+)

New commits:
commit 138064713af2db8e797e3aa441657f6a7500cc46
Author: Noel 
AuthorDate: Fri Feb 12 12:48:54 2021 +0200
Commit: Noel Grandin 
CommitDate: Fri Feb 12 14:33:02 2021 +0100

add conversion operator to rtl::Reference

to make it easier to convert to uno::Reference

Change-Id: I7ec1d66651e21ec71f1eef035d7ed3d6acc70b91
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110810
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/ref.hxx b/include/rtl/ref.hxx
index 37cbad4da8c0..38dfe3769e81 100644
--- a/include/rtl/ref.hxx
+++ b/include/rtl/ref.hxx
@@ -31,6 +31,7 @@
 #include 
 #ifdef LIBO_INTERNAL_ONLY
 #include 
+#include "com/sun/star/uno/Reference.h"
 #endif
 
 #include "sal/types.h"
@@ -107,6 +108,17 @@ public:
 if (m_pBody)
 m_pBody->acquire();
 }
+
+/** Up-casting conversion operator to convert to css::uno::Interface
+
+Does not work for up-casts to ambiguous bases.
+*/
+template< class super_type,
+std::enable_if_t, int> = 
0 >
+inline operator css::uno::Reference() const
+{
+return css::uno::Reference(m_pBody);
+}
 #endif
 
 /** Destructor...
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2021-02-08 Thread Michael Stahl (via logerrit)
 include/rtl/uri.h |   13 +
 1 file changed, 13 insertions(+)

New commits:
commit c5329ac1fa239bf4864e44c557210e9b08c47c68
Author: Michael Stahl 
AuthorDate: Wed Feb 3 19:43:31 2021 +0100
Commit: Michael Stahl 
CommitDate: Mon Feb 8 14:56:37 2021 +0100

rtl::Uri: document difference of rtl_UriCharClass to RFC 3986

Change-Id: I640777aa7bb4baf5b0d74e996c036e16f6127d57
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110387
Tested-by: Jenkins
Reviewed-by: Michael Stahl 

diff --git a/include/rtl/uri.h b/include/rtl/uri.h
index 7767762da229..1fbd0128ab89 100644
--- a/include/rtl/uri.h
+++ b/include/rtl/uri.h
@@ -59,6 +59,8 @@ typedef enum
 @verbatim
 The 'valid' characters are !$&'()*+,-./:;=?@[]_~ plus digits and
 letters.
+
+This differs from RFC 3986 @ in additionally allowing []
 @endverbatim
  */
 rtl_UriCharClassUric,
@@ -67,6 +69,9 @@ typedef enum
 
 @verbatim
 The 'valid' characters are !$&'()*+,-.:;=?@_~ plus digits and letters.
+
+This differs from RFC 3986 @ in additionally encoding /
+This differs from RFC 3986 @ in additionally allowing ?
 @endverbatim
  */
 rtl_UriCharClassUricNoSlash,
@@ -75,6 +80,8 @@ typedef enum
 
 @verbatim
 The 'valid' characters are !$&'()*+,-.;=@_~ plus digits and letters.
+
+This is the same as RFC 3986 @
 @endverbatim
  */
 rtl_UriCharClassRelSegment,
@@ -83,6 +90,8 @@ typedef enum
 
 @verbatim
 The 'valid' characters are !$&'()*+,-.:;=@_~ plus digits and letters.
+
+This differs from RFC 3986 @ in additionally allowing @
 @endverbatim
  */
 rtl_UriCharClassRegName,
@@ -91,6 +100,8 @@ typedef enum
 
 @verbatim
 The 'valid' characters are !$&'()*+,-.:;=_~ plus digits and letters.
+
+This is the same as RFC 3986 @
 @endverbatim
  */
 rtl_UriCharClassUserinfo,
@@ -99,6 +110,8 @@ typedef enum
 
 @verbatim
 The 'valid' characters are !$&'()*+,-.:=@_~ plus digits and letters.
+
+This differs from RFC 3986 @ in additionally encoding ;
 @endverbatim
  */
 rtl_UriCharClassPchar,
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl sal/qa sot/source

2021-01-14 Thread Tor Lillqvist (via logerrit)
 include/rtl/ustring.hxx   |   20 
 sal/qa/rtl/oustring/rtl_OUString2.cxx |   19 ---
 sot/source/base/exchange.cxx  |2 +-
 3 files changed, 1 insertion(+), 40 deletions(-)

New commits:
commit 846bcc5adb82b601937681da7cec96c40253c2e7
Author: Tor Lillqvist 
AuthorDate: Thu Jan 14 22:18:20 2021 +0200
Commit: Tor Lillqvist 
CommitDate: Fri Jan 15 08:48:20 2021 +0100

OUString::matchAsciiL() can be used instead of the fresh startsWithAsciiL()

Revert the addition of the latter.

Change-Id: I93636a901cde401b0b7d923e052887f57dd58212
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109315
Tested-by: Jenkins
Reviewed-by: Tor Lillqvist 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 3a7f8bd5654f..ee3cfe170555 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -1419,26 +1419,6 @@ public:
 return b;
 }
 
-/**
-  Check whether this string starts with a given ASCII string.
-
-  @param asciiStr a sequence of at least asciiStrLength ASCII characters
-  (bytes in the range 0x00--0x7F)
-  @param asciiStrLength the length of asciiStr; must be non-negative
-  @return true if this string starts with asciiStr; otherwise, false is
-  returned
-
-  @since LibreOffice 7.2
- */
-bool startsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
-const
-{
-return asciiStrLength <= pData->length
-&& rtl_ustr_asciil_reverseEquals_WithLength(
-pData->buffer, asciiStr,
-asciiStrLength);
-}
-
 /**
   Check whether this string starts with a given string, ignoring the case 
of
   ASCII letters.
diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx 
b/sal/qa/rtl/oustring/rtl_OUString2.cxx
index d2223511f92a..516378dc14a7 100644
--- a/sal/qa/rtl/oustring/rtl_OUString2.cxx
+++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx
@@ -881,24 +881,6 @@ void indexOfAscii::test() {
 sal_Int32(3), OUString("foofoobar").indexOf("foo", 1));
 }
 
-class startsWithAsciiL: public CppUnit::TestFixture {
-public:
-void test();
-
-CPPUNIT_TEST_SUITE(startsWithAsciiL);
-CPPUNIT_TEST(test);
-CPPUNIT_TEST_SUITE_END();
-};
-
-void startsWithAsciiL::test() {
-CPPUNIT_ASSERT_EQUAL(true, OUString().startsWithAsciiL("", 0));
-CPPUNIT_ASSERT_EQUAL(false, OUString().startsWithAsciiL("x", 1));
-CPPUNIT_ASSERT_EQUAL(true, OUString("bar").startsWithAsciiL("bar", 3));
-CPPUNIT_ASSERT_EQUAL(false, OUString("bar").startsWithAsciiL("foobar", 6));
-CPPUNIT_ASSERT_EQUAL(true, OUString("foobar").startsWithAsciiL("foo", 3));
-CPPUNIT_ASSERT_EQUAL(false, OUString("FOOBAR").startsWithAsciiL("foo", 3));
-}
-
 class endsWith: public CppUnit::TestFixture {
 public:
 void test();
@@ -1051,7 +1033,6 @@ CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::getToken);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::convertToString);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::construction);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::indexOfAscii);
-CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::startsWithAsciiL);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::endsWith);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::isEmpty);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::createFromCodePoints);
diff --git a/sot/source/base/exchange.cxx b/sot/source/base/exchange.cxx
index 84a2427d334b..d00565d618fd 100644
--- a/sot/source/base/exchange.cxx
+++ b/sot/source/base/exchange.cxx
@@ -442,7 +442,7 @@ SotClipboardFormatId SotExchange::GetFormat( const 
DataFlavor& rFlavor )
 {
 const char* const pFormatMimeType = pFormatArray_Impl[ 
static_cast(i) ].pMimeType;
 const sal_Int32 nFormatMimeTypeLen = rtl_str_getLength( 
pFormatMimeType );
-if( rMimeType.startsWithAsciiL( pFormatMimeType, nFormatMimeTypeLen ) 
&&
+if( rMimeType.matchAsciiL( pFormatMimeType, nFormatMimeTypeLen ) &&
 ( rMimeType.getLength() == nFormatMimeTypeLen ||
   rMimeType[ nFormatMimeTypeLen ] == ';' ) )
 return ( (i == SotClipboardFormatId::STARCHARTDOCUMENT_50)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl sal/qa

2021-01-14 Thread Tor Lillqvist (via logerrit)
 include/rtl/ustring.hxx   |   20 
 sal/qa/rtl/oustring/rtl_OUString2.cxx |   19 +++
 2 files changed, 39 insertions(+)

New commits:
commit 06ecfbe3d236e06f597e5422bfc24a9a76c3f90c
Author: Tor Lillqvist 
AuthorDate: Thu Jan 14 10:59:34 2021 +0200
Commit: Tor Lillqvist 
CommitDate: Thu Jan 14 18:06:58 2021 +0100

Introduce startsWithAsciiL() to match endsWithAsciiL()

Will be used in an upcoming change. Unit test included.

Change-Id: I777a755cab543ea277b84fb5ad021d0b91725764
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109264
Tested-by: Jenkins
Reviewed-by: Tor Lillqvist 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index ee3cfe170555..3a7f8bd5654f 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -1419,6 +1419,26 @@ public:
 return b;
 }
 
+/**
+  Check whether this string starts with a given ASCII string.
+
+  @param asciiStr a sequence of at least asciiStrLength ASCII characters
+  (bytes in the range 0x00--0x7F)
+  @param asciiStrLength the length of asciiStr; must be non-negative
+  @return true if this string starts with asciiStr; otherwise, false is
+  returned
+
+  @since LibreOffice 7.2
+ */
+bool startsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
+const
+{
+return asciiStrLength <= pData->length
+&& rtl_ustr_asciil_reverseEquals_WithLength(
+pData->buffer, asciiStr,
+asciiStrLength);
+}
+
 /**
   Check whether this string starts with a given string, ignoring the case 
of
   ASCII letters.
diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx 
b/sal/qa/rtl/oustring/rtl_OUString2.cxx
index 516378dc14a7..d2223511f92a 100644
--- a/sal/qa/rtl/oustring/rtl_OUString2.cxx
+++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx
@@ -881,6 +881,24 @@ void indexOfAscii::test() {
 sal_Int32(3), OUString("foofoobar").indexOf("foo", 1));
 }
 
+class startsWithAsciiL: public CppUnit::TestFixture {
+public:
+void test();
+
+CPPUNIT_TEST_SUITE(startsWithAsciiL);
+CPPUNIT_TEST(test);
+CPPUNIT_TEST_SUITE_END();
+};
+
+void startsWithAsciiL::test() {
+CPPUNIT_ASSERT_EQUAL(true, OUString().startsWithAsciiL("", 0));
+CPPUNIT_ASSERT_EQUAL(false, OUString().startsWithAsciiL("x", 1));
+CPPUNIT_ASSERT_EQUAL(true, OUString("bar").startsWithAsciiL("bar", 3));
+CPPUNIT_ASSERT_EQUAL(false, OUString("bar").startsWithAsciiL("foobar", 6));
+CPPUNIT_ASSERT_EQUAL(true, OUString("foobar").startsWithAsciiL("foo", 3));
+CPPUNIT_ASSERT_EQUAL(false, OUString("FOOBAR").startsWithAsciiL("foo", 3));
+}
+
 class endsWith: public CppUnit::TestFixture {
 public:
 void test();
@@ -1033,6 +1051,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::getToken);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::convertToString);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::construction);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::indexOfAscii);
+CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::startsWithAsciiL);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::endsWith);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::isEmpty);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::createFromCodePoints);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2020-12-28 Thread Stephan Bergmann (via logerrit)
 include/rtl/stringconcat.hxx |8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

New commits:
commit f72a5fd03ddfa94b074b28cf1259284f727139f0
Author: Stephan Bergmann 
AuthorDate: Mon Dec 28 16:03:06 2020 +0100
Commit: Stephan Bergmann 
CommitDate: Mon Dec 28 21:15:34 2020 +0100

Avoid calling memcpy with nullptr

...which can easily happen when default-constructed std::[u16]string_view 
are
involved

Change-Id: I2b11b3943ccaa5344cf9d1f4546d756bc4a2d10f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108414
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx
index e2cba5d86f0d..7f55d6c3473d 100644
--- a/include/rtl/stringconcat.hxx
+++ b/include/rtl/stringconcat.hxx
@@ -74,14 +74,18 @@ struct ToStringHelper
 inline
 char* addDataHelper( char* buffer, const char* data, std::size_t length )
 {
-memcpy( buffer, data, length );
+if (length != 0) {
+memcpy( buffer, data, length );
+}
 return buffer + length;
 }
 
 inline
 sal_Unicode* addDataHelper( sal_Unicode* buffer, const sal_Unicode* data, 
std::size_t length )
 {
-memcpy( buffer, data, length * sizeof( sal_Unicode ));
+if (length != 0) {
+memcpy( buffer, data, length * sizeof( sal_Unicode ));
+}
 return buffer + length;
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl include/sal

2020-12-23 Thread Mike Kaganski (via logerrit)
 include/rtl/character.hxx |   74 --
 include/sal/types.h   |   13 
 2 files changed, 53 insertions(+), 34 deletions(-)

New commits:
commit a385c5c568fbbb56750f68afed16b26b6828b5d4
Author: Mike Kaganski 
AuthorDate: Tue Dec 22 21:37:35 2020 +0300
Commit: Mike Kaganski 
CommitDate: Wed Dec 23 09:28:57 2020 +0100

Make functions in rtl/character.hxx constexpr for internal use

Allows to use them in compile-time initializers.

Change-Id: Ifa4b8da5db6ad7b1d7c87cb2476f4c59abeb32d1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108219
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/rtl/character.hxx b/include/rtl/character.hxx
index 4bab490441ef..9ba9f7a11a58 100644
--- a/include/rtl/character.hxx
+++ b/include/rtl/character.hxx
@@ -37,7 +37,7 @@ namespace rtl
 
 @since LibreOffice 5.2
 */
-inline bool isUnicodeCodePoint(sal_uInt32 code) { return code <= 0x10; }
+inline SAL_CONSTEXPR bool isUnicodeCodePoint(sal_uInt32 code) { return code <= 
0x10; }
 
 /** Check for ASCII character.
 
@@ -47,7 +47,7 @@ inline bool isUnicodeCodePoint(sal_uInt32 code) { return code 
<= 0x10; }
 
 @since LibreOffice 4.1
  */
-inline bool isAscii(sal_uInt32 code)
+inline SAL_CONSTEXPR bool isAscii(sal_uInt32 code)
 {
 assert(isUnicodeCodePoint(code));
 return code <= 0x7F;
@@ -56,7 +56,7 @@ inline bool isAscii(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAscii(char) = delete;
 bool isAscii(signed char) = delete;
-template  inline bool isAscii(T code) { return 
isAscii(sal_uInt32(code)); }
+template  inline constexpr bool isAscii(T code) { return 
isAscii(sal_uInt32(code)); }
 #endif
 
 /** Check for ASCII lower case character.
@@ -68,7 +68,7 @@ template  inline bool isAscii(T code) { return 
isAscii(sal_uInt32(co
 
 @since LibreOffice 4.1
  */
-inline bool isAsciiLowerCase(sal_uInt32 code)
+inline SAL_CONSTEXPR bool isAsciiLowerCase(sal_uInt32 code)
 {
 assert(isUnicodeCodePoint(code));
 return code >= 'a' && code <= 'z';
@@ -77,7 +77,7 @@ inline bool isAsciiLowerCase(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiLowerCase(char) = delete;
 bool isAsciiLowerCase(signed char) = delete;
-template  inline bool isAsciiLowerCase(T code)
+template  inline constexpr bool isAsciiLowerCase(T code)
 {
 return isAsciiLowerCase(sal_uInt32(code));
 }
@@ -92,7 +92,7 @@ template  inline bool isAsciiLowerCase(T code)
 
 @since LibreOffice 4.1
  */
-inline bool isAsciiUpperCase(sal_uInt32 code)
+inline SAL_CONSTEXPR bool isAsciiUpperCase(sal_uInt32 code)
 {
 assert(isUnicodeCodePoint(code));
 return code >= 'A' && code <= 'Z';
@@ -101,7 +101,7 @@ inline bool isAsciiUpperCase(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiUpperCase(char) = delete;
 bool isAsciiUpperCase(signed char) = delete;
-template  inline bool isAsciiUpperCase(T code)
+template  inline constexpr bool isAsciiUpperCase(T code)
 {
 return isAsciiUpperCase(sal_uInt32(code));
 }
@@ -116,7 +116,7 @@ template  inline bool isAsciiUpperCase(T code)
 
 @since LibreOffice 4.1
  */
-inline bool isAsciiAlpha(sal_uInt32 code)
+inline SAL_CONSTEXPR bool isAsciiAlpha(sal_uInt32 code)
 {
 assert(isUnicodeCodePoint(code));
 return isAsciiLowerCase(code) || isAsciiUpperCase(code);
@@ -125,7 +125,10 @@ inline bool isAsciiAlpha(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiAlpha(char) = delete;
 bool isAsciiAlpha(signed char) = delete;
-template  inline bool isAsciiAlpha(T code) { return 
isAsciiAlpha(sal_uInt32(code)); }
+template  inline constexpr bool isAsciiAlpha(T code)
+{
+return isAsciiAlpha(sal_uInt32(code));
+}
 #endif
 
 /** Check for ASCII digit character.
@@ -137,7 +140,7 @@ template  inline bool isAsciiAlpha(T code) { 
return isAsciiAlpha(sal
 
 @since LibreOffice 4.1
  */
-inline bool isAsciiDigit(sal_uInt32 code)
+inline SAL_CONSTEXPR bool isAsciiDigit(sal_uInt32 code)
 {
 assert(isUnicodeCodePoint(code));
 return code >= '0' && code <= '9';
@@ -146,7 +149,10 @@ inline bool isAsciiDigit(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiDigit(char) = delete;
 bool isAsciiDigit(signed char) = delete;
-template  inline bool isAsciiDigit(T code) { return 
isAsciiDigit(sal_uInt32(code)); }
+template  inline constexpr bool isAsciiDigit(T code)
+{
+return isAsciiDigit(sal_uInt32(code));
+}
 #endif
 
 /** Check for ASCII alphanumeric character.
@@ -158,7 +164,7 @@ template  inline bool isAsciiDigit(T code) { 
return isAsciiDigit(sal
 
 @since LibreOffice 4.1
  */
-inline bool isAsciiAlphanumeric(sal_uInt32 code)
+inline SAL_CONSTEXPR bool isAsciiAlphanumeric(sal_uInt32 code)
 {
 assert(isUnicodeCodePoint(code));
 return isAsciiDigit(code) || isAsciiAlpha(code);
@@ -167,7 +173,7 @@ inline bool isAsciiAlphanumeric(sal_uInt32 code)
 #if defined LIBO_INTERNAL_ONLY
 bool isAsciiAlphanumeric(char) = 

[Libreoffice-commits] core.git: include/rtl

2020-12-20 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 31cd6fd0f3c856a81a03d0229de1c4d10442844f
Author: Stephan Bergmann 
AuthorDate: Sun Dec 20 19:27:52 2020 +0100
Commit: Stephan Bergmann 
CommitDate: Sun Dec 20 21:28:23 2020 +0100

Make OStringLiteral ctor non-explicit

a5bdf3c606b562a2af3dd4e4162b734abb1cb24c "Make O[U]StringLiteral ctor 
explicit"
made both the OStringLiteral and the OUStringLiteral ctor explicit, and
87707670c993794ab12b0fad0f048f11429269c2 "Make OUStringLiteral more useful" 
made
(only) the OUStringLiteral ctor non-explicit again.  There appears to be no 
good
reason to keep the OStringLiteral ctor explict, and the current sitation 
lead to

  OUStringLiteral v = u"...";

being valid while

  OStringLiteral v = "...";

was not (and needed to be written as

  OStringLieral v("...");

instead).

Change-Id: Ide26917efabb6eca31c19f64652ee87460e6dd1a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108056
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index e5e7f5716b74..4b4c683d4b6d 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -89,7 +89,7 @@ public:
 #else
 constexpr
 #endif
-explicit OStringLiteral(char const ()[N]) {
+OStringLiteral(char const ()[N]) {
 assertLayout();
 assert(literal[N - 1] == '\0');
 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl sal/qa

2020-12-20 Thread Stephan Bergmann (via logerrit)
 include/rtl/ustring.hxx   |   86 --
 sal/qa/rtl/strings/test_strings_defaultstringview.cxx |   18 +--
 2 files changed, 9 insertions(+), 95 deletions(-)

New commits:
commit 22f7411ecfe0ecc2a62bbc85a6ed27977df03e89
Author: Stephan Bergmann 
AuthorDate: Sun Dec 20 10:50:26 2020 +0100
Commit: Stephan Bergmann 
CommitDate: Sun Dec 20 14:26:49 2020 +0100

Remove the OUString vs. std::u16string_view comparison operators again

...that were introduced in e6dfaf9f44f9939abc338c83b3024108431d0f69 "Turn
OUStringLiteral into a consteval'ed, static-refcound rtl_uString" to avoid
ambiguities, but which is no longer an issue since
46c5de832868d2812448b2caace3eeaa9237b9f6 "make *String(string_view) 
constructors
explicit"

Change-Id: I0a7a3fe23412f77fa85fb7e90f04e22f9abd9230
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108044
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 270eedd2c32d..ee3cfe170555 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -1950,92 +1950,6 @@ public:
 /// @endcond
 #endif
 
-#if defined LIBO_INTERNAL_ONLY
-friend bool operator ==(OUString const & lhs, std::u16string_view rhs) {
-return
-rtl_ustr_reverseCompare_WithLength(
-lhs.pData->buffer, lhs.pData->length, rhs.data(), rhs.size())
-== 0;
-}
-
-friend bool operator !=(OUString const & lhs, std::u16string_view rhs) {
-return
-rtl_ustr_reverseCompare_WithLength(
-lhs.pData->buffer, lhs.pData->length, rhs.data(), rhs.size())
-!= 0;
-}
-
-friend bool operator <(OUString const & lhs, std::u16string_view rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.pData->buffer, lhs.pData->length, rhs.data(), rhs.size()))
-< 0;
-}
-
-friend bool operator <=(OUString const & lhs, std::u16string_view rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.pData->buffer, lhs.pData->length, rhs.data(), rhs.size()))
-<= 0;
-}
-
-friend bool operator >(OUString const & lhs, std::u16string_view rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.pData->buffer, lhs.pData->length, rhs.data(), rhs.size()))
-> 0;
-}
-
-friend bool operator >=(OUString const & lhs, std::u16string_view rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.pData->buffer, lhs.pData->length, rhs.data(), rhs.size()))
->= 0;
-}
-
-friend bool operator ==(std::u16string_view lhs, OUString const & rhs) {
-return
-rtl_ustr_reverseCompare_WithLength(
-lhs.data(), lhs.size(), rhs.pData->buffer, rhs.pData->length)
-== 0;
-}
-
-friend bool operator !=(std::u16string_view lhs, OUString const & rhs) {
-return
-rtl_ustr_reverseCompare_WithLength(
-lhs.data(), lhs.size(), rhs.pData->buffer, rhs.pData->length)
-!= 0;
-}
-
-friend bool operator <(std::u16string_view lhs, OUString const & rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.data(), lhs.size(), rhs.pData->buffer, rhs.pData->length))
-< 0;
-}
-
-friend bool operator <=(std::u16string_view lhs, OUString const & rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.data(), lhs.size(), rhs.pData->buffer, rhs.pData->length))
-<= 0;
-}
-
-friend bool operator >(std::u16string_view lhs, OUString const & rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.data(), lhs.size(), rhs.pData->buffer, rhs.pData->length))
-> 0;
-}
-
-friend bool operator >=(std::u16string_view lhs, OUString const & rhs) {
-return
-(rtl_ustr_compare_WithLength(
-lhs.data(), lhs.size(), rhs.pData->buffer, rhs.pData->length))
->= 0;
-}
-#endif
-
 /**
   Returns a hashcode for this string.
 
diff --git a/sal/qa/rtl/strings/test_strings_defaultstringview.cxx 
b/sal/qa/rtl/strings/test_strings_defaultstringview.cxx
index a16e5d49..591688b31c3c 100644
--- a/sal/qa/rtl/strings/test_strings_defaultstringview.cxx
+++ b/sal/qa/rtl/strings/test_strings_defaultstringview.cxx
@@ -52,19 +52,19 @@ class Test : public CppUnit::TestFixture
  
OUString("foo").startsWithIgnoreAsciiCase(std::u16string_view()));
 CPPUNIT_ASSERT_EQUAL(true, 
OUString("foo").endsWith(std::u16string_view()));
 CPPUNIT_ASSERT_EQUAL(true, 
OUString("foo").endsWithIgnoreAsciiCase(std::u16string_view()));
-OUString const foo("foo"); // avoid loplugin:stringconstant
+OUString const foo("foo"); // avoid 

[Libreoffice-commits] core.git: include/rtl

2020-12-18 Thread Noel (via logerrit)
 include/rtl/strbuf.hxx |   10 ++
 1 file changed, 10 insertions(+)

New commits:
commit ccb3fed37d849a88c74594c44f2aec68c808a33f
Author: Noel 
AuthorDate: Fri Dec 18 11:20:01 2020 +0200
Commit: Noel Grandin 
CommitDate: Fri Dec 18 11:50:55 2020 +0100

add OStringBuffer::append(std::string_view)

so we don't need to construct an OString when appending from a view

Change-Id: I8105d916b43215e312857e9d9d00a38c3d833861
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107938
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 074d1278ea86..2f2df8624f25 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -30,6 +30,7 @@
 
 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
 #include "rtl/stringconcat.hxx"
+#include 
 #endif
 
 #ifdef RTL_STRING_UNITTEST
@@ -585,6 +586,15 @@ public:
 return append( c.buf, c.length );
 }
 
+/**
+ @overload
+ @internal
+ */
+OStringBuffer& append( std::string_view s )
+{
+return append( s.data(), s.size() );
+}
+
 #endif
 
 /**
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2020-12-14 Thread Noel (via logerrit)
 include/rtl/strbuf.hxx  |2 +-
 include/rtl/ustrbuf.hxx |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 9ac5ef97aea670631a0dab45abeacb4180eab6d2
Author: Noel 
AuthorDate: Mon Dec 14 12:10:52 2020 +0200
Commit: Noel Grandin 
CommitDate: Mon Dec 14 12:56:34 2020 +0100

remove unnecessary const qualifier from toString

in *StringBuffer

Change-Id: Ifc1a07b2ab47d6853e3e0a39e74741b2e0b488fd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107678
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 83144a74afab..074d1278ea86 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -477,7 +477,7 @@ public:
 Return an OString instance reflecting the current content
 of this OStringBuffer.
  */
-const OString toString() const
+OString toString() const
 {
 return OString(pData->buffer, pData->length);
 }
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 56968def8d71..bd7f77b503b7 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -536,7 +536,7 @@ public:
 Return an OUString instance reflecting the current content
 of this OUStringBuffer.
  */
-const OUString toString() const
+OUString toString() const
 {
 return OUString(pData->buffer, pData->length);
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl vcl/source writerfilter/source

2020-12-10 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx   |6 ++
 vcl/source/filter/ipdf/pdfread.cxx   |4 ++--
 writerfilter/source/rtftok/rtfdispatchsymbol.cxx |2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)

New commits:
commit 9df9208b7d0fd9dd49c681c3c1b546d8ca402925
Author: Stephan Bergmann 
AuthorDate: Thu Dec 10 15:15:40 2020 +0100
Commit: Stephan Bergmann 
CommitDate: Thu Dec 10 22:21:23 2020 +0100

Catch inadvertent uses of OString(char) ctor

...similar to cbe944e323edb20f958bb46ea644de659b75382e "Catch inadvertent 
uses
of OUString(sal_Unicode) ctor".  The existing few places did mean to use 
that
ctor after all, but this clean-up should come in handy when single-character
instances of OString are replaced with OStringChar, which already rejects 
non-
char arguments.

Change-Id: I9dbd85b85c3be653c5e8084aed39689f8c6c3bb8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107557
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 4d229fd86931..3c540198f95f 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -243,6 +243,12 @@ public:
 rtl_string_newFromStr_WithLength( , , 1 );
 }
 
+#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
+// Catch inadvertent conversions to the above ctor (e.g., from 
sal_[u]Int8, aka [un]signed
+// char):
+OString(int) = delete;
+#endif
+
 /**
   New string from a character buffer array.
 
diff --git a/vcl/source/filter/ipdf/pdfread.cxx 
b/vcl/source/filter/ipdf/pdfread.cxx
index a36eacbfd41a..ef5d799fe4ee 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -54,8 +54,8 @@ bool isCompatible(SvStream& rInStream, sal_uInt64 nPos, 
sal_uInt64 nSize)
 || aFirstBytes[3] != 'F' || aFirstBytes[4] != '-')
 return false;
 
-sal_Int32 nMajor = OString(aFirstBytes[5]).toInt32();
-sal_Int32 nMinor = OString(aFirstBytes[7]).toInt32();
+sal_Int32 nMajor = OString(char(aFirstBytes[5])).toInt32();
+sal_Int32 nMinor = OString(char(aFirstBytes[7])).toInt32();
 return !(nMajor > 1 || (nMajor == 1 && nMinor > 6));
 }
 
diff --git a/writerfilter/source/rtftok/rtfdispatchsymbol.cxx 
b/writerfilter/source/rtftok/rtfdispatchsymbol.cxx
index ff13dedcf5fa..418498f98df3 100644
--- a/writerfilter/source/rtftok/rtfdispatchsymbol.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchsymbol.cxx
@@ -80,7 +80,7 @@ RTFError RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
 }
 if (cCh > 0)
 {
-OUString aStr(OStringToOUString(OString(cCh), 
RTL_TEXTENCODING_MS_1252));
+OUString aStr(OStringToOUString(OString(char(cCh)), 
RTL_TEXTENCODING_MS_1252));
 text(aStr);
 return RTFError::OK;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl sal/CppunitTest_sal_rtl.mk sal/qa sal/rtl

2020-11-21 Thread Stephan Bergmann (via logerrit)
 include/rtl/ustring.h |   16 +-
 sal/CppunitTest_sal_rtl.mk|1 
 sal/qa/rtl/strings/test_strings_defaultstringview.cxx |  118 ++
 sal/rtl/strtmpl.cxx   |   10 +
 sal/rtl/ustring.cxx   |   27 ++--
 5 files changed, 151 insertions(+), 21 deletions(-)

New commits:
commit 142e8ccd3aa14a347f44bd09fa1020b097298140
Author: Stephan Bergmann 
AuthorDate: Fri Nov 20 18:26:43 2020 +0100
Commit: Stephan Bergmann 
CommitDate: Sat Nov 21 13:32:21 2020 +0100

Relax non-null requirement for some rtl_uString_* functions

...that take a pointer and a length, and where it should be OK that the 
pointer
is null if the length is zero.  Those rtl_uString_* functions are targets of
OUString member functions that take std::[u16]string_view arguments, and
19926ed35ebb623fc896942b1f232b83edf1fc1e "loplugin:stringview: Flag empty 
string
converted to string view" (which changed some call sites to pass in default-
constructed std::[u16]string_view, for which data() returns null) revealed 
that
those rtl_uString_* functions were not prepared for such input.

(The guardings of memcpy are necessary because memcpy still requires its 
pointer
arguments to be non-null, even if the corresponding length is zero.)

The new sal/qa/rtl/strings/test_strings_defaultstringview.cxx systematically
tests all O[U]String[Buffer] member functions taking std::[u16]string_view
arguments.  It revealed one further issue in
IMPL_RTL_STRNAME(compare_WithLength), where UBSan reported a
nullptr-with-nonzero-offset

> sal/rtl/strtmpl.cxx:149:9: runtime error: applying non-zero offset 
18446744073709551614 to null pointer

Also, rtl_uString_newReplaceFirstUtf16LUtf16L was found to lack a check for 
its
`from` argument to be non-null.

Change-Id: I6a7a712570f7d1e8d52097208c8a43a5a24797af
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106295
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h
index abd33bb77f15..9e61df974618 100644
--- a/include/rtl/ustring.h
+++ b/include/rtl/ustring.h
@@ -1495,8 +1495,8 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_newConcatAsciiL(
 
 @param left a valid string.
 
-@param right must not be null and must point to memory of at least
-\p rightLength UTF-16 code units
+@param right must point to memory of at least \p rightLength UTF-16 code 
units; may be null if
+\p rigthLength is zero
 
 @param rightLength the length of the \p right string; must be non-negative
 
@@ -1763,13 +1763,13 @@ SAL_DLLPUBLIC void SAL_CALL 
rtl_uString_newReplaceFirstUtf16LAsciiL(
 
 @param str  pointer to the original string; must not be null
 
-@param from  pointer to the substring to be replaced; must not be null and
-must point to memory of at least \p fromLength UTF-16 code units
+@param from  pointer to the substring to be replaced; must point to memory 
of at least
+\p fromLength UTF-16 code units; may be null if \p toLength is zero
 
 @param fromLength  the length of the \p from substring; must be 
non-negative
 
-@param to  pointer to the substring to be replaced; must not be null and
-must point to memory of at least \p toLength UTF-16 code units
+@param to  pointer to the substring to be replaced; must point to memory 
of at least \p toLength
+UTF-16 code units; may be null if \p toLength is zero
 
 @param toLength  the length of the \p to substring; must be non-negative
 
@@ -1927,8 +1927,8 @@ SAL_DLLPUBLIC void SAL_CALL 
rtl_uString_newReplaceAllAsciiLAsciiL(
 
 @param fromLength  the length of the \p from substring; must be 
non-negative
 
-@param to  pointer to the substring to be replaced; must not be null and
-must point to memory of at least \p toLength UTF-16 code units
+@param to  pointer to the substring to be replaced; must point to memory 
of at least \p toLength
+UTF-16 code units; may be null if \p toLength is zero
 
 @param toLength  the length of the \p to substring; must be non-negative
 
diff --git a/sal/CppunitTest_sal_rtl.mk b/sal/CppunitTest_sal_rtl.mk
index f559202c54d5..02b6c94e3d1b 100644
--- a/sal/CppunitTest_sal_rtl.mk
+++ b/sal/CppunitTest_sal_rtl.mk
@@ -31,6 +31,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sal_rtl,\
sal/qa/rtl/ref/rtl_ref \
sal/qa/rtl/strings/nonconstarray \
sal/qa/rtl/strings/test_strings_replace \
+   sal/qa/rtl/strings/test_strings_defaultstringview \
sal/qa/rtl/strings/test_ostring \
sal/qa/rtl/strings/test_ostring_concat \
sal/qa/rtl/strings/test_ostring_stringliterals \
diff --git a/sal/qa/rtl/strings/test_strings_defaultstringview.cxx 
b/sal/qa/rtl/strings/test_strings_defaultstringview.cxx
new file mode 100644
index 

[Libreoffice-commits] core.git: include/rtl

2020-09-22 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx  |   14 ++
 include/rtl/ustring.hxx |   13 +
 2 files changed, 11 insertions(+), 16 deletions(-)

New commits:
commit 43003173fb457616c4396592c75afc653dc0ab0c
Author: Stephan Bergmann 
AuthorDate: Tue Sep 22 09:26:09 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Tue Sep 22 16:21:10 2020 +0200

Simplify those assertLayout checks

...recently introduced with 52a49f9e480ca03e231cfda82640a928393131c9
"static_assert that O[U]StringLiteral are layout compatible with 
rtl_[u]String"

Change-Id: Ie89e92aa4230329aa582c4211c2001117d2287b5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103138
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index fd65e2dfa477..d9422c696059 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -90,6 +90,7 @@ public:
 constexpr
 #endif
 explicit OStringLiteral(char const ()[N]) {
+assertLayout();
 assert(literal[N - 1] == '\0');
 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
 for (std::size_t i = 0; i != N; ++i) {
@@ -104,6 +105,7 @@ public:
 constexpr
 #endif
 explicit OStringLiteral(char8_t const ()[N]) {
+assertLayout();
 assert(literal[N - 1] == '\0');
 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
 for (std::size_t i = 0; i != N; ++i) {
@@ -116,10 +118,10 @@ public:
 
 constexpr char const * getStr() const SAL_RETURNS_NONNULL { return buffer; 
}
 
-// offsetof needs a complete type, so do not have these static_asserts as 
class template
-// members, but postpone their instantiation to the later non-member 
static_assert that calls
-// detail_assertLayout:
-static constexpr bool detail_assertLayout() {
+private:
+static constexpr void assertLayout() {
+// These static_asserts verifying the layout compatibility with 
rtl_String cannot be class
+// member declarations, as offsetof requires a complete type, so defer 
them to here:
 static_assert(offsetof(OStringLiteral, refCount) == 
offsetof(rtl_String, refCount));
 static_assert(
 std::is_same_v);
@@ -130,17 +132,13 @@ public:
 std::is_same_v<
 std::remove_extent_t,
 std::remove_extent_t>);
-return true;
 }
 
-private:
 // Same layout as rtl_String (include/rtl/string.h):
 oslInterlockedCount refCount = 0x4000; // SAL_STRING_STATIC_FLAG 
(sal/rtl/strimp.hxx)
 sal_Int32 length = N - 1;
 char buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2)
 };
-
-static_assert(OStringLiteral<1>::detail_assertLayout());
 #endif
 
 /* === */
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index f458ac061ea4..707bbf6e66d6 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -87,6 +87,7 @@ public:
 constexpr
 #endif
 OUStringLiteral(char16_t const ()[N]) {
+assertLayout();
 assert(literal[N - 1] == '\0');
 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
 for (std::size_t i = 0; i != N; ++i) {
@@ -100,10 +101,10 @@ public:
 
 constexpr operator std::u16string_view() const { return {buffer, 
sal_uInt32(length)}; }
 
-// offsetof needs a complete type, so do not have these static_asserts as 
class template
-// members, but postpone their instantiation to the later non-member 
static_assert that calls
-// detail_assertLayout:
-static constexpr bool detail_assertLayout() {
+private:
+static constexpr void assertLayout() {
+// These static_asserts verifying the layout compatibility with 
rtl_uString cannot be class
+// member declarations, as offsetof requires a complete type, so defer 
them to here:
 static_assert(offsetof(OUStringLiteral, refCount) == 
offsetof(rtl_uString, refCount));
 static_assert(std::is_same_v);
 static_assert(offsetof(OUStringLiteral, length) == 
offsetof(rtl_uString, length));
@@ -113,18 +114,14 @@ public:
 std::is_same_v<
 std::remove_extent_t,
 std::remove_extent_t>);
-return true;
 }
 
-private:
 // Same layout as rtl_uString (include/rtl/ustring.h):
 oslInterlockedCount refCount = 0x4000; // SAL_STRING_STATIC_FLAG 
(sal/rtl/strimp.hxx)
 sal_Int32 length = N - 1;
 sal_Unicode buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2)
 };
 
-static_assert(OUStringLiteral<1>::detail_assertLayout());
-
 #if defined RTL_STRING_UNITTEST
 namespace libreoffice_internal {
 template struct 
ExceptConstCharArrayDetector> {};
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2020-09-21 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit e79a6a5270d190d6e89a6acf08e22419386d2117
Author: Stephan Bergmann 
AuthorDate: Mon Sep 21 20:48:56 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Mon Sep 21 22:15:56 2020 +0200

No need to make the OString(std::string_view) ctor explicit


"Make std::u16string_view -> OUString construction explicit" (which has
meanwhile been abandoned) had intended to make the 
OUString(std::u16string_view)
ctor explicit, mostly not for the rationale given in the commit message 
there
(it being "a rather expensive operation"), but rather to avoid anticipated
ambiguity issues when introducing e6dfaf9f44f9939abc338c83b3024108431d0f69 
"Turn
OUStringLiteral into a consteval'ed, static-refcound rtl_uString"---but 
which
has ultimately been added in a form that did not give rise to such ambiguity
issues after all.

4b9e440c51be3e40326bc90c33ae69885bfb51e4 "Turn OStringLiteral into a
consteval'ed, static-refcound rtl_String" had added the
OString(std::string_view) ctor as explicit to match the corresponding 
explicit
OUString(std::u16string_view) from the above
.  But as that has now been
abandoned, there is no good reason to keep this ctor explicit, either.

Change-Id: I05742de5f3992ad5995149631bf8d55c8d448387
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103124
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index e59ffba83a62..7086de15c987 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -304,7 +304,7 @@ public:
 #endif
 
 #if defined LIBO_INTERNAL_ONLY
-explicit OString(std::string_view sv) {
+OString(std::string_view sv) {
 if (sv.size() > sal_uInt32(std::numeric_limits::max())) {
 throw std::bad_alloc();
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2020-09-10 Thread Caolán McNamara (via logerrit)
 include/rtl/stringutils.hxx |   18 ++
 1 file changed, 18 insertions(+)

New commits:
commit 13cea4e3e6256a65f264e0922a91cf39ea1e9835
Author: Caolán McNamara 
AuthorDate: Wed Sep 9 10:49:41 2020 +0100
Commit: Caolán McNamara 
CommitDate: Thu Sep 10 09:50:15 2020 +0200

cid#1466656 silence Logically dead code

Change-Id: Id49181f71390ff6768ce6bc5734f8166e1a310b7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102293
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 

diff --git a/include/rtl/stringutils.hxx b/include/rtl/stringutils.hxx
index c7abe5e60df6..7a1bc606ff5b 100644
--- a/include/rtl/stringutils.hxx
+++ b/include/rtl/stringutils.hxx
@@ -268,6 +268,24 @@ struct ConstCharArrayDetector {
 sal_Unicode const (& literal)[N])
 { return literal; }
 };
+
+#if defined(__COVERITY__)
+//to silence over zealous warnings that the loop is logically dead
+//for the single char case
+template
+struct ConstCharArrayDetector {
+using TypeUtf16 = T;
+static constexpr bool const ok = true;
+static constexpr std::size_t const length = 0;
+static constexpr bool isValid(sal_Unicode const (& literal)[1]) {
+return literal[0] == '\0';
+}
+static constexpr sal_Unicode const * toPointer(
+sal_Unicode const (& literal)[1])
+{ return literal; }
+};
+#endif
+
 template struct ConstCharArrayDetector<
 OUStringChar,
 T>
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2020-09-07 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx |1 +
 1 file changed, 1 insertion(+)

New commits:
commit 0cf956017477ad4f6aaae413eb434ab9b870725d
Author: Stephan Bergmann 
AuthorDate: Mon Sep 7 15:10:56 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Mon Sep 7 16:58:51 2020 +0200

Avoid dangling pData when constructing OUString from temporary 
OUStringLiteral

...afer 4b9e440c51be3e40326bc90c33ae69885bfb51e4 "Turn OStringLiteral into a
consteval'ed, static-refcound rtl_String"

Change-Id: I8afab29e9b7477c8a6c519b61d1fd6b3c21589e2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102174
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index ca1fd99b7fba..3a95b807c3a0 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -299,6 +299,7 @@ public:
 */
 template OString(OStringLiteral const & literal):
 pData(const_cast(reinterpret_cast())) {}
+template OString(OStringLiteral &&) = delete;
 /// @endcond
 #endif
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2020-09-05 Thread Andrea Gelmini (via logerrit)
 include/rtl/ustring.h |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit d1708ea5ef42daea49368d159324a4ba11256e55
Author: Andrea Gelmini 
AuthorDate: Fri Sep 4 12:03:48 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Sat Sep 5 16:00:21 2020 +0200

Fix typo in code

Change-Id: I2934b96c8b2b0a9049d7f238b9c67c8ecf56fa38
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102035
Reviewed-by: Julien Nabet 
Tested-by: Jenkins

diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h
index 6bf0d2aef0eb..1595cdf4f3ab 100644
--- a/include/rtl/ustring.h
+++ b/include/rtl/ustring.h
@@ -2032,7 +2032,7 @@ SAL_DLLPUBLIC void SAL_CALL 
rtl_uString_newReplaceAllUtf16LUtf16L(
 */
 SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceAllFromIndexUtf16LUtf16L(
 rtl_uString ** newStr, rtl_uString * str, sal_Unicode const * from,
-sal_Int32 fromLength, sal_Unicode const * to, sal_Int32 toLengt, sal_Int32 
fromIndex)
+sal_Int32 fromLength, sal_Unicode const * to, sal_Int32 toLength, 
sal_Int32 fromIndex)
 SAL_THROW_EXTERN_C();
 #endif
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl sal/CppunitTest_sal_rtl.mk sal/qa sw/source

2020-09-05 Thread Stephan Bergmann (via logerrit)
 include/rtl/stringutils.hxx |   11 +-
 include/rtl/ustring.hxx |2 
 sal/CppunitTest_sal_rtl.mk  |1 
 sal/qa/rtl/strings/nonconstarray.cxx|   94 
 sal/qa/rtl/strings/test_oustring_stringliterals.cxx |2 
 sw/source/filter/ww8/ww8par.cxx |8 +
 6 files changed, 112 insertions(+), 6 deletions(-)

New commits:
commit 9abaa6492899b3a8e467b08ec8a084ed3db7f518
Author: Stephan Bergmann 
AuthorDate: Fri Sep 4 20:26:58 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Sat Sep 5 12:29:10 2020 +0200

Make OUString(char16_t const[N]) ctor check for embedded NULs

...and fix the detected fallout.

That ctor only started to get used recently with
a1570b6052ae9c9349282027c9007b071589bce6 "Make the OUString
ConstCharArrayDetector::TypeUtf16 overloads are actually used", but it 
turns out
that that also gave rise to that ctor being picked in error.  To better 
guard
against such erroneous uses, make that ctor assert that the given array 
does not
contain embedded NUL characters, see the new
sal/qa/rtl/strings/nonconstarray.cxx tests.

The one place where that assert would fire during `make check` is fixed now 
in
SwWW8ImplReader::ImportDopTypography.

That assert would also fire for tow OUStringLiteral-related tests in the
recently added test::oustring::StringLiterals::checkEmbeddedNul, so drop 
those
for how.  They cna presumably be added back (with reversed logic values) 
when
OUStringLiteral is changed similarly to how OStringLiteral was changed in
4b9e440c51be3e40326bc90c33ae69885bfb51e4 "Turn OStringLiteral into a
consteval'ed, static-refcound rtl_String".

Change-Id: I6056244003a20f77ba0d953538d25edcbd562211
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102063
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/stringutils.hxx b/include/rtl/stringutils.hxx
index 2a6f841ecaed..c7abe5e60df6 100644
--- a/include/rtl/stringutils.hxx
+++ b/include/rtl/stringutils.hxx
@@ -256,8 +256,14 @@ struct ConstCharArrayDetector {
 using TypeUtf16 = T;
 static constexpr bool const ok = true;
 static constexpr std::size_t const length = N - 1;
-static constexpr bool isValid(sal_Unicode const (& literal)[N])
-{ return literal[N - 1] == '\0'; }
+static constexpr bool isValid(sal_Unicode const (& literal)[N]) {
+for (std::size_t i = 0; i != N - 1; ++i) {
+if (literal[i] == '\0') {
+return false;
+}
+}
+return literal[N - 1] == '\0';
+}
 static constexpr sal_Unicode const * toPointer(
 sal_Unicode const (& literal)[N])
 { return literal; }
@@ -269,6 +275,7 @@ template struct ConstCharArrayDetector<
 using TypeUtf16 = T;
 static constexpr bool const ok = true;
 static constexpr std::size_t const length = 1;
+static constexpr bool isValid(OUStringChar) { return true; }
 static constexpr sal_Unicode const * toPointer(
 OUStringChar_ const & literal)
 { return  }
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index d53eab6c3038..cba3c47f5155 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -301,6 +301,8 @@ public:
 = libreoffice_internal::Dummy()):
 pData(nullptr)
 {
+assert(
+libreoffice_internal::ConstCharArrayDetector::isValid(literal));
 if (libreoffice_internal::ConstCharArrayDetector::length == 0) {
 rtl_uString_new();
 } else {
diff --git a/sal/CppunitTest_sal_rtl.mk b/sal/CppunitTest_sal_rtl.mk
index c2eaa72daa26..f559202c54d5 100644
--- a/sal/CppunitTest_sal_rtl.mk
+++ b/sal/CppunitTest_sal_rtl.mk
@@ -29,6 +29,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sal_rtl,\
sal/qa/rtl/process/rtl_Process \
sal/qa/rtl/random/rtl_random \
sal/qa/rtl/ref/rtl_ref \
+   sal/qa/rtl/strings/nonconstarray \
sal/qa/rtl/strings/test_strings_replace \
sal/qa/rtl/strings/test_ostring \
sal/qa/rtl/strings/test_ostring_concat \
diff --git a/sal/qa/rtl/strings/nonconstarray.cxx 
b/sal/qa/rtl/strings/nonconstarray.cxx
new file mode 100644
index ..4b66e4e311c3
--- /dev/null
+++ b/sal/qa/rtl/strings/nonconstarray.cxx
@@ -0,0 +1,94 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * 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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace
+{
+class Test : public CppUnit::TestFixture
+{
+private:
+void testOString()

[Libreoffice-commits] core.git: include/rtl

2020-09-01 Thread Stephan Bergmann (via logerrit)
 include/rtl/ustring.hxx |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

New commits:
commit 464ad36998ee3ec9fc579c5a99134e7b1eb52edc
Author: Stephan Bergmann 
AuthorDate: Mon Aug 31 22:15:05 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Tue Sep 1 09:41:43 2020 +0200

Adapt documentation comment

...to 33ecd0d5c4fff9511a8436513936a3f7044a775a "Change OUStringLiteral from
char[] to char16_t[]"

Change-Id: I661e1b1ce59461f30a9c1d75a1e4acb71fa113f2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101770
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 6c6e92207242..8e7a61f79005 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -343,8 +343,7 @@ public:
 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
 /// @cond INTERNAL
 /**
-  New string from an 8-Bit string literal that is expected to contain only
-  characters in the ASCII set (i.e. first 128 characters).
+  New string from a string literal.
 
   This constructor is similar to the "direct template" one, but can be
   useful in cases where the latter does not work, like in
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2020-08-31 Thread Stephan Bergmann (via logerrit)
 include/rtl/string.hxx  |2 +-
 include/rtl/ustring.hxx |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 5fca6fefc9cb47737663fbcd04660d2c5bcfde93
Author: Stephan Bergmann 
AuthorDate: Mon Aug 31 08:30:58 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Mon Aug 31 09:24:45 2020 +0200

Fix typos in comments

...introduced with 2e21240f23ac2191a3535d697a7308b29303c67c "Goodbye
O[U]StringView, welcome O[U]String::Concat".  Thanks to Mike for spotting 
them!

Change-Id: Ic401c564eac03a34184204f09cb8d0cb6be4e6e5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101689
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 60485fbdfb96..da75e5eee57c 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -1909,7 +1909,7 @@ public:
 // concatenation chain, when neither of the first two e1, e2 is one of our 
rtl string-related
 // classes (so something like
 //
-//   OString s = "a" + (b ? std::string_view("c" : "dd");
+//   OString s = "a" + (b ? std::string_view("c") : 
std::string_view("dd"));
 //
 // would not compile):
 template [[nodiscard]] static
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index b99cf758ed8b..6c6e92207242 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -3701,7 +3701,7 @@ public:
 // concatenation chain, when neither of the first two e1, e2 is one of our 
rtl string-related
 // classes (so something like
 //
-//   OUString s = "a" + (b ? std::u16string_view(u"c" : u"dd");
+//   OUString s = "a" + (b ? std::u16string_view(u"c") : 
std::u16string_view(u"dd"));
 //
 // would not compile):
 template [[nodiscard]] static
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2020-08-26 Thread Stephan Bergmann (via logerrit)
 include/rtl/stringutils.hxx |6 +++---
 include/rtl/ustrbuf.hxx |4 +++-
 include/rtl/ustring.hxx |4 +++-
 3 files changed, 9 insertions(+), 5 deletions(-)

New commits:
commit 4382d36ffd38f2481f83e59fd11ead8d62e08a39
Author: Stephan Bergmann 
AuthorDate: Tue Aug 25 20:52:05 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Aug 26 12:34:15 2020 +0200

Except[Const]CharArrayDetector is only used by RTL_STRING_UNITTEST

...which in turn should be a LIBO_INTERNAL_ONLY feature, so confine all 
relevant
declarations accordingly

Change-Id: I7545eadad6f097d0ee905583b1610631c92f1858
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101373
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/stringutils.hxx b/include/rtl/stringutils.hxx
index b968845465ce..40b03c84f4bb 100644
--- a/include/rtl/stringutils.hxx
+++ b/include/rtl/stringutils.hxx
@@ -272,6 +272,8 @@ template struct ConstCharArrayDetector<
 };
 #endif
 
+#if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
+
 // this one is used to rule out only const char[N]
 template< typename T >
 struct ExceptConstCharArrayDetector
@@ -282,14 +284,12 @@ template< int N >
 struct ExceptConstCharArrayDetector< const char[ N ] >
 {
 };
-#if defined LIBO_INTERNAL_ONLY
 template
 struct ExceptConstCharArrayDetector {};
 template<> struct ExceptConstCharArrayDetector<
 OUStringChar
 >
 {};
-#endif
 
 // this one is used to rule out only const char[N]
 // (const will be brought in by 'const T&' in the function call)
@@ -308,10 +308,10 @@ template< int N >
 struct ExceptCharArrayDetector< const char[ N ] >
 {
 };
-#if defined LIBO_INTERNAL_ONLY
 template struct ExceptCharArrayDetector {};
 template struct ExceptCharArrayDetector 
{};
 template<> struct ExceptCharArrayDetector {};
+
 #endif
 
 template< typename T1, typename T2 = void >
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index dcd228e9eea8..2d957d81064e 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -181,7 +181,8 @@ public:
 }
 #endif
 
-#ifdef RTL_STRING_UNITTEST
+#if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
+/// @cond INTERNAL
 /**
  * Only used by unittests to detect incorrect conversions.
  * @internal
@@ -206,6 +207,7 @@ public:
 rtl_uString_newFromLiteral( , "!!br0ken!!", 10, 0 ); // set to 
garbage
 rtl_string_unittest_invalid_conversion = true;
 }
+/// @endcond
 #endif
 
 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index d86602e9f2e3..d73977192cd0 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -290,7 +290,8 @@ public:
 }
 #endif
 
-#ifdef RTL_STRING_UNITTEST
+#if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
+/// @cond INTERNAL
 /**
  * Only used by unittests to detect incorrect conversions.
  * @internal
@@ -313,6 +314,7 @@ public:
 rtl_uString_newFromLiteral( , "!!br0ken!!", 10, 0 ); // set to 
garbage
 rtl_string_unittest_invalid_conversion = true;
 }
+/// @endcond
 #endif
 
 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2020-08-26 Thread Stephan Bergmann (via logerrit)
 include/rtl/ustring.hxx |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 0f00c7f42403ad037a5c64adf777be7da87732f1
Author: Stephan Bergmann 
AuthorDate: Wed Aug 26 07:15:13 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Aug 26 09:24:39 2020 +0200

Missing 'const'

Apparently typos in 0c8fa58a2d73702770687ed15b98822d09f96ac3 "Support
ConstCharArrayDetector also for UTF-16 arrays" that went unnoticed as for a
const OUString s,

  s == u"..."

could still pick the

  bool operator ==(OUString const &, sal_Unicode const *)

overload.

Change-Id: I61344ef2912fffca3cccf375e2e4c2be9beca604
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101377
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 5f0c1032c603..d86602e9f2e3 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -1827,7 +1827,7 @@ public:
 #if defined LIBO_INTERNAL_ONLY
 /** @overload @since LibreOffice 5.3 */
 template friend typename 
libreoffice_internal::ConstCharArrayDetector::TypeUtf16
-operator ==(OUString & string, T & literal) {
+operator ==(OUString const & string, T & literal) {
 return
 rtl_ustr_reverseCompare_WithLength(
 string.pData->buffer, string.pData->length,
@@ -1838,7 +1838,7 @@ public:
 }
 /** @overload @since LibreOffice 5.3 */
 template friend typename 
libreoffice_internal::ConstCharArrayDetector::TypeUtf16
-operator ==(T & literal, OUString & string) {
+operator ==(T & literal, OUString const & string) {
 return
 rtl_ustr_reverseCompare_WithLength(
 libreoffice_internal::ConstCharArrayDetector::toPointer(
@@ -1849,7 +1849,7 @@ public:
 }
 /** @overload @since LibreOffice 5.3 */
 template friend typename 
libreoffice_internal::ConstCharArrayDetector::TypeUtf16
-operator !=(OUString & string, T & literal) {
+operator !=(OUString const & string, T & literal) {
 return
 rtl_ustr_reverseCompare_WithLength(
 string.pData->buffer, string.pData->length,
@@ -1860,7 +1860,7 @@ public:
 }
 /** @overload @since LibreOffice 5.3 */
 template friend typename 
libreoffice_internal::ConstCharArrayDetector::TypeUtf16
-operator !=(T & literal, OUString & string) {
+operator !=(T & literal, OUString const & string) {
 return
 rtl_ustr_reverseCompare_WithLength(
 libreoffice_internal::ConstCharArrayDetector::toPointer(
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl solenv/gbuild

2020-05-05 Thread Stephan Bergmann (via logerrit)
 include/rtl/strbuf.hxx |8 
 include/rtl/string.hxx |   16 
 include/rtl/ustring.hxx|   16 
 solenv/gbuild/platform/com_GCC_defs.mk |3 +++
 4 files changed, 3 insertions(+), 40 deletions(-)

New commits:
commit 0613619a61c39eff4b7d47d7afdd991658986a72
Author: Stephan Bergmann 
AuthorDate: Tue May 5 14:18:02 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Tue May 5 21:43:12 2020 +0200

Disable -Wstringop-overflow in --enable-optimized builds with GCC

This reverts commit e287fde52fb9de5bdf1d00c8a3fbfcca7db9892c "Silence bogus
-Wstringop-overflow with GCC trunk towards GCC 10", as that workaround, 
which
happened to work for some revisions of GCC trunk towards GCC 10, no longer 
works
for GCC 10 release candidates, see
 "[10 Regression]
Unhelpful -Wstringop-overflow warning for a trailing one-element array".

(Using -Wstringop-overflow=1 instead of the -Wstringop-overflow=2 default 
would
have still caused bogus warnings, requiring -Wno-stringop-overflow.)

Change-Id: I9b7342748c18da32f509b4a0e0653aede8447657
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93499
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index e9a548297016..2a303ce998e6 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -569,15 +569,7 @@ public:
 return *this;
 l += pData->length;
 rtl_stringbuffer_ensureCapacity( , , l );
-#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
-// Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
-//  "Unhelpful 
-Wstringop-overflow
-// warning"):
-struct Hack { char c; char a[]; };
-char* end = c.addData( _cast(pData->buffer)->c + 
pData->length );
-#else
 char* end = c.addData( pData->buffer + pData->length );
-#endif
 *end = '\0';
 pData->length = l;
 return *this;
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 4f600affdabe..809b0a11bcd5 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -273,15 +273,7 @@ public:
 pData = rtl_string_alloc( l );
 if (l != 0)
 {
-#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
-// Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
-//  "Unhelpful 
-Wstringop-overflow
-// warning"):
-struct Hack { char c; char a[]; };
-char* end = c.addData( _cast(pData->buffer)->c 
);
-#else
 char* end = c.addData( pData->buffer );
-#endif
 pData->length = l;
 *end = '\0';
 }
@@ -389,15 +381,7 @@ public:
 return *this;
 l += pData->length;
 rtl_string_ensureCapacity( , l );
-#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
-// Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
-//  "Unhelpful 
-Wstringop-overflow
-// warning"):
-struct Hack { char c; char a[]; };
-char* end = c.addData( _cast(pData->buffer)->c + 
pData->length );
-#else
 char* end = c.addData( pData->buffer + pData->length );
-#endif
 *end = '\0';
 pData->length = l;
 return *this;
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index ffe42d139215..5f0c1032c603 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -401,15 +401,7 @@ public:
 pData = rtl_uString_alloc( l );
 if (l != 0)
 {
-#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
-// Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
-//  "Unhelpful 
-Wstringop-overflow
-// warning"):
-struct Hack { sal_Unicode c; sal_Unicode a[]; };
-sal_Unicode* end = c.addData( reinterpret_cast(pData->buffer - 1)->a );
-#else
 sal_Unicode* end = c.addData( pData->buffer );
-#endif
 pData->length = l;
 *end = '\0';
 // TODO realloc in case pData->length is noticeably smaller than l?
@@ -638,15 +630,7 @@ public:
 return *this;
 l += pData->length;
 rtl_uString_ensureCapacity( , l );
-#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
-// Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
-//  "Unhelpful 
-Wstringop-overflow
-// warning"):
-struct Hack { sal_Unicode c; sal_Unicode a[]; };
-sal_Unicode* end = c.addData( 

[Libreoffice-commits] core.git: include/rtl

2020-04-29 Thread Stephan Bergmann (via logerrit)
 include/rtl/strbuf.hxx  |8 
 include/rtl/string.hxx  |   16 
 include/rtl/ustring.hxx |   16 
 3 files changed, 40 insertions(+)

New commits:
commit e287fde52fb9de5bdf1d00c8a3fbfcca7db9892c
Author: Stephan Bergmann 
AuthorDate: Sun Dec 15 09:23:14 2019 +0100
Commit: Stephan Bergmann 
CommitDate: Wed Apr 29 21:31:27 2020 +0200

Silence bogus -Wstringop-overflow with GCC trunk towards GCC 10

...see  "Unhelpful
-Wstringop-overflow warning"

Change-Id: I14b2e5e19b57df6f57a9252f27ee4b3feb8ba18c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85161
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 2a303ce998e6..e9a548297016 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -569,7 +569,15 @@ public:
 return *this;
 l += pData->length;
 rtl_stringbuffer_ensureCapacity( , , l );
+#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
+// Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
+//  "Unhelpful 
-Wstringop-overflow
+// warning"):
+struct Hack { char c; char a[]; };
+char* end = c.addData( _cast(pData->buffer)->c + 
pData->length );
+#else
 char* end = c.addData( pData->buffer + pData->length );
+#endif
 *end = '\0';
 pData->length = l;
 return *this;
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 809b0a11bcd5..4f600affdabe 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -273,7 +273,15 @@ public:
 pData = rtl_string_alloc( l );
 if (l != 0)
 {
+#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
+// Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
+//  "Unhelpful 
-Wstringop-overflow
+// warning"):
+struct Hack { char c; char a[]; };
+char* end = c.addData( _cast(pData->buffer)->c 
);
+#else
 char* end = c.addData( pData->buffer );
+#endif
 pData->length = l;
 *end = '\0';
 }
@@ -381,7 +389,15 @@ public:
 return *this;
 l += pData->length;
 rtl_string_ensureCapacity( , l );
+#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
+// Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
+//  "Unhelpful 
-Wstringop-overflow
+// warning"):
+struct Hack { char c; char a[]; };
+char* end = c.addData( _cast(pData->buffer)->c + 
pData->length );
+#else
 char* end = c.addData( pData->buffer + pData->length );
+#endif
 *end = '\0';
 pData->length = l;
 return *this;
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 5f0c1032c603..ffe42d139215 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -401,7 +401,15 @@ public:
 pData = rtl_uString_alloc( l );
 if (l != 0)
 {
+#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
+// Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
+//  "Unhelpful 
-Wstringop-overflow
+// warning"):
+struct Hack { sal_Unicode c; sal_Unicode a[]; };
+sal_Unicode* end = c.addData( reinterpret_cast(pData->buffer - 1)->a );
+#else
 sal_Unicode* end = c.addData( pData->buffer );
+#endif
 pData->length = l;
 *end = '\0';
 // TODO realloc in case pData->length is noticeably smaller than l?
@@ -630,7 +638,15 @@ public:
 return *this;
 l += pData->length;
 rtl_uString_ensureCapacity( , l );
+#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
+// Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
+//  "Unhelpful 
-Wstringop-overflow
+// warning"):
+struct Hack { sal_Unicode c; sal_Unicode a[]; };
+sal_Unicode* end = c.addData( reinterpret_cast(pData->buffer - 
1)->a + pData->length );
+#else
 sal_Unicode* end = c.addData( pData->buffer + pData->length );
+#endif
 *end = '\0';
 pData->length = l;
 return *this;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2020-04-24 Thread Noel Grandin (via logerrit)
 include/rtl/ref.hxx |   21 +
 1 file changed, 21 insertions(+)

New commits:
commit b95ead7b2a39bf52e2293d7e8094b9520af74ade
Author: Noel Grandin 
AuthorDate: Wed Apr 22 13:36:13 2020 +0200
Commit: Noel Grandin 
CommitDate: Fri Apr 24 18:26:23 2020 +0200

add upcasting support to rtl::Reference

Change-Id: I34ca9ef65356be56db7ac008238ccadc6697e27a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92693
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/include/rtl/ref.hxx b/include/rtl/ref.hxx
index b0324d99313d..838be87c2c89 100644
--- a/include/rtl/ref.hxx
+++ b/include/rtl/ref.hxx
@@ -25,6 +25,9 @@
 #include 
 #include 
 #include 
+#ifdef LIBO_INTERNAL_ONLY
+#include 
+#endif
 
 #include "sal/types.h"
 
@@ -84,6 +87,24 @@ public:
 }
 #endif
 
+#if defined LIBO_INTERNAL_ONLY
+/** Up-casting conversion constructor: Copies interface reference.
+
+Does not work for up-casts to ambiguous bases.
+
+@param rRef another reference
+*/
+template< class derived_type >
+inline Reference(
+const Reference< derived_type > & rRef,
+std::enable_if_t, int> 
= 0 )
+: m_pBody (rRef.get())
+{
+if (m_pBody)
+m_pBody->acquire();
+}
+#endif
+
 /** Destructor...
  */
 ~Reference() COVERITY_NOEXCEPT_FALSE
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/rtl

2019-11-30 Thread Andrea Gelmini (via logerrit)
 include/rtl/ustring.hxx |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

New commits:
commit bd9d5cc4dc012e8fb8453b094cc0ff6a7a8b4a06
Author: Andrea Gelmini 
AuthorDate: Fri Nov 29 23:38:39 2019 +0100
Commit: Julien Nabet 
CommitDate: Sat Nov 30 10:20:50 2019 +0100

Fix typo

Change-Id: I8d7ed542dc331d3861fcfe2fec7250b5a4bbb166
Reviewed-on: https://gerrit.libreoffice.org/84094
Tested-by: Jenkins
Reviewed-by: Julien Nabet 

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 5919e3de6371..5f0c1032c603 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -924,7 +924,7 @@ public:
   This function can't be used for language specific comparison.
 
   @paramstr the object (substring) to be compared.
-  @paramfromIndex   the index to start the comparion from.
+  @paramfromIndex   the index to start the comparison from.
 The index must be greater than or equal to 0
 and less or equal as the string length.
   @return   true if str match with the characters in the string
@@ -993,7 +993,7 @@ public:
   This function can't be used for language specific comparison.
 
   @paramstr the object (substring) to be compared.
-  @paramfromIndex   the index to start the comparion from.
+  @paramfromIndex   the index to start the comparison from.
 The index must be greater than or equal to 0
 and less than or equal to the string length.
   @return   true if str match with the characters in the string
@@ -1265,7 +1265,7 @@ public:
 
   @paramasciiStrthe object (substring) to be compared.
   @paramasciiStrLength the length of asciiStr.
-  @paramfromIndex   the index to start the comparion from.
+  @paramfromIndex   the index to start the comparison from.
 The index must be greater than or equal to 0
 and less than or equal to the string length.
   @return   true if str match with the characters in the string
@@ -1303,7 +1303,7 @@ public:
 
   @paramasciiStrthe 8-Bit ASCII character string to be 
compared.
   @paramasciiStrLength  the length of the ascii string
-  @paramfromIndex   the index to start the comparion from.
+  @paramfromIndex   the index to start the comparison from.
 The index must be greater than or equal to 0
 and less than or equal to the string length.
   @return   true if str match with the characters in the string
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

  1   2   >