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}; }
100 using OUStringChar = OUStringChar_
const;
105 namespace libreoffice_internal
132 template<
typename T1,
typename T2 =
void >
135 static const bool ok =
false;
137 template<
typename T >
141 static const bool ok =
true;
143 template<
typename T >
147 static const bool ok =
true;
149 #if defined LIBO_INTERNAL_ONLY
151 template<
typename T>
struct CharPtrDetector<
sal_Unicode const *, T> {
using TypeUtf16 = T; };
152 template<
typename T>
struct CharPtrDetector<
sal_Unicode[], T> {
using TypeUtf16 = T; };
153 template<
typename T>
struct CharPtrDetector<
sal_Unicode const[], T> {
using TypeUtf16 = T; };
156 template<
typename T1,
typename T2 >
160 template<
typename T,
int N >
165 #ifdef RTL_STRING_UNITTEST
167 template<
typename T >
172 template<
typename T >
173 struct NonConstCharArrayDetector< const char[], T >
178 #if defined LIBO_INTERNAL_ONLY
179 template<
typename T, std::
size_t N>
struct NonConstCharArrayDetector<
sal_Unicode[N], T> {
184 template<
typename T1,
typename T2 =
void >
187 static const bool ok =
false;
189 template< 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__)
215 template<
typename T >
216 struct 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
235 template<std::
size_t N,
typename T>
236 struct 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
254 template<std::
size_t N,
typename T>
255 struct 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__)
276 struct 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';
289 template<
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
306 template<
typename T >
307 struct ExceptConstCharArrayDetector
312 struct ExceptConstCharArrayDetector< const char[ N ] >
315 template<std::
size_t N>
316 struct ExceptConstCharArrayDetector<
sal_Unicode const[N]> {};
317 template<>
struct ExceptConstCharArrayDetector<
326 template<
typename T >
327 struct ExceptCharArrayDetector
332 struct ExceptCharArrayDetector< char[ N ] >
336 struct ExceptCharArrayDetector< const char[ N ] >
339 template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode[N]> {};
340 template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode const[N]> {};
341 template<>
struct ExceptCharArrayDetector<OUStringChar_> {};
345 template<
typename T1,
typename T2 =
void >
348 static const bool ok =
false;
350 template<
typename T >
354 static const bool ok =
true;
356 template<
typename T >
360 static const bool ok =
true;
364 template<
typename T,
bool >
369 template<
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
T Type
Definition: stringutils.hxx:192
static char const * toPointer(char const (&literal)[N])
Definition: stringutils.hxx:209
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