14 #ifndef INCLUDED_RTL_STRINGUTILS_HXX 15 #define INCLUDED_RTL_STRINGUTILS_HXX 22 #if defined LIBO_INTERNAL_ONLY 23 #include <type_traits> 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}; }
111 using OUStringChar = OUStringChar_
const;
116 namespace libreoffice_internal
147 template<
typename T1,
typename T2 =
void >
150 static const bool ok =
false;
152 template<
typename T >
156 static const bool ok =
true;
158 template<
typename T >
162 static const bool ok =
true;
164 #if defined LIBO_INTERNAL_ONLY 166 template<
typename T>
struct CharPtrDetector<
sal_Unicode const *, T> {
using TypeUtf16 = T; };
167 template<
typename T>
struct CharPtrDetector<
sal_Unicode[], T> {
using TypeUtf16 = T; };
168 template<
typename T>
struct CharPtrDetector<
sal_Unicode const[], T> {
using TypeUtf16 = T; };
171 template<
typename T1,
typename T2 >
175 template<
typename T,
int N >
180 #ifdef RTL_STRING_UNITTEST 182 template<
typename T >
187 template<
typename T >
188 struct NonConstCharArrayDetector< const char[], T >
193 #if defined LIBO_INTERNAL_ONLY 194 template<
typename T, std::
size_t N>
struct NonConstCharArrayDetector<
sal_Unicode[N], T> {
199 template<
typename T1,
typename T2 =
void >
202 static const bool ok =
false;
204 template< 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__) 230 template<
typename T >
231 struct 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) 251 template<std::
size_t N,
typename T>
252 struct 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 270 template<std::
size_t N,
typename T>
271 struct 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__) 292 struct 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';
305 template<
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 322 template<
typename T >
323 struct ExceptConstCharArrayDetector
328 struct ExceptConstCharArrayDetector< const char[ N ] >
331 template<std::
size_t N>
332 struct ExceptConstCharArrayDetector<
sal_Unicode const[N]> {};
333 template<>
struct ExceptConstCharArrayDetector<
342 template<
typename T >
343 struct ExceptCharArrayDetector
348 struct ExceptCharArrayDetector< char[ N ] >
352 struct ExceptCharArrayDetector< const char[ N ] >
355 template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode[N]> {};
356 template<std::
size_t N>
struct ExceptCharArrayDetector<
sal_Unicode const[N]> {};
357 template<>
struct ExceptCharArrayDetector<OUStringChar_> {};
361 template<
typename T1,
typename T2 =
void >
364 static const bool ok =
false;
366 template<
typename T >
370 static const bool ok =
true;
372 template<
typename T >
376 static const bool ok =
true;
380 template<
typename T,
bool >
385 template<
typename T >
396 #endif // INCLUDED_RTL_STRINGUTILS_HXX T Type
Definition: stringutils.hxx:207
T Type
Definition: stringutils.hxx:369
Definition: stringutils.hxx:146
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:587
Definition: stringutils.hxx:200
T Type
Definition: stringutils.hxx:161
static const bool ok
Definition: stringutils.hxx:364
T Type
Definition: stringutils.hxx:178
Definition: stringutils.hxx:381
sal_uInt16 sal_Unicode
Definition: types.h:123
Definition: stringutils.hxx:362
static const bool ok
Definition: stringutils.hxx:202
Definition: bootstrap.hxx:33
T Type
Definition: stringutils.hxx:388
T Type
Definition: stringutils.hxx:375
static bool isValid(char const (&literal)[N])
Definition: stringutils.hxx:213
Definition: stringutils.hxx:172
Definition: stringutils.hxx:148
static const bool ok
Definition: stringutils.hxx:150
T Type
Definition: stringutils.hxx:155
static char const * toPointer(char const (&literal)[N])
Definition: stringutils.hxx:224