14#ifndef INCLUDED_RTL_STRINGUTILS_HXX
15#define INCLUDED_RTL_STRINGUTILS_HXX
22#if defined LIBO_INTERNAL_ONLY
35#ifdef RTL_STRING_UNITTEST
36#define rtl rtlunittest
42#ifdef RTL_STRING_UNITTEST
46#if defined LIBO_INTERNAL_ONLY
56 constexpr OStringChar(
char theC): c(theC) {}
57 template<
typename T> OStringChar(
58 T, std::enable_if_t<std::is_arithmetic_v<T> || std::is_enum_v<T>,
int> = 0) =
delete;
59 constexpr operator std::string_view()
const {
return {&c, 1}; }
106 constexpr OUStringChar_(
sal_Unicode theC): c(theC) {}
107 constexpr OUStringChar_(
char theC): c(theC) { assert(c <= 0x7F); }
108 template<
typename T> OUStringChar_(
109 T, std::enable_if_t<std::is_arithmetic_v<T> || std::is_enum_v<T>,
int> = 0) =
delete;
110 constexpr operator std::u16string_view()
const {
return {&c, 1}; }
113using OUStringChar = OUStringChar_
const;
120#if defined LIBO_INTERNAL_ONLY
121template <
typename I, std::enable_if_t<
122 std::is_integral_v<I> && std::is_signed_v<I>,
124constexpr bool IsValidStrLen(I i, sal_Int32 margin = 0)
127 constexpr sal_uInt32 maxLen = std::numeric_limits<sal_Int32>::max();
128 return i >= 0 &&
static_cast<std::make_unsigned_t<I>
>(i) <= maxLen - margin;
131template <
typename I, std::enable_if_t<
132 std::is_integral_v<I> && std::is_unsigned_v<I>,
134constexpr bool IsValidStrLen(I i, sal_Int32 margin = 0)
137 constexpr sal_uInt32 maxLen = std::numeric_limits<sal_Int32>::max();
138 return i <= maxLen - margin;
141template <
typename I, std::enable_if_t<std::is_
integral_v<I>,
int> = 0>
142sal_Int32 ThrowIfInvalidStrLen(I i, sal_Int32 margin = 0)
144 if (!IsValidStrLen(i, margin))
145 throw std::bad_alloc();
179template<
typename T1,
typename T2 =
void >
182 static const bool ok =
false;
184template<
typename T >
188 static const bool ok =
true;
190template<
typename T >
194 static const bool ok =
true;
196#if defined LIBO_INTERNAL_ONLY
198template<
typename T>
struct CharPtrDetector<
sal_Unicode const *, T> {
using TypeUtf16 = T; };
199template<
typename T>
struct CharPtrDetector<
sal_Unicode[], T> {
using TypeUtf16 = T; };
203template<
typename T1,
typename T2 >
207template<
typename T,
int N >
212#ifdef RTL_STRING_UNITTEST
214template<
typename T >
219template<
typename T >
220struct NonConstCharArrayDetector< const char[], T >
225#if defined LIBO_INTERNAL_ONLY
226template<
typename T, std::
size_t N>
struct NonConstCharArrayDetector<
sal_Unicode[N], T> {
231template<
typename T1,
typename T2 =
void >
234 static const bool ok =
false;
236template< std::
size_t N,
typename T >
241 static const bool ok =
true;
242#if defined LIBO_INTERNAL_ONLY
245 static bool isValid(
char const (& literal)[N]) {
246 for (std::size_t i = 0; i != N - 1; ++i) {
247 if (literal[i] ==
'\0') {
251 return literal[N - 1] ==
'\0';
253#if defined LIBO_INTERNAL_ONLY
256 static char const *
toPointer(
char const (& literal)[N]) {
return literal; }
259#if defined(__COVERITY__) && __COVERITY_MAJOR__ <= 2023
262template<
typename T >
263struct ConstCharArrayDetector< const char[ 1 ], T >
266 static const std::size_t length = 0;
267 static const bool ok =
true;
268#if defined LIBO_INTERNAL_ONLY
271 static bool isValid(
char const (& literal)[1]) {
272 return literal[0] ==
'\0';
274#if defined LIBO_INTERNAL_ONLY
277 static char const * toPointer(
char const (& literal)[1]) {
return literal; }
281#if defined LIBO_INTERNAL_ONLY \
282 && !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1939 && defined _MANAGED)
283template<std::
size_t N,
typename T>
286 static constexpr bool const ok =
true;
287 static constexpr std::size_t
const length = N - 1;
288 static constexpr bool isValid(
char8_t const (& literal)[N]) {
289 for (std::size_t i = 0; i != N - 1; ++i) {
290 if (literal[i] == u8
'\0') {
294 return literal[N - 1] == u8
'\0';
296 static constexpr char const * toPointer(
char8_t const (& literal)[N])
297 {
return reinterpret_cast<char const *
>(literal); }
301#if defined LIBO_INTERNAL_ONLY
302template<std::
size_t N,
typename T>
305 static constexpr bool const ok =
true;
306 static constexpr std::size_t
const length = N - 1;
307 static constexpr bool isValid(
sal_Unicode const (& literal)[N]) {
308 for (std::size_t i = 0; i != N - 1; ++i) {
309 if (literal[i] ==
'\0') {
313 return literal[N - 1] ==
'\0';
320#if defined(__COVERITY__) && __COVERITY_MAJOR__ <= 2023
326 static constexpr bool const ok =
true;
327 static constexpr std::size_t
const length = 0;
328 static constexpr bool isValid(
sal_Unicode const (& literal)[1]) {
329 return literal[0] ==
'\0';
342 static constexpr bool const ok =
true;
343 static constexpr std::size_t
const length = 1;
344 static constexpr bool isValid(OUStringChar) {
return true; }
346 OUStringChar_
const & literal)
347 {
return &literal.c; }
351#if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
354template<
typename T >
355struct ExceptConstCharArrayDetector
360struct ExceptConstCharArrayDetector< const char[ N ] >
363template<std::
size_t N>
364struct ExceptConstCharArrayDetector<
sal_Unicode const[N]> {};
365template<>
struct ExceptConstCharArrayDetector<
374template<
typename T >
375struct ExceptCharArrayDetector
380struct ExceptCharArrayDetector< char[ N ] >
384struct ExceptCharArrayDetector< const char[ N ] >
387template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode[N]> {};
388template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode const[N]> {};
389template<>
struct ExceptCharArrayDetector<OUStringChar_> {};
393template<
typename T1,
typename T2 =
void >
396 static const bool ok =
false;
398template<
typename T >
402 static const bool ok =
true;
404template<
typename T >
408 static const bool ok =
true;
412template<
typename T,
bool >
417template<
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:119
Definition stringutils.hxx:178
Definition stringutils.hxx:181
static const bool ok
Definition stringutils.hxx:182
T Type
Definition stringutils.hxx:187
static const bool ok
Definition stringutils.hxx:188
T Type
Definition stringutils.hxx:193
static const bool ok
Definition stringutils.hxx:194
Definition stringutils.hxx:205
T Type
Definition stringutils.hxx:210
Definition stringutils.hxx:233
static const bool ok
Definition stringutils.hxx:234
static char const * toPointer(char const (&literal)[N])
Definition stringutils.hxx:256
static const bool ok
Definition stringutils.hxx:241
T Type
Definition stringutils.hxx:239
static bool isValid(char const (&literal)[N])
Definition stringutils.hxx:245
static const std::size_t length
Definition stringutils.hxx:240
Definition stringutils.hxx:395
static const bool ok
Definition stringutils.hxx:396
T Type
Definition stringutils.hxx:401
static const bool ok
Definition stringutils.hxx:402
static const bool ok
Definition stringutils.hxx:408
T Type
Definition stringutils.hxx:407
Definition stringutils.hxx:414
T Type
Definition stringutils.hxx:420