subsurface/core/subsurface-string.h
Berthold Stoeger ccdd92aeb7 preferences: use std::string in struct preferences
This is a messy commit, because the "qPref" system relies
heavily on QString, which means lots of conversions between
the two worlds. Ultimately, I plan to base the preferences
system on std::string and only convert to QString when
pushing through Qt's property system or when writing into
Qt's settings.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00

57 lines
1.3 KiB
C++

// SPDX-License-Identifier: GPL-2.0
#ifndef SUBSURFACE_STRING_H
#define SUBSURFACE_STRING_H
#include <algorithm>
#include <stdbool.h>
#include <string.h>
#include <time.h>
#include <string>
#include <string_view>
#include <vector>
// string handling
static inline bool same_string(const char *a, const char *b)
{
return !strcmp(a ?: "", b ?: "");
}
static inline bool same_string_caseinsensitive(const char *a, const char *b)
{
return !strcasecmp(a ?: "", b ?: "");
}
static inline bool empty_string(const char *s)
{
return !s || !*s;
}
extern double permissive_strtod(const char *str, const char **ptr);
extern double ascii_strtod(const char *str, const char **ptr);
// Sadly, starts_with only with C++20!
inline bool starts_with(std::string_view s, const char *s2)
{
return s.rfind(s2, 0) == 0;
}
// Sadly, std::string::contains only with C++23!
inline bool contains(std::string_view s, char c)
{
return s.find(c) != std::string::npos;
}
inline bool contains(std::string_view haystack, const char *needle)
{
return haystack.find(needle) != std::string::npos;
}
inline bool contains(std::string_view haystack, const std::string &needle)
{
return haystack.find(needle) != std::string::npos;
}
std::string join(const std::vector<std::string> &l, const std::string &separator, bool skip_empty = false);
#endif // SUBSURFACE_STRING_H