diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-08-20 20:20:22 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2018-08-21 07:35:50 +0200 |
commit | f0fcbcadac148a5bfd36b2a26795d45aef8eace4 (patch) | |
tree | bade826c5f4dc8148423af476b5c980a7de28837 /include/rtl/stringutils.hxx | |
parent | 7d01ce4021bafde8184355f46d1cbe2c370767e1 (diff) |
Make OUStringLiteral ctor actually constexpr
...which had accidentally been broken with
87707670c993794ab12b0fad0f048f11429269c2 "Make OUStringLiteral more useful".
(std::strlen unfortunately isn't constexpr, so need to use an explicit loop
instead.)
Change-Id: I9a820e2940b99a0c37124477810ef879d82c8325
Reviewed-on: https://gerrit.libreoffice.org/59344
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/rtl/stringutils.hxx')
-rw-r--r-- | include/rtl/stringutils.hxx | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/include/rtl/stringutils.hxx b/include/rtl/stringutils.hxx index c6a5fcb64917..53f7554ee132 100644 --- a/include/rtl/stringutils.hxx +++ b/include/rtl/stringutils.hxx @@ -13,10 +13,13 @@ #include "sal/config.h" #include <cstddef> -#include <cstring> #include "sal/types.h" +#if defined LIBO_INTERNAL_ONLY +#include "config_global.h" +#endif + // The unittest uses slightly different code to help check that the proper // calls are made. The class is put into a different namespace to make // sure the compiler generates a different (if generating also non-inline) @@ -165,8 +168,20 @@ struct ConstCharArrayDetector< const char[ N ], T > typedef T Type; static const std::size_t length = N - 1; static const bool ok = true; - static bool isValid(char const (& literal)[N]) - { return std::strlen(literal) == length; } +#if defined LIBO_INTERNAL_ONLY && HAVE_CXX14_CONSTEXPR + constexpr +#endif + static bool isValid(char const (& literal)[N]) { + for (std::size_t i = 0; i != N - 1; ++i) { + if (literal[i] == '\0') { + return false; + } + } + return literal[N - 1] == '\0'; + } +#if defined LIBO_INTERNAL_ONLY + constexpr +#endif static char const * toPointer(char const (& literal)[N]) { return literal; } }; #if defined LIBO_INTERNAL_ONLY |