14#ifndef INCLUDED_RTL_STRINGUTILS_HXX
15#define INCLUDED_RTL_STRINGUTILS_HXX
29#ifdef RTL_STRING_UNITTEST
30#define rtl rtlunittest
36#ifdef RTL_STRING_UNITTEST
40#if defined LIBO_INTERNAL_ONLY
50 constexpr OStringChar(
char theC): c(theC) {}
51 template<
typename T> OStringChar(T &&) =
delete;
52 constexpr operator std::string_view()
const {
return {&c, 1}; }
99 constexpr OUStringChar_(
sal_Unicode theC): c(theC) {}
100 constexpr OUStringChar_(
char theC): c(theC) { assert(c <= 0x7F); }
101 template<
typename T> OUStringChar_(T &&) =
delete;
102 constexpr operator std::u16string_view()
const {
return {&c, 1}; }
105using OUStringChar = OUStringChar_
const;
110namespace libreoffice_internal
141template<
typename T1,
typename T2 =
void >
144 static const bool ok =
false;
146template<
typename T >
150 static const bool ok =
true;
152template<
typename T >
156 static const bool ok =
true;
158#if defined LIBO_INTERNAL_ONLY
160template<
typename T>
struct CharPtrDetector<
sal_Unicode const *, T> {
using TypeUtf16 = T; };
161template<
typename T>
struct CharPtrDetector<
sal_Unicode[], T> {
using TypeUtf16 = T; };
162template<
typename T>
struct CharPtrDetector<
sal_Unicode const[], T> {
using TypeUtf16 = T; };
165template<
typename T1,
typename T2 >
169template<
typename T,
int N >
174#ifdef RTL_STRING_UNITTEST
176template<
typename T >
181template<
typename T >
182struct NonConstCharArrayDetector< const char[], T >
187#if defined LIBO_INTERNAL_ONLY
188template<
typename T, std::
size_t N>
struct NonConstCharArrayDetector<
sal_Unicode[N], T> {
193template<
typename T1,
typename T2 =
void >
196 static const bool ok =
false;
198template< std::
size_t N,
typename T >
202 static const std::size_t length = N - 1;
203 static const bool ok =
true;
204#if defined LIBO_INTERNAL_ONLY
207 static bool isValid(
char const (& literal)[N]) {
208 for (std::size_t i = 0; i != N - 1; ++i) {
209 if (literal[i] ==
'\0') {
213 return literal[N - 1] ==
'\0';
215#if defined LIBO_INTERNAL_ONLY
218 static char const *
toPointer(
char const (& literal)[N]) {
return literal; }
221#if defined(__COVERITY__)
224template<
typename T >
225struct ConstCharArrayDetector< const char[ 1 ], T >
228 static const std::size_t length = 0;
229 static const bool ok =
true;
230#if defined LIBO_INTERNAL_ONLY
233 static bool isValid(
char const (& literal)[1]) {
234 return literal[0] ==
'\0';
236#if defined LIBO_INTERNAL_ONLY
239 static char const * toPointer(
char const (& literal)[1]) {
return literal; }
243#if defined LIBO_INTERNAL_ONLY && defined __cpp_char8_t
244template<std::
size_t N,
typename T>
245struct ConstCharArrayDetector<char8_t const [N], T> {
247 static constexpr bool const ok =
true;
248 static constexpr std::size_t
const length = N - 1;
249 static constexpr bool isValid(
char8_t const (& literal)[N]) {
250 for (std::size_t i = 0; i != N - 1; ++i) {
251 if (literal[i] == u8
'\0') {
255 return literal[N - 1] == u8
'\0';
257 static constexpr char const * toPointer(
char8_t const (& literal)[N])
258 {
return reinterpret_cast<char const *
>(literal); }
262#if defined LIBO_INTERNAL_ONLY
263template<std::
size_t N,
typename T>
264struct ConstCharArrayDetector<
sal_Unicode const [N], T> {
266 static constexpr bool const ok =
true;
267 static constexpr std::size_t
const length = N - 1;
268 static constexpr bool isValid(
sal_Unicode const (& literal)[N]) {
269 for (std::size_t i = 0; i != N - 1; ++i) {
270 if (literal[i] ==
'\0') {
274 return literal[N - 1] ==
'\0';
281#if defined(__COVERITY__)
285struct ConstCharArrayDetector<
sal_Unicode const [1], T> {
287 static constexpr bool const ok =
true;
288 static constexpr std::size_t
const length = 0;
289 static constexpr bool isValid(
sal_Unicode const (& literal)[1]) {
290 return literal[0] ==
'\0';
298template<
typename T>
struct ConstCharArrayDetector<
303 static constexpr bool const ok =
true;
304 static constexpr std::size_t
const length = 1;
305 static constexpr bool isValid(OUStringChar) {
return true; }
307 OUStringChar_
const & literal)
308 {
return &literal.c; }
312#if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
315template<
typename T >
316struct ExceptConstCharArrayDetector
321struct ExceptConstCharArrayDetector< const char[ N ] >
324template<std::
size_t N>
325struct ExceptConstCharArrayDetector<
sal_Unicode const[N]> {};
326template<>
struct ExceptConstCharArrayDetector<
335template<
typename T >
336struct ExceptCharArrayDetector
341struct ExceptCharArrayDetector< char[ N ] >
345struct ExceptCharArrayDetector< const char[ N ] >
348template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode[N]> {};
349template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode const[N]> {};
350template<>
struct ExceptCharArrayDetector<OUStringChar_> {};
354template<
typename T1,
typename T2 =
void >
357 static const bool ok =
false;
359template<
typename T >
363 static const bool ok =
true;
365template<
typename T >
369 static const bool ok =
true;
373template<
typename T,
bool >
378template<
typename T >
sal_uInt16 sal_Unicode
Definition: types.h:123
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:587
Definition: bootstrap.hxx:34
Definition: stringutils.hxx:140
Definition: stringutils.hxx:143
static const bool ok
Definition: stringutils.hxx:144
T Type
Definition: stringutils.hxx:149
T Type
Definition: stringutils.hxx:155
Definition: stringutils.hxx:167
T Type
Definition: stringutils.hxx:172
Definition: stringutils.hxx:195
static const bool ok
Definition: stringutils.hxx:196
static char const * toPointer(char const (&literal)[N])
Definition: stringutils.hxx:218
T Type
Definition: stringutils.hxx:201
static bool isValid(char const (&literal)[N])
Definition: stringutils.hxx:207
Definition: stringutils.hxx:356
static const bool ok
Definition: stringutils.hxx:357
T Type
Definition: stringutils.hxx:362
T Type
Definition: stringutils.hxx:368
Definition: stringutils.hxx:375
T Type
Definition: stringutils.hxx:381