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}; }
105 using OUStringChar = OUStringChar_
const;
110 namespace libreoffice_internal
141 template<
typename T1,
typename T2 =
void >
144 static const bool ok =
false;
146 template<
typename T >
150 static const bool ok =
true;
152 template<
typename T >
156 static const bool ok =
true;
158 #if defined LIBO_INTERNAL_ONLY
160 template<
typename T>
struct CharPtrDetector<
sal_Unicode const *, T> {
using TypeUtf16 = T; };
161 template<
typename T>
struct CharPtrDetector<
sal_Unicode[], T> {
using TypeUtf16 = T; };
162 template<
typename T>
struct CharPtrDetector<
sal_Unicode const[], T> {
using TypeUtf16 = T; };
165 template<
typename T1,
typename T2 >
169 template<
typename T,
int N >
174 #ifdef RTL_STRING_UNITTEST
176 template<
typename T >
181 template<
typename T >
182 struct NonConstCharArrayDetector< const char[], T >
187 #if defined LIBO_INTERNAL_ONLY
188 template<
typename T, std::
size_t N>
struct NonConstCharArrayDetector<
sal_Unicode[N], T> {
193 template<
typename T1,
typename T2 =
void >
196 static const bool ok =
false;
198 template< 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__)
224 template<
typename T >
225 struct 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
244 template<std::
size_t N,
typename T>
245 struct 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
263 template<std::
size_t N,
typename T>
264 struct 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__)
285 struct 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';
298 template<
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
315 template<
typename T >
316 struct ExceptConstCharArrayDetector
321 struct ExceptConstCharArrayDetector< const char[ N ] >
324 template<std::
size_t N>
325 struct ExceptConstCharArrayDetector<
sal_Unicode const[N]> {};
326 template<>
struct ExceptConstCharArrayDetector<
335 template<
typename T >
336 struct ExceptCharArrayDetector
341 struct ExceptCharArrayDetector< char[ N ] >
345 struct ExceptCharArrayDetector< const char[ N ] >
348 template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode[N]> {};
349 template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode const[N]> {};
350 template<>
struct ExceptCharArrayDetector<OUStringChar_> {};
354 template<
typename T1,
typename T2 =
void >
357 static const bool ok =
false;
359 template<
typename T >
363 static const bool ok =
true;
365 template<
typename T >
369 static const bool ok =
true;
373 template<
typename T,
bool >
378 template<
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
T Type
Definition: stringutils.hxx:201
static char const * toPointer(char const (&literal)[N])
Definition: stringutils.hxx:218
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