office-gobmx/sal/CompilerTest_sal_rtl_oustring.mk
Stephan Bergmann 1b43cceaea Make many OUString functions take std::u16string_view parameters
...instead of having individual overloads for OUString, OUStringLiteral, and
literal char16_t const[N].  (The variants taking OUString are still needed for
!LIBO_INTERNAL_ONLY, though.  The variants taking ASCII-only literal char
const[N] are also left in place.)

This nicely reduces the number of needed overloads.  std::u16string_view allows
to pass as arguments:

* OUString
* OUStringLiteral
* OUStringChar  (with the necessary conversion added now)
* OUStringNumber
* u"..." char16_t string literals
* u"..."sv std::u16string_view literals
* std::u16string, plain char16_t*, and more

A notable exceptions is OUStringConcat, which now needs to be wrapped in
OUString(...), see the handful of places that needed to be adapted.

One caveat is the treatment of embedded NUL characters, as

  std::u16string_view(u"x\0y")

constructs a view of size 1, while only

  u"x\0y"sv

constructs a view of size 3 (which matches the old behavior of overloads for
literal char16_t const[N] via the ConstCharArrayDetector<>::TypeUtf16
machinery).  See the new checkEmbeddedNul in
sal/qa/rtl/strings/test_oustring_stringliterals.cxx.

The functions that have been changed are generally those that:

* already take a string of determined length, so that using std::u16string_view,
  which is always constructed with a determined length, is no pessimization
  (e.g., there are operator == overloads taking plain pointers, which do not
  need to determine the string length upfront);

* could not benefit from the fact that the passed-in argument is an OUString
  (e.g., the corresponding operator = overload can reuse the passed-in
  OUString's rtl_uString pData member);

* do not run into overload resolution ambiguity issues, like the comparison
  operators would do.

One inconsistency that showed up is that while the original

  replaceAll(OUString const &, OUString const &, sal_Int32 fromIndex = 0)

overload takes an optional third fromIndex argument, the existing replaceAll
overloads taking OUStringLiteral and literal char16_t const[N] arguments did
not.  Fixing that required a new (LIBO_INTERNAL_ONLY)
rtl_uString_newReplaceAllFromIndexUtf16LUtf16L (with test code in
sal/qa/rtl/strings/test_strings_replace.cxx).

Another issue was posed by test code in
sal/qa/rtl/strings/test_oustring_stringliterals.cxx that used the
RTL_STRING_UNITTEST-only OUString(Except*CharArrayDetector) ctors to verify that
certain function calls should not compile (and would compile under
RTL_STRING_UNITTEST by taking those Except*CharArrayDetector converted to
OUString as arguments).  Those problematic "should fail to compile" tests have
been converted into a new CompilerTest_sal_rtl_oustring.

Change-Id: Id72e8c4cc338258cadad00ddc6ea5b9da2e1f780
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102020
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-09-04 07:55:15 +02:00

16 lines
546 B
Makefile

# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; 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/.
#
$(eval $(call gb_CompilerTest_CompilerTest,sal_rtl_oustring))
$(eval $(call gb_CompilerTest_add_exception_objects,sal_rtl_oustring, \
sal/qa/rtl/strings/compile-oustring \
))
# vim: set noet sw=4 ts=4: