1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 21:35:45 +02:00
bees/include/crucible/string.h
Zygo Blaxell 6325f9ed72 lib: deprecate memset_zero template, use C99 compound literals instead
Sprinkle in some asserts to make sure compilers aren't getting creative.

This may introduce a new compiler dependency, as I suspect older versions
of GCC don't support this syntax.

It definitely needs a new compiler flag to suppress a warning when some
fields are not explicitly initialized.  If we've omitted a field, it's
because it's a field we don't know (or care) about, and we want that
thing initialized to zero.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2021-11-29 21:27:48 -05:00

51 lines
1.0 KiB
C++

#ifndef CRUCIBLE_STRING_H
#define CRUCIBLE_STRING_H
#include "crucible/error.h"
#include <cstdint>
#include <cstring>
#include <string>
#include <vector>
namespace crucible {
using namespace std;
// int->hex conversion with sprintf
string to_hex(uint64_t i);
// hex->int conversion with stoull
uint64_t from_hex(const string &s);
// asprintf with string output and exceptions
template<class... Args>
string
astringprintf(const char *fmt, Args... args)
{
char *rv = NULL;
DIE_IF_MINUS_ONE(asprintf(&rv, fmt, args...));
string rv_string = rv;
free(rv);
return rv_string;
}
template<class... Args>
string
astringprintf(const string &fmt, Args... args)
{
return astringprintf(fmt.c_str(), args...);
}
vector<string> split(string delim, string s);
// Shut up and give me the difference between two pointers
template <class P1, class P2>
ptrdiff_t
pointer_distance(const P1 *a, const P2 *b)
{
return reinterpret_cast<const uint8_t *>(a) - reinterpret_cast<const uint8_t *>(b);
}
};
#endif // CRUCIBLE_STRING_H