14#ifndef INCLUDED_RTL_STRINGUTILS_HXX
15#define INCLUDED_RTL_STRINGUTILS_HXX
22#if defined LIBO_INTERNAL_ONLY
33#ifdef RTL_STRING_UNITTEST
34#define rtl rtlunittest
40#ifdef RTL_STRING_UNITTEST
44#if defined LIBO_INTERNAL_ONLY
54 constexpr OStringChar(
char theC): c(theC) {}
55 template<
typename T> OStringChar(
56 T, std::enable_if_t<std::is_arithmetic_v<T> || std::is_enum_v<T>,
int> = 0) =
delete;
57 constexpr operator std::string_view()
const {
return {&c, 1}; }
104 constexpr OUStringChar_(
sal_Unicode theC): c(theC) {}
105 constexpr OUStringChar_(
char theC): c(theC) { assert(c <= 0x7F); }
106 template<
typename T> OUStringChar_(
107 T, std::enable_if_t<std::is_arithmetic_v<T> || std::is_enum_v<T>,
int> = 0) =
delete;
108 constexpr operator std::u16string_view()
const {
return {&c, 1}; }
111using OUStringChar = OUStringChar_
const;
116namespace libreoffice_internal
147template<
typename T1,
typename T2 =
void >
150 static const bool ok =
false;
152template<
typename T >
156 static const bool ok =
true;
158template<
typename T >
162 static const bool ok =
true;
164#if defined LIBO_INTERNAL_ONLY
166template<
typename T>
struct CharPtrDetector<
sal_Unicode const *, T> {
using TypeUtf16 = T; };
167template<
typename T>
struct CharPtrDetector<
sal_Unicode[], T> {
using TypeUtf16 = T; };
168template<
typename T>
struct CharPtrDetector<
sal_Unicode const[], T> {
using TypeUtf16 = T; };
171template<
typename T1,
typename T2 >
175template<
typename T,
int N >
180#ifdef RTL_STRING_UNITTEST
182template<
typename T >
187template<
typename T >
188struct NonConstCharArrayDetector< const char[], T >
193#if defined LIBO_INTERNAL_ONLY
194template<
typename T, std::
size_t N>
struct NonConstCharArrayDetector<
sal_Unicode[N], T> {
199template<
typename T1,
typename T2 =
void >
202 static const bool ok =
false;
204template< std::
size_t N,
typename T >
208 static const std::size_t length = N - 1;
209 static const bool ok =
true;
210#if defined LIBO_INTERNAL_ONLY
213 static bool isValid(
char const (& literal)[N]) {
214 for (std::size_t i = 0; i != N - 1; ++i) {
215 if (literal[i] ==
'\0') {
219 return literal[N - 1] ==
'\0';
221#if defined LIBO_INTERNAL_ONLY
224 static char const *
toPointer(
char const (& literal)[N]) {
return literal; }
227#if defined(__COVERITY__)
230template<
typename T >
231struct ConstCharArrayDetector< const char[ 1 ], T >
234 static const std::size_t length = 0;
235 static const bool ok =
true;
236#if defined LIBO_INTERNAL_ONLY
239 static bool isValid(
char const (& literal)[1]) {
240 return literal[0] ==
'\0';
242#if defined LIBO_INTERNAL_ONLY
245 static char const * toPointer(
char const (& literal)[1]) {
return literal; }
249#if defined LIBO_INTERNAL_ONLY \
250 && !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1939 && defined _MANAGED)
251template<std::
size_t N,
typename T>
252struct ConstCharArrayDetector<char8_t const [N], T> {
254 static constexpr bool const ok =
true;
255 static constexpr std::size_t
const length = N - 1;
256 static constexpr bool isValid(
char8_t const (& literal)[N]) {
257 for (std::size_t i = 0; i != N - 1; ++i) {
258 if (literal[i] == u8
'\0') {
262 return literal[N - 1] == u8
'\0';
264 static constexpr char const * toPointer(
char8_t const (& literal)[N])
265 {
return reinterpret_cast<char const *
>(literal); }
269#if defined LIBO_INTERNAL_ONLY
270template<std::
size_t N,
typename T>
271struct ConstCharArrayDetector<
sal_Unicode const [N], T> {
273 static constexpr bool const ok =
true;
274 static constexpr std::size_t
const length = N - 1;
275 static constexpr bool isValid(
sal_Unicode const (& literal)[N]) {
276 for (std::size_t i = 0; i != N - 1; ++i) {
277 if (literal[i] ==
'\0') {
281 return literal[N - 1] ==
'\0';
288#if defined(__COVERITY__)
292struct ConstCharArrayDetector<
sal_Unicode const [1], T> {
294 static constexpr bool const ok =
true;
295 static constexpr std::size_t
const length = 0;
296 static constexpr bool isValid(
sal_Unicode const (& literal)[1]) {
297 return literal[0] ==
'\0';
305template<
typename T>
struct ConstCharArrayDetector<
310 static constexpr bool const ok =
true;
311 static constexpr std::size_t
const length = 1;
312 static constexpr bool isValid(OUStringChar) {
return true; }
314 OUStringChar_
const & literal)
315 {
return &literal.c; }
319#if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
322template<
typename T >
323struct ExceptConstCharArrayDetector
328struct ExceptConstCharArrayDetector< const char[ N ] >
331template<std::
size_t N>
332struct ExceptConstCharArrayDetector<
sal_Unicode const[N]> {};
333template<>
struct ExceptConstCharArrayDetector<
342template<
typename T >
343struct ExceptCharArrayDetector
348struct ExceptCharArrayDetector< char[ N ] >
352struct ExceptCharArrayDetector< const char[ N ] >
355template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode[N]> {};
356template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode const[N]> {};
357template<>
struct ExceptCharArrayDetector<OUStringChar_> {};
361template<
typename T1,
typename T2 =
void >
364 static const bool ok =
false;
366template<
typename T >
370 static const bool ok =
true;
372template<
typename T >
376 static const bool ok =
true;
380template<
typename T,
bool >
385template<
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:611
Definition bootstrap.hxx:34
Definition stringutils.hxx:146
Definition stringutils.hxx:149
static const bool ok
Definition stringutils.hxx:150
T Type
Definition stringutils.hxx:155
T Type
Definition stringutils.hxx:161
Definition stringutils.hxx:173
T Type
Definition stringutils.hxx:178
Definition stringutils.hxx:201
static const bool ok
Definition stringutils.hxx:202
static char const * toPointer(char const (&literal)[N])
Definition stringutils.hxx:224
T Type
Definition stringutils.hxx:207
static bool isValid(char const (&literal)[N])
Definition stringutils.hxx:213
Definition stringutils.hxx:363
static const bool ok
Definition stringutils.hxx:364
T Type
Definition stringutils.hxx:369
T Type
Definition stringutils.hxx:375
Definition stringutils.hxx:382
T Type
Definition stringutils.hxx:388