mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
6b835710bc
This makes memory management more simple, as not explicit deletion is necessary. A rather large commit, because changing QVector<> to std::vector<> is propagated up the call chain. Adds a new range_contains() helper function for collection types such as std::vector<>. I didn't want to call it contains(), since we already have a contains function for strings and let's keep argument overloading simple. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
52 lines
1.2 KiB
C++
52 lines
1.2 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;
|
|
}
|
|
|
|
static inline char *copy_string(const char *s)
|
|
{
|
|
return (s && *s) ? strdup(s) : NULL;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
std::string join(const std::vector<std::string> &l, const std::string &separator, bool skip_empty = false);
|
|
|
|
#endif // SUBSURFACE_STRING_H
|