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
137template<
typename T1,
typename T2 =
void >
140 static const bool ok =
false;
142template<
typename T >
146 static const bool ok =
true;
148template<
typename T >
152 static const bool ok =
true;
154#if defined LIBO_INTERNAL_ONLY
156template<
typename T>
struct CharPtrDetector<
sal_Unicode const *, T> {
using TypeUtf16 = T; };
157template<
typename T>
struct CharPtrDetector<
sal_Unicode[], T> {
using TypeUtf16 = T; };
158template<
typename T>
struct CharPtrDetector<
sal_Unicode const[], T> {
using TypeUtf16 = T; };
161template<
typename T1,
typename T2 >
165template<
typename T,
int N >
170#ifdef RTL_STRING_UNITTEST
172template<
typename T >
177template<
typename T >
178struct NonConstCharArrayDetector< const char[], T >
183#if defined LIBO_INTERNAL_ONLY
184template<
typename T, std::
size_t N>
struct NonConstCharArrayDetector<
sal_Unicode[N], T> {
189template<
typename T1,
typename T2 =
void >
192 static const bool ok =
false;
194template< std::
size_t N,
typename T >
198 static const std::size_t length = N - 1;
199 static const bool ok =
true;
200#if defined LIBO_INTERNAL_ONLY
203 static bool isValid(
char const (& literal)[N]) {
204 for (std::size_t i = 0; i != N - 1; ++i) {
205 if (literal[i] ==
'\0') {
209 return literal[N - 1] ==
'\0';
211#if defined LIBO_INTERNAL_ONLY
214 static char const *
toPointer(
char const (& literal)[N]) {
return literal; }
217#if defined(__COVERITY__)
220template<
typename T >
221struct ConstCharArrayDetector< const char[ 1 ], T >
224 static const std::size_t length = 0;
225 static const bool ok =
true;
226#if defined LIBO_INTERNAL_ONLY
229 static bool isValid(
char const (& literal)[1]) {
230 return literal[0] ==
'\0';
232#if defined LIBO_INTERNAL_ONLY
235 static char const * toPointer(
char const (& literal)[1]) {
return literal; }
239#if defined LIBO_INTERNAL_ONLY && defined __cpp_char8_t
240template<std::
size_t N,
typename T>
241struct ConstCharArrayDetector<char8_t const [N], T> {
243 static constexpr bool const ok =
true;
244 static constexpr std::size_t
const length = N - 1;
245 static constexpr bool isValid(
char8_t const (& literal)[N]) {
246 for (std::size_t i = 0; i != N - 1; ++i) {
247 if (literal[i] == u8
'\0') {
251 return literal[N - 1] == u8
'\0';
253 static constexpr char const * toPointer(
char8_t const (& literal)[N])
254 {
return reinterpret_cast<char const *
>(literal); }
258#if defined LIBO_INTERNAL_ONLY
259template<std::
size_t N,
typename T>
260struct ConstCharArrayDetector<
sal_Unicode const [N], T> {
262 static constexpr bool const ok =
true;
263 static constexpr std::size_t
const length = N - 1;
264 static constexpr bool isValid(
sal_Unicode const (& literal)[N]) {
265 for (std::size_t i = 0; i != N - 1; ++i) {
266 if (literal[i] ==
'\0') {
270 return literal[N - 1] ==
'\0';
277#if defined(__COVERITY__)
281struct ConstCharArrayDetector<
sal_Unicode const [1], T> {
283 static constexpr bool const ok =
true;
284 static constexpr std::size_t
const length = 0;
285 static constexpr bool isValid(
sal_Unicode const (& literal)[1]) {
286 return literal[0] ==
'\0';
294template<
typename T>
struct ConstCharArrayDetector<
299 static constexpr bool const ok =
true;
300 static constexpr std::size_t
const length = 1;
301 static constexpr bool isValid(OUStringChar) {
return true; }
303 OUStringChar_
const & literal)
304 {
return &literal.c; }
308#if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
311template<
typename T >
312struct ExceptConstCharArrayDetector
317struct ExceptConstCharArrayDetector< const char[ N ] >
320template<std::
size_t N>
321struct ExceptConstCharArrayDetector<
sal_Unicode const[N]> {};
322template<>
struct ExceptConstCharArrayDetector<
331template<
typename T >
332struct ExceptCharArrayDetector
337struct ExceptCharArrayDetector< char[ N ] >
341struct ExceptCharArrayDetector< const char[ N ] >
344template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode[N]> {};
345template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode const[N]> {};
346template<>
struct ExceptCharArrayDetector<OUStringChar_> {};
350template<
typename T1,
typename T2 =
void >
353 static const bool ok =
false;
355template<
typename T >
359 static const bool ok =
true;
361template<
typename T >
365 static const bool ok =
true;
369template<
typename T,
bool >
374template<
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:136
Definition: stringutils.hxx:139
static const bool ok
Definition: stringutils.hxx:140
T Type
Definition: stringutils.hxx:145
T Type
Definition: stringutils.hxx:151
Definition: stringutils.hxx:163
T Type
Definition: stringutils.hxx:168
Definition: stringutils.hxx:191
static const bool ok
Definition: stringutils.hxx:192
static char const * toPointer(char const (&literal)[N])
Definition: stringutils.hxx:214
T Type
Definition: stringutils.hxx:197
static bool isValid(char const (&literal)[N])
Definition: stringutils.hxx:203
Definition: stringutils.hxx:352
static const bool ok
Definition: stringutils.hxx:353
T Type
Definition: stringutils.hxx:358
T Type
Definition: stringutils.hxx:364
Definition: stringutils.hxx:371
T Type
Definition: stringutils.hxx:377