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
137 template<
typename T1,
typename T2 =
void >
140 static const bool ok =
false;
142 template<
typename T >
146 static const bool ok =
true;
148 template<
typename T >
152 static const bool ok =
true;
154 #if defined LIBO_INTERNAL_ONLY
156 template<
typename T>
struct CharPtrDetector<
sal_Unicode const *, T> {
using TypeUtf16 = T; };
157 template<
typename T>
struct CharPtrDetector<
sal_Unicode[], T> {
using TypeUtf16 = T; };
158 template<
typename T>
struct CharPtrDetector<
sal_Unicode const[], T> {
using TypeUtf16 = T; };
161 template<
typename T1,
typename T2 >
165 template<
typename T,
int N >
170 #ifdef RTL_STRING_UNITTEST
172 template<
typename T >
177 template<
typename T >
178 struct NonConstCharArrayDetector< const char[], T >
183 #if defined LIBO_INTERNAL_ONLY
184 template<
typename T, std::
size_t N>
struct NonConstCharArrayDetector<
sal_Unicode[N], T> {
189 template<
typename T1,
typename T2 =
void >
192 static const bool ok =
false;
194 template< std::
size_t N,
typename T >
198 static const std::size_t length = N - 1;
199 static const bool ok =
true;
200 #if defined LIBO_INTERNAL_ONLY
203 static bool isValid(
char const (& literal)[N]) {
204 for (std::size_t i = 0; i != N - 1; ++i) {
205 if (literal[i] ==
'\0') {
209 return literal[N - 1] ==
'\0';
211 #if defined LIBO_INTERNAL_ONLY
214 static char const *
toPointer(
char const (& literal)[N]) {
return literal; }
217 #if defined(__COVERITY__)
220 template<
typename T >
221 struct ConstCharArrayDetector< const char[ 1 ], T >
224 static const std::size_t length = 0;
225 static const bool ok =
true;
226 #if defined LIBO_INTERNAL_ONLY
229 static bool isValid(
char const (& literal)[1]) {
230 return literal[0] ==
'\0';
232 #if defined LIBO_INTERNAL_ONLY
235 static char const * toPointer(
char const (& literal)[1]) {
return literal; }
239 #if defined LIBO_INTERNAL_ONLY && defined __cpp_char8_t
240 template<std::
size_t N,
typename T>
241 struct ConstCharArrayDetector<char8_t const [N], T> {
243 static constexpr
bool const ok =
true;
244 static constexpr std::size_t
const length = N - 1;
245 static constexpr
bool isValid(char8_t
const (& literal)[N]) {
246 for (std::size_t i = 0; i != N - 1; ++i) {
247 if (literal[i] == u8
'\0') {
251 return literal[N - 1] == u8
'\0';
253 static constexpr
char const * toPointer(char8_t
const (& literal)[N])
254 {
return reinterpret_cast<char const *
>(literal); }
258 #if defined LIBO_INTERNAL_ONLY
259 template<std::
size_t N,
typename T>
260 struct ConstCharArrayDetector<
sal_Unicode const [N], T> {
262 static constexpr
bool const ok =
true;
263 static constexpr std::size_t
const length = N - 1;
264 static constexpr
bool isValid(
sal_Unicode const (& literal)[N]) {
265 for (std::size_t i = 0; i != N - 1; ++i) {
266 if (literal[i] ==
'\0') {
270 return literal[N - 1] ==
'\0';
277 #if defined(__COVERITY__)
281 struct ConstCharArrayDetector<
sal_Unicode const [1], T> {
283 static constexpr
bool const ok =
true;
284 static constexpr std::size_t
const length = 0;
285 static constexpr
bool isValid(
sal_Unicode const (& literal)[1]) {
286 return literal[0] ==
'\0';
294 template<
typename T>
struct ConstCharArrayDetector<
299 static constexpr
bool const ok =
true;
300 static constexpr std::size_t
const length = 1;
301 static constexpr
bool isValid(OUStringChar) {
return true; }
303 OUStringChar_
const & literal)
304 {
return &literal.c; }
308 #if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
311 template<
typename T >
312 struct ExceptConstCharArrayDetector
317 struct ExceptConstCharArrayDetector< const char[ N ] >
320 template<std::
size_t N>
321 struct ExceptConstCharArrayDetector<
sal_Unicode const[N]> {};
322 template<>
struct ExceptConstCharArrayDetector<
331 template<
typename T >
332 struct ExceptCharArrayDetector
337 struct ExceptCharArrayDetector< char[ N ] >
341 struct ExceptCharArrayDetector< const char[ N ] >
344 template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode[N]> {};
345 template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode const[N]> {};
346 template<>
struct ExceptCharArrayDetector<OUStringChar_> {};
350 template<
typename T1,
typename T2 =
void >
353 static const bool ok =
false;
355 template<
typename T >
359 static const bool ok =
true;
361 template<
typename T >
365 static const bool ok =
true;
369 template<
typename T,
bool >
374 template<
typename T >
385 #endif // INCLUDED_RTL_STRINGUTILS_HXX
T Type
Definition: stringutils.hxx:168
T Type
Definition: stringutils.hxx:358
static bool isValid(char const (&literal)[N])
Definition: stringutils.hxx:203
T Type
Definition: stringutils.hxx:145
static const bool ok
Definition: stringutils.hxx:140
static const bool ok
Definition: stringutils.hxx:353
Definition: stringutils.hxx:370
T Type
Definition: stringutils.hxx:377
Definition: stringutils.hxx:190
T Type
Definition: stringutils.hxx:151
static char const * toPointer(char const (&literal)[N])
Definition: stringutils.hxx:214
T Type
Definition: stringutils.hxx:197
Definition: stringutils.hxx:162
Definition: stringutils.hxx:138
T Type
Definition: stringutils.hxx:364
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:587
Definition: stringutils.hxx:351
Definition: stringutils.hxx:136
static const bool ok
Definition: stringutils.hxx:192
sal_uInt16 sal_Unicode
Definition: types.h:123