10#ifndef INCLUDED_RTL_STRINGUTILS_HXX
11#define INCLUDED_RTL_STRINGUTILS_HXX
25#ifdef RTL_STRING_UNITTEST
26#define rtl rtlunittest
32#ifdef RTL_STRING_UNITTEST
36#if defined LIBO_INTERNAL_ONLY
46 constexpr OStringChar(
char theC): c(theC) {}
47 template<
typename T> OStringChar(T &&) =
delete;
94 constexpr OUStringChar_(
sal_Unicode theC): c(theC) {}
95 constexpr OUStringChar_(
char theC): c(theC) { assert(c <= 0x7F); }
96 template<
typename T> OUStringChar_(T &&) =
delete;
97 constexpr operator std::u16string_view()
const {
return {&c, 1}; }
100using OUStringChar = OUStringChar_
const;
105namespace libreoffice_internal
132template<
typename T1,
typename T2 =
void >
135 static const bool ok =
false;
137template<
typename T >
141 static const bool ok =
true;
143template<
typename T >
147 static const bool ok =
true;
149#if defined LIBO_INTERNAL_ONLY
151template<
typename T>
struct CharPtrDetector<
sal_Unicode const *, T> {
using TypeUtf16 = T; };
152template<
typename T>
struct CharPtrDetector<
sal_Unicode[], T> {
using TypeUtf16 = T; };
153template<
typename T>
struct CharPtrDetector<
sal_Unicode const[], T> {
using TypeUtf16 = T; };
156template<
typename T1,
typename T2 >
160template<
typename T,
int N >
165#ifdef RTL_STRING_UNITTEST
167template<
typename T >
172template<
typename T >
173struct NonConstCharArrayDetector< const char[], T >
178#if defined LIBO_INTERNAL_ONLY
179template<
typename T, std::
size_t N>
struct NonConstCharArrayDetector<
sal_Unicode[N], T> {
184template<
typename T1,
typename T2 =
void >
187 static const bool ok =
false;
189template< std::
size_t N,
typename T >
193 static const std::size_t length = N - 1;
194 static const bool ok =
true;
195#if defined LIBO_INTERNAL_ONLY
198 static bool isValid(
char const (& literal)[N]) {
199 for (std::size_t i = 0; i != N - 1; ++i) {
200 if (literal[i] ==
'\0') {
204 return literal[N - 1] ==
'\0';
206#if defined LIBO_INTERNAL_ONLY
209 static char const *
toPointer(
char const (& literal)[N]) {
return literal; }
212#if defined(__COVERITY__)
215template<
typename T >
216struct ConstCharArrayDetector< const char[ 1 ], T >
219 static const std::size_t length = 0;
220 static const bool ok =
true;
221#if defined LIBO_INTERNAL_ONLY
224 static bool isValid(
char const (& literal)[1]) {
225 return literal[0] ==
'\0';
227#if defined LIBO_INTERNAL_ONLY
230 static char const * toPointer(
char const (& literal)[1]) {
return literal; }
234#if defined LIBO_INTERNAL_ONLY && defined __cpp_char8_t
235template<std::
size_t N,
typename T>
236struct ConstCharArrayDetector<char8_t const [N], T> {
238 static constexpr bool const ok =
true;
239 static constexpr std::size_t
const length = N - 1;
240 static constexpr bool isValid(
char8_t const (& literal)[N]) {
241 for (std::size_t i = 0; i != N - 1; ++i) {
242 if (literal[i] == u8
'\0') {
246 return literal[N - 1] == u8
'\0';
248 static constexpr char const * toPointer(
char8_t const (& literal)[N])
249 {
return reinterpret_cast<char const *
>(literal); }
253#if defined LIBO_INTERNAL_ONLY
254template<std::
size_t N,
typename T>
255struct ConstCharArrayDetector<
sal_Unicode const [N], T> {
257 static constexpr bool const ok =
true;
258 static constexpr std::size_t
const length = N - 1;
259 static constexpr bool isValid(
sal_Unicode const (& literal)[N]) {
260 for (std::size_t i = 0; i != N - 1; ++i) {
261 if (literal[i] ==
'\0') {
265 return literal[N - 1] ==
'\0';
272#if defined(__COVERITY__)
276struct ConstCharArrayDetector<
sal_Unicode const [1], T> {
278 static constexpr bool const ok =
true;
279 static constexpr std::size_t
const length = 0;
280 static constexpr bool isValid(
sal_Unicode const (& literal)[1]) {
281 return literal[0] ==
'\0';
289template<
typename T>
struct ConstCharArrayDetector<
294 static constexpr bool const ok =
true;
295 static constexpr std::size_t
const length = 1;
296 static constexpr bool isValid(OUStringChar) {
return true; }
298 OUStringChar_
const & literal)
299 {
return &literal.c; }
303#if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
306template<
typename T >
307struct ExceptConstCharArrayDetector
312struct ExceptConstCharArrayDetector< const char[ N ] >
315template<std::
size_t N>
316struct ExceptConstCharArrayDetector<
sal_Unicode const[N]> {};
317template<>
struct ExceptConstCharArrayDetector<
326template<
typename T >
327struct ExceptCharArrayDetector
332struct ExceptCharArrayDetector< char[ N ] >
336struct ExceptCharArrayDetector< const char[ N ] >
339template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode[N]> {};
340template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode const[N]> {};
341template<>
struct ExceptCharArrayDetector<OUStringChar_> {};
345template<
typename T1,
typename T2 =
void >
348 static const bool ok =
false;
350template<
typename T >
354 static const bool ok =
true;
356template<
typename T >
360 static const bool ok =
true;
364template<
typename T,
bool >
369template<
typename T >
sal_uInt16 sal_Unicode
Definition: types.h:119
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:558
Definition: bootstrap.hxx:30
Definition: stringutils.hxx:131
Definition: stringutils.hxx:134
static const bool ok
Definition: stringutils.hxx:135
T Type
Definition: stringutils.hxx:140
T Type
Definition: stringutils.hxx:146
Definition: stringutils.hxx:158
T Type
Definition: stringutils.hxx:163
Definition: stringutils.hxx:186
static const bool ok
Definition: stringutils.hxx:187
static char const * toPointer(char const (&literal)[N])
Definition: stringutils.hxx:209
T Type
Definition: stringutils.hxx:192
static bool isValid(char const (&literal)[N])
Definition: stringutils.hxx:198
Definition: stringutils.hxx:347
static const bool ok
Definition: stringutils.hxx:348
T Type
Definition: stringutils.hxx:353
T Type
Definition: stringutils.hxx:359
Definition: stringutils.hxx:366
T Type
Definition: stringutils.hxx:372