SDL3pp
A slim C++ wrapper for SDL3
|
SDL provides its own implementation of some of the most important C runtime functions. More...
Classes | |
class | SDL::Time |
SDL times are signed, 64-bit integers representing nanoseconds since the Unix epoch (Jan 1, 1970). More... | |
struct | SDL::EnvironmentBase |
A thread-safe set of environment variables. More... | |
struct | SDL::EnvironmentRef |
Handle to a non owned environment. More... | |
struct | SDL::Environment |
Handle to an owned environment. More... | |
class | SDL::Random |
A independent pseudo random state. More... | |
struct | SDL::IConvBase |
An opaque handle representing string encoding conversion state. More... | |
struct | SDL::IConvRef |
Handle to a non owned iConv. More... | |
struct | SDL::IConv |
Handle to an owned iConv. More... | |
Macros | |
#define | SDL_NOLONGLONG 1 |
Don't let SDL use "long long" C types. | |
#define | SDL_SIZE_MAX SIZE_MAX |
The largest value that a size_t can hold for the target platform. | |
#define | SDL_STRINGIFY_ARG(arg) #arg |
Macro useful for building other macros with strings in them. | |
#define | SDL_SINT64_C(c) c##LL /* or whatever the current compiler uses. */ |
Append the 64 bit integer suffix to a signed integer literal. | |
#define | SDL_UINT64_C(c) c##ULL /* or whatever the current compiler uses. */ |
Append the 64 bit integer suffix to an unsigned integer literal. | |
#define | SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */ |
Epsilon constant, used for comparing floating-point numbers. | |
#define | SDL_INIT_INTERFACE(iface) |
A macro to initialize an SDL interface. | |
#define | SDL_copyp(dst, src) |
A macro to copy memory between objects, with basic type checking. | |
#define | SDL_ICONV_ERROR (size_t)-1 |
Generic error. | |
#define | SDL_ICONV_E2BIG (size_t)-2 |
Output buffer was too small. | |
#define | SDL_ICONV_EILSEQ (size_t)-3 |
Invalid input sequence was encountered. | |
#define | SDL_ICONV_EINVAL (size_t)-4 |
Incomplete input sequence was encountered. | |
#define | SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S) + 1) |
Convert a UTF-8 string to the current locale's character encoding. | |
#define | SDL_iconv_utf8_ucs2(S) (Uint16*)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S) + 1) |
Convert a UTF-8 string to UCS-2. | |
#define | SDL_iconv_utf8_ucs4(S) (Uint32*)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S) + 1) |
Convert a UTF-8 string to UCS-4. | |
#define | SDL_iconv_wchar_utf8(S) |
Convert a wchar_t string to UTF-8. | |
Typedefs | |
using | SDL::Seconds = std::chrono::duration< float > |
Duration in seconds (float). | |
using | SDL::Nanoseconds = std::chrono::nanoseconds |
Duration in Nanoseconds (Sint64). | |
using | SDL::malloc_func = SDL_malloc_func |
A callback used to implement malloc(). | |
using | SDL::calloc_func = SDL_calloc_func |
A callback used to implement calloc(). | |
using | SDL::realloc_func = SDL_realloc_func |
A callback used to implement realloc(). | |
using | SDL::free_func = SDL_free_func |
A callback used to implement free(). | |
using | SDL::CompareCallback = SDL_CompareCallback |
A callback used with SDL sorting and binary search functions. | |
using | SDL::CompareCallback_r = SDL_CompareCallback_r |
A callback used with SDL sorting and binary search functions. | |
using | SDL::CompareCB = std::function< int(const void *, const void *)> |
A callback used with SDL sorting and binary search functions. | |
using | SDL::FunctionPointer = SDL_FunctionPointer |
A generic function pointer. | |
Functions | |
template<class T , std::size_t N> | |
constexpr std::size_t | SDL::arraysize (const T(&array)[N]) |
The number of elements in a static array. | |
constexpr Uint32 | SDL::FourCC (Uint8 a, Uint8 b, Uint8 c, Uint8 d) |
Define a four character code as a Uint32. | |
constexpr float | SDL::ToSeconds (Seconds duration) |
Converts a time duration to seconds (float). | |
constexpr Seconds | SDL::FromSeconds (float duration) |
Converts a float to seconds representation. | |
constexpr Sint64 | SDL::ToNS (std::chrono::nanoseconds duration) |
Converts a time duration to nanoseconds (Sint64);. | |
constexpr Nanoseconds | SDL::FromNS (Sint64 duration) |
Converts a Sint64 to nanoseconds representation. | |
void * | SDL::malloc (size_t size) |
Allocate uninitialized memory. | |
void * | SDL::calloc (size_t nmemb, size_t size) |
Allocate a zero-initialized array. | |
void * | SDL::realloc (void *mem, size_t size) |
Change the size of allocated memory. | |
void | SDL::free (void *mem) |
Free allocated memory. | |
void | SDL::GetOriginalMemoryFunctions (malloc_func *malloc_func, calloc_func *calloc_func, realloc_func *realloc_func, free_func *free_func) |
Get the original set of SDL memory functions. | |
void | SDL::GetMemoryFunctions (malloc_func *malloc_func, calloc_func *calloc_func, realloc_func *realloc_func, free_func *free_func) |
Get the current set of SDL memory functions. | |
void | SDL::SetMemoryFunctions (malloc_func malloc_func, calloc_func calloc_func, realloc_func realloc_func, free_func free_func) |
Replace SDL's memory allocation functions with a custom set. | |
void * | SDL::aligned_alloc (size_t alignment, size_t size) |
Allocate memory aligned to a specific alignment. | |
void | SDL::aligned_free (void *mem) |
Free memory allocated by aligned_alloc(). | |
int | SDL::GetNumAllocations () |
Get the number of outstanding (unfreed) allocations. | |
EnvironmentRef | SDL::GetEnvironment () |
Get the process environment. | |
const char * | SDL::getenv (StringParam name) |
Get the value of a variable in the environment. | |
const char * | SDL::getenv_unsafe (StringParam name) |
Get the value of a variable in the environment. | |
int | SDL::setenv_unsafe (StringParam name, StringParam value, int overwrite) |
Set the value of a variable in the environment. | |
int | SDL::unsetenv_unsafe (StringParam name) |
Clear a variable from the environment. | |
void | SDL::qsort (void *base, size_t nmemb, size_t size, CompareCallback compare) |
Sort an array. | |
void * | SDL::bsearch (const void *key, const void *base, size_t nmemb, size_t size, CompareCallback compare) |
Perform a binary search on a previously sorted array. | |
void | SDL::qsort_r (void *base, size_t nmemb, size_t size, CompareCallback_r compare, void *userdata) |
Sort an array, passing a userdata pointer to the compare function. | |
void | SDL::qsort_r (void *base, size_t nmemb, size_t size, CompareCB compare) |
Sort an array, passing a userdata pointer to the compare function. | |
void * | SDL::bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, CompareCallback_r compare, void *userdata) |
Perform a binary search on a previously sorted array, passing a userdata pointer to the compare function. | |
void * | SDL::bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, CompareCB compare) |
Perform a binary search on a previously sorted array, passing a userdata pointer to the compare function. | |
int | SDL::abs (int x) |
Compute the absolute value of x . | |
double | SDL::abs (double x) |
Compute the absolute value of x | |
float | SDL::abs (float x) |
Compute the absolute value of x | |
template<class T , class U > | |
constexpr T | SDL::min (T x, U y) |
Return the lesser of two values. | |
template<class T , class U > | |
constexpr T | SDL::max (T x, U y) |
Return the greater of two values. | |
template<class T , class U , class V > | |
constexpr T | SDL::clamp (T x, U a, V b) |
Return a value clamped to a range. | |
int | SDL::isalpha (int x) |
Query if a character is alphabetic (a letter). | |
int | SDL::isalnum (int x) |
Query if a character is alphabetic (a letter) or a number. | |
int | SDL::isblank (int x) |
Report if a character is blank (a space or tab). | |
int | SDL::iscntrl (int x) |
Report if a character is a control character. | |
int | SDL::isdigit (int x) |
Report if a character is a numeric digit. | |
int | SDL::isxdigit (int x) |
Report if a character is a hexadecimal digit. | |
int | SDL::ispunct (int x) |
Report if a character is a punctuation mark. | |
int | SDL::isspace (int x) |
Report if a character is whitespace. | |
int | SDL::isupper (int x) |
Report if a character is upper case. | |
int | SDL::islower (int x) |
Report if a character is lower case. | |
int | SDL::isprint (int x) |
Report if a character is "printable". | |
int | SDL::isgraph (int x) |
Report if a character is any "printable" except space. | |
int | SDL::toupper (int x) |
Convert low-ASCII English letters to uppercase. | |
int | SDL::tolower (int x) |
Convert low-ASCII English letters to lowercase. | |
Uint16 | SDL::crc16 (Uint16 crc, const void *data, size_t len) |
Calculate a CRC-16 value. | |
Uint32 | SDL::crc32 (Uint32 crc, const void *data, size_t len) |
Calculate a CRC-32 value. | |
Uint32 | SDL::murmur3_32 (const void *data, size_t len, Uint32 seed) |
Calculate a 32-bit MurmurHash3 value for a block of data. | |
void * | SDL::memcpy (void *dst, const void *src, size_t len) |
Copy non-overlapping memory. | |
void * | SDL::memmove (void *dst, const void *src, size_t len) |
Copy memory ranges that might overlap. | |
void * | SDL::memset (void *dst, int c, size_t len) |
Initialize all bytes of buffer of memory to a specific value. | |
void * | SDL::memset4 (void *dst, Uint32 val, size_t dwords) |
Initialize all 32-bit words of buffer of memory to a specific value. | |
template<class T > | |
void | SDL::zero (T &x) |
Clear an object's memory to zero. | |
template<class T > | |
void | SDL::zerop (T *x) |
Clear an object's memory to zero, using a pointer. | |
template<class T , std::size_t N> | |
void | SDL::zeroa (T(&x)[N]) |
Clear an array's memory to zero. | |
int | SDL::memcmp (const void *s1, const void *s2, size_t len) |
Compare two buffers of memory. | |
size_t | SDL::wcslen (const wchar_t *wstr) |
This works exactly like wcslen() but doesn't require access to a C runtime. | |
size_t | SDL::wcsnlen (const wchar_t *wstr, size_t maxlen) |
This works exactly like wcsnlen() but doesn't require access to a C runtime. | |
size_t | SDL::wcslcpy (wchar_t *dst, const wchar_t *src, size_t maxlen) |
Copy a wide string. | |
size_t | SDL::wcslcat (wchar_t *dst, const wchar_t *src, size_t maxlen) |
Concatenate wide strings. | |
wchar_t * | SDL::wcsdup (const wchar_t *wstr) |
Allocate a copy of a wide string. | |
wchar_t * | SDL::wcsstr (const wchar_t *haystack, const wchar_t *needle) |
Search a wide string for the first instance of a specific substring. | |
wchar_t * | SDL::wcsnstr (const wchar_t *haystack, const wchar_t *needle, size_t maxlen) |
Search a wide string, up to n wide chars, for the first instance of a specific substring. | |
int | SDL::wcscmp (const wchar_t *str1, const wchar_t *str2) |
Compare two null-terminated wide strings. | |
int | SDL::wcsncmp (const wchar_t *str1, const wchar_t *str2, size_t maxlen) |
Compare two wide strings up to a number of wchar_t values. | |
int | SDL::wcscasecmp (const wchar_t *str1, const wchar_t *str2) |
Compare two null-terminated wide strings, case-insensitively. | |
int | SDL::wcsncasecmp (const wchar_t *str1, const wchar_t *str2, size_t maxlen) |
Compare two wide strings, case-insensitively, up to a number of wchar_t. | |
long | SDL::wcstol (const wchar_t *str, wchar_t **endp, int base) |
Parse a long from a wide string. | |
size_t | SDL::strlen (StringParam str) |
This works exactly like strlen() but doesn't require access to a C runtime. | |
size_t | SDL::strnlen (StringParam str, size_t maxlen) |
This works exactly like strnlen() but doesn't require access to a C runtime. | |
size_t | SDL::strlcpy (char *dst, StringParam src, size_t maxlen) |
Copy a string. | |
size_t | SDL::utf8strlcpy (char *dst, StringParam src, size_t dst_bytes) |
Copy an UTF-8 string. | |
size_t | SDL::strlcat (char *dst, StringParam src, size_t maxlen) |
Concatenate strings. | |
char * | SDL::strdup (StringParam str) |
Allocate a copy of a string. | |
char * | SDL::strndup (StringParam str, size_t maxlen) |
Allocate a copy of a string, up to n characters. | |
char * | SDL::strrev (char *str) |
Reverse a string's contents. | |
char * | SDL::strupr (char *str) |
Convert a string to uppercase. | |
char * | SDL::strlwr (char *str) |
Convert a string to lowercase. | |
char * | SDL::strchr (StringParam str, int c) |
Search a string for the first instance of a specific byte. | |
char * | SDL::strrchr (StringParam str, int c) |
Search a string for the last instance of a specific byte. | |
char * | SDL::strstr (StringParam haystack, StringParam needle) |
Search a string for the first instance of a specific substring. | |
char * | SDL::strnstr (StringParam haystack, StringParam needle, size_t maxlen) |
Search a string, up to n bytes, for the first instance of a specific substring. | |
char * | SDL::strcasestr (StringParam haystack, StringParam needle) |
Search a UTF-8 string for the first instance of a specific substring, case-insensitively. | |
char * | SDL::strtok_r (char *str, StringParam delim, char **saveptr) |
This works exactly like strtok_r() but doesn't require access to a C runtime. | |
size_t | SDL::utf8strlen (StringParam str) |
Count the number of codepoints in a UTF-8 string. | |
size_t | SDL::utf8strnlen (StringParam str, size_t bytes) |
Count the number of codepoints in a UTF-8 string, up to n bytes. | |
char * | SDL::itoa (int value, char *str, int radix) |
Convert an integer into a string. | |
char * | SDL::uitoa (unsigned int value, char *str, int radix) |
Convert an unsigned integer into a string. | |
char * | SDL::ltoa (long value, char *str, int radix) |
Convert a long integer into a string. | |
char * | SDL::ultoa (unsigned long value, char *str, int radix) |
Convert an unsigned long integer into a string. | |
int | SDL::atoi (StringParam str) |
Parse an int from a string. | |
double | SDL::atof (StringParam str) |
Parse a double from a string. | |
long | SDL::strtol (StringParam str, char **endp, int base) |
Parse a long from a string. | |
unsigned long | SDL::strtoul (StringParam str, char **endp, int base) |
Parse an unsigned long from a string. | |
double | SDL::strtod (StringParam str, char **endp) |
Parse a double from a string. | |
int | SDL::strcmp (StringParam str1, StringParam str2) |
Compare two null-terminated UTF-8 strings. | |
int | SDL::strncmp (StringParam str1, StringParam str2, size_t maxlen) |
Compare two UTF-8 strings up to a number of bytes. | |
int | SDL::strcasecmp (StringParam str1, StringParam str2) |
Compare two null-terminated UTF-8 strings, case-insensitively. | |
int | SDL::strncasecmp (StringParam str1, StringParam str2, size_t maxlen) |
Compare two UTF-8 strings, case-insensitively, up to a number of bytes. | |
char * | SDL::strpbrk (StringParam str, StringParam breakset) |
Searches a string for the first occurence of any character contained in a breakset, and returns a pointer from the string to that character. | |
Uint32 | SDL::StepUTF8 (const char **pstr, size_t *pslen) |
Decode a UTF-8 string, one Unicode codepoint at a time. | |
Uint32 | SDL::StepBackUTF8 (StringParam start, const char **pstr) |
Decode a UTF-8 string in reverse, one Unicode codepoint at a time. | |
char * | SDL::UCS4ToUTF8 (Uint32 codepoint, char *dst) |
Convert a single Unicode codepoint to UTF-8. | |
int | SDL::sscanf (StringParam text, SDL_SCANF_FORMAT_STRING const char *fmt,...) |
This works exactly like sscanf() but doesn't require access to a C runtime. | |
int | SDL::vsscanf (StringParam text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) |
This works exactly like vsscanf() but doesn't require access to a C runtime. | |
int | SDL::snprintf (char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt,...) |
This works exactly like snprintf() but doesn't require access to a C runtime. | |
int | SDL::swprintf (wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt,...) |
This works exactly like swprintf() but doesn't require access to a C runtime. | |
int | SDL::vsnprintf (char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) |
This works exactly like vsnprintf() but doesn't require access to a C runtime. | |
int | SDL::vswprintf (wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap) |
This works exactly like vswprintf() but doesn't require access to a C runtime. | |
int | SDL::asprintf (char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt,...) |
This works exactly like asprintf() but doesn't require access to a C runtime. | |
int | SDL::vasprintf (char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) |
This works exactly like vasprintf() but doesn't require access to a C runtime. | |
void | SDL::srand (Uint64 seed) |
Seeds the pseudo-random number generator. | |
Sint32 | SDL::rand (Sint32 n) |
Generate a pseudo-random number less than n for positive n. | |
float | SDL::randf () |
Generate a uniform pseudo-random floating point number less than 1.0. | |
Uint32 | SDL::rand_bits () |
Generate 32 pseudo-random bits. | |
double | SDL::acos (double x) |
Compute the arc cosine of x . | |
float | SDL::acos (float x) |
Compute the arc cosine of x . | |
double | SDL::asin (double x) |
Compute the arc sine of x . | |
float | SDL::asin (float x) |
Compute the arc sine of x . | |
double | SDL::atan (double x) |
Compute the arc tangent of x . | |
float | SDL::atan (float x) |
Compute the arc tangent of x . | |
double | SDL::atan2 (double y, double x) |
Compute the arc tangent of y / x , using the signs of x and y to adjust the result's quadrant. | |
float | SDL::atan2 (float y, float x) |
Compute the arc tangent of y / x , using the signs of x and y to adjust the result's quadrant. | |
double | SDL::ceil (double x) |
Compute the ceiling of x . | |
float | SDL::ceil (float x) |
Compute the ceiling of x . | |
double | SDL::copysign (double x, double y) |
Copy the sign of one floating-point value to another. | |
float | SDL::copysign (float x, float y) |
Copy the sign of one floating-point value to another. | |
double | SDL::cos (double x) |
Compute the cosine of x . | |
float | SDL::cos (float x) |
Compute the cosine of x . | |
double | SDL::exp (double x) |
Compute the exponential of x . | |
float | SDL::exp (float x) |
Compute the exponential of x . | |
double | SDL::floor (double x) |
Compute the floor of x . | |
float | SDL::floor (float x) |
Compute the floor of x . | |
double | SDL::trunc (double x) |
Truncate x to an integer. | |
float | SDL::trunc (float x) |
Truncate x to an integer. | |
double | SDL::fmod (double x, double y) |
Return the floating-point remainder of x / y | |
float | SDL::fmod (float x, float y) |
Return the floating-point remainder of x / y | |
int | SDL::isinf (double x) |
Return whether the value is infinity. | |
int | SDL::isinf (float x) |
Return whether the value is infinity. | |
int | SDL::isnan (double x) |
Return whether the value is NaN. | |
int | SDL::isnan (float x) |
Return whether the value is NaN. | |
double | SDL::log (double x) |
Compute the natural logarithm of x . | |
float | SDL::log (float x) |
Compute the natural logarithm of x . | |
double | SDL::log10 (double x) |
Compute the base-10 logarithm of x . | |
float | SDL::log10 (float x) |
Compute the base-10 logarithm of x . | |
double | SDL::modf (double x, double *y) |
Split x into integer and fractional parts. | |
float | SDL::modf (float x, float *y) |
Split x into integer and fractional parts. | |
double | SDL::pow (double x, double y) |
Raise x to the power y | |
float | SDL::pow (float x, float y) |
Raise x to the power y | |
double | SDL::round (double x) |
Round x to the nearest integer. | |
float | SDL::round (float x) |
Round x to the nearest integer. | |
long | SDL::lround (double x) |
Round x to the nearest integer representable as a long. | |
long | SDL::lround (float x) |
Round x to the nearest integer representable as a long. | |
double | SDL::scalbn (double x, int n) |
Scale x by an integer power of two. | |
float | SDL::scalbn (float x, int n) |
Scale x by an integer power of two. | |
double | SDL::sin (double x) |
Compute the sine of x . | |
float | SDL::sin (float x) |
Compute the sine of x . | |
double | SDL::sqrt (double x) |
Compute the square root of x . | |
float | SDL::sqrt (float x) |
Compute the square root of x . | |
double | SDL::tan (double x) |
Compute the tangent of x . | |
float | SDL::tan (float x) |
Compute the tangent of x . | |
OwnPtr< char > | SDL::iconv_string (StringParam tocode, StringParam fromcode, StringParam inbuf, size_t inbytesleft) |
Helper function to convert a string's encoding in one call. | |
bool | SDL::size_mul_check_overflow (size_t a, size_t b, size_t *ret) |
Multiply two integers, checking for overflow. | |
bool | SDL::size_add_check_overflow (size_t a, size_t b, size_t *ret) |
Add two integers, checking for overflow. | |
Variables | |
constexpr Sint8 | SDL::MAX_SINT8 = SDL_MAX_SINT8 |
constexpr Sint8 | SDL::MIN_SINT8 = SDL_MIN_SINT8 |
constexpr Uint8 | SDL::MAX_UINT8 = SDL_MAX_UINT8 |
constexpr Uint8 | SDL::MIN_UINT8 = SDL_MIN_UINT8 |
constexpr Sint16 | SDL::MAX_SINT16 = SDL_MAX_SINT16 |
constexpr Sint16 | SDL::MIN_SINT16 = SDL_MIN_SINT16 |
constexpr Uint16 | SDL::MAX_UINT16 = SDL_MAX_UINT16 |
constexpr Uint16 | SDL::MIN_UINT16 = SDL_MIN_UINT16 |
constexpr Sint32 | SDL::MAX_SINT32 = SDL_MAX_SINT32 |
constexpr Sint32 | SDL::MIN_SINT32 = SDL_MIN_SINT32 |
constexpr Uint32 | SDL::MAX_UINT32 = SDL_MAX_UINT32 |
constexpr Uint8 | SDL::MIN_UINT32 = SDL_MIN_UINT32 |
constexpr Sint64 | SDL::MAX_SINT64 = SDL_MAX_SINT64 |
constexpr Sint64 | SDL::MIN_SINT64 = SDL_MIN_SINT64 |
constexpr Uint64 | SDL::MAX_UINT64 = SDL_MAX_UINT64 |
constexpr Uint8 | SDL::MIN_UINT64 = SDL_MIN_UINT64 |
constexpr Time | SDL::MAX_TIME = Time::FromNS(SDL_MAX_TIME) |
constexpr Time | SDL::MIN_TIME = Time::FromNS(SDL_MIN_TIME) |
constexpr Uint32 | SDL::INVALID_UNICODE_CODEPOINT = SDL_INVALID_UNICODE_CODEPOINT |
The Unicode REPLACEMENT CHARACTER codepoint. | |
constexpr double | SDL::PI_D = SDL_PI_D |
The value of Pi, as a double-precision floating point literal. | |
constexpr float | SDL::PI_F = SDL_PI_F |
The value of Pi, as a single-precision floating point literal. | |
Using these functions allows an app to have access to common C functionality without depending on a specific C runtime (or a C runtime at all). More importantly, the SDL implementations work identically across platforms, so apps can avoid surprises like snprintf() behaving differently between Windows and Linux builds, or itoa() only existing on some platforms.
For many of the most common functions, like SDL_memcpy, SDL might just call through to the usual C runtime behind the scenes, if it makes sense to do so (if it's faster and always available/reliable on a given platform), reducing library size and offering the most optimized option.
SDL also offers other C-runtime-adjacent functionality in this header that either isn't, strictly speaking, part of any C runtime standards, like SDL_crc32() and SDL_reinterpret_cast, etc. It also offers a few better options, like SDL_strlcpy(), which functions as a safer form of strcpy().
#define SDL_copyp | ( | dst, | |
src | |||
) |
memcpy and memmove do not care where you copy memory to and from, which can lead to bugs. This macro aims to avoid most of those bugs by making sure that the source and destination are both pointers to objects that are the same size. It does not check that the objects are the same type, just that the copy will not overflow either object.
The size check happens at compile time, and the compiler will throw an error if the objects are different sizes.
Generally this is intended to copy a single object, not an array.
This macro looks like it double-evaluates its parameters, but the extras them are in sizeof
sections, which generate no code nor side-effects.
dst | a pointer to the destination object. Must not be nullptr. |
src | a pointer to the source object. Must not be nullptr. |
#define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */ |
Equals by default to platform-defined FLT_EPSILON
, or 1.1920928955078125e-07F
if that's not available.
#define SDL_ICONV_ERROR (size_t)-1 |
Check GetError()?
#define SDL_iconv_utf8_locale | ( | S | ) | SDL_iconv_string("", "UTF-8", S, SDL_strlen(S) + 1) |
This is a helper macro that might be more clear than calling iconv_string directly. However, it double-evaluates its parameter, so do not use an expression with side-effects here.
S | the string to convert. |
#define SDL_iconv_utf8_ucs2 | ( | S | ) | (Uint16*)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S) + 1) |
This is a helper macro that might be more clear than calling iconv_string directly. However, it double-evaluates its parameter, so do not use an expression with side-effects here.
S | the string to convert. |
#define SDL_iconv_utf8_ucs4 | ( | S | ) | (Uint32*)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S) + 1) |
This is a helper macro that might be more clear than calling iconv_string directly. However, it double-evaluates its parameter, so do not use an expression with side-effects here.
S | the string to convert. |
#define SDL_iconv_wchar_utf8 | ( | S | ) |
This is a helper macro that might be more clear than calling iconv_string directly. However, it double-evaluates its parameter, so do not use an expression with side-effects here.
S | the string to convert. |
#define SDL_INIT_INTERFACE | ( | iface | ) |
This macro will initialize an SDL interface structure and should be called before you fill out the fields with your implementation.
You can use it like this:
If you are using designated initializers, you can use the size of the interface as the version, e.g.
#define SDL_NOLONGLONG 1 |
SDL will define this if it believes the compiler doesn't understand the "long long" syntax for C datatypes. This can happen on older compilers.
If your compiler doesn't support "long long" but SDL doesn't know it, it is safe to define this yourself to build against the SDL headers.
If this is defined, it will remove access to some C runtime support functions, like SDL_ulltoa and SDL_strtoll that refer to this datatype explicitly. The rest of SDL will still be available.
SDL's own source code cannot be built with a compiler that has this defined, for various technical reasons.
#define SDL_SINT64_C | ( | c | ) | c##LL /* or whatever the current compiler uses. */ |
This helps compilers that might believe a integer literal larger than 0xFFFFFFFF is overflowing a 32-bit value. Use SDL_SINT64_C(0xFFFFFFFF1)
instead of 0xFFFFFFFF1
by itself.
#define SDL_SIZE_MAX SIZE_MAX |
size_t
is generally the same size as a pointer in modern times, but this can get weird on very old and very esoteric machines. For example, on a 16-bit Intel 286, you might have a 32-bit "far" pointer (16-bit segment plus 16-bit offset), but size_t
is 16 bits, because it can only deal with the offset into an individual segment.
In modern times, it's generally expected to cover an entire linear address space. But be careful!
#define SDL_STRINGIFY_ARG | ( | arg | ) | #arg |
For example:
arg | the text to turn into a string literal. |
#define SDL_UINT64_C | ( | c | ) | c##ULL /* or whatever the current compiler uses. */ |
This helps compilers that might believe a integer literal larger than 0xFFFFFFFF is overflowing a 32-bit value. Use SDL_UINT64_C(0xFFFFFFFF1)
instead of 0xFFFFFFFF1
by itself.
using SDL::calloc_func = typedef SDL_calloc_func |
SDL will always ensure that the passed nmemb
and size
are both greater than 0.
nmemb | the number of elements in the array. |
size | the size of each element of the array. |
using SDL::CompareCallback = typedef SDL_CompareCallback |
a | a pointer to the first element being compared. |
b | a pointer to the second element being compared. |
a
should be sorted before b
, 1 if b
should be sorted before a
, 0 if they are equal. If two elements are equal, their order in the sorted array is undefined.using SDL::CompareCallback_r = typedef SDL_CompareCallback_r |
userdata | the userdata pointer passed to the sort function. |
a | a pointer to the first element being compared. |
b | a pointer to the second element being compared. |
a
should be sorted before b
, 1 if b
should be sorted before a
, 0 if they are equal. If two elements are equal, their order in the sorted array is undefined.using SDL::CompareCB = typedef std::function<int(const void*, const void*)> |
a | a pointer to the first element being compared. |
b | a pointer to the second element being compared. |
a
should be sorted before b
, 1 if b
should be sorted before a
, 0 if they are equal. If two elements are equal, their order in the sorted array is undefined.using SDL::free_func = typedef SDL_free_func |
using SDL::FunctionPointer = typedef SDL_FunctionPointer |
In theory, generic function pointers should use this, instead of void *
, since some platforms could treat code addresses differently than data addresses. Although in current times no popular platforms make this distinction, it is more correct and portable to use the correct type for a generic pointer.
If for some reason you need to force this typedef to be an actual void *
, perhaps to work around a compiler or existing code, you can define SDL_FUNCTION_POINTER_IS_VOID_POINTER
before including any SDL headers.
using SDL::malloc_func = typedef SDL_malloc_func |
using SDL::realloc_func = typedef SDL_realloc_func |
SDL will always ensure that the passed size
is greater than 0.
mem | a pointer to allocated memory to reallocate, or nullptr. |
size | the new size of the memory. |
|
inline |
|
inline |
|
inline |
x | an integer value. |
|
inline |
The definition of y = acos(x)
is x = cos(y)
.
Domain: -1 <= x <= 1
Range: 0 <= y <= Pi
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. |
x
, in radians.
|
inline |
The definition of y = acos(x)
is x = cos(y)
.
Domain: -1 <= x <= 1
Range: 0 <= y <= Pi
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. |
x
, in radians.
|
inline |
The memory returned by this function must be freed with aligned_free(), not free().
If alignment
is less than the size of void *
, it will be increased to match that.
The returned memory address will be a multiple of the alignment value, and the size of the memory allocated will be a multiple of the alignment value.
alignment | the alignment of the memory. |
size | the size to allocate. |
|
inline |
The pointer is no longer valid after this call and cannot be dereferenced anymore.
If mem
is nullptr, this function does nothing.
mem | a pointer previously returned by aligned_alloc(), or nullptr. |
|
constexpr |
This will compile but return incorrect results for a pointer to an array; it has to be an array the compiler knows the size of.
|
inline |
The definition of y = asin(x)
is x = sin(y)
.
Domain: -1 <= x <= 1
Range: -Pi/2 <= y <= Pi/2
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. |
x
, in radians.
|
inline |
The definition of y = asin(x)
is x = sin(y)
.
Domain: -1 <= x <= 1
Range: -Pi/2 <= y <= Pi/2
This function operates on single-precision floating point values, use asin for double-precision floats.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. |
x
, in radians.
|
inline |
Functions identically to snprintf(), except it allocates a buffer large enough to hold the output string on behalf of the caller.
On success, this function returns the number of bytes (not characters) comprising the output string, not counting the null-terminator character, and sets *strp
to the newly-allocated string.
On error, this function returns a negative number, and the value of *strp
is undefined.
The returned string is owned by the caller, and should be passed to free when no longer needed.
strp | on output, is set to the new string. Must not be nullptr. |
fmt | a printf-style format string. Must not be nullptr. |
... | a list of values to be used with the format string. |
|
inline |
The definition of y = atan(x)
is x = tan(y)
.
Domain: -INF <= x <= INF
Range: -Pi/2 <= y <= Pi/2
To calculate the arc tangent of y / x, use atan2.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. |
x
in radians, or 0 if x = 0
.
|
inline |
The definition of y = atan(x)
is x = tan(y)
.
Domain: -INF <= x <= INF
Range: -Pi/2 <= y <= Pi/2
To calculate the arc tangent of y / x, use atan2f.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. |
x
in radians, or 0 if x = 0
.
|
inline |
The definition of z = atan2(x, y)
is y = x tan(z)
, where the quadrant of z is determined based on the signs of x and y.
Domain: -INF <= x <= INF
, -INF <= y <= INF
Range: -Pi/2 <= y <= Pi/2
This function operates on double-precision floating point values, use atan2f for single-precision floats.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
y | floating point value of the numerator (y coordinate). |
x | floating point value of the denominator (x coordinate). |
y / x
in radians, or, if x = 0
, either -Pi/2
, 0
, or Pi/2
, depending on the value of y
.
|
inline |
The definition of z = atan2(x, y)
is y = x tan(z)
, where the quadrant of z is determined based on the signs of x and y.
Domain: -INF <= x <= INF
, -INF <= y <= INF
Range: -Pi/2 <= y <= Pi/2
This function operates on single-precision floating point values, use atan2 for double-precision floats.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
y | floating point value of the numerator (y coordinate). |
x | floating point value of the denominator (x coordinate). |
y / x
in radians, or, if x = 0
, either -Pi/2
, 0
, or Pi/2
, depending on the value of y
.
|
inline |
The result of calling atof(str)
is equivalent to strtod(str,
nullptr)
.
str | The null-terminated string to read. Must not be nullptr. |
double
.
|
inline |
The result of calling atoi(str)
is equivalent to (int)strtol(str, nullptr, 10)
.
str | The null-terminated string to read. Must not be nullptr. |
int
.
|
inline |
For example:
key | a pointer to a key equal to the element being searched for. |
base | a pointer to the start of the array. |
nmemb | the number of elements in the array. |
size | the size of the elements in the array. |
compare | a function used to compare elements in the array. |
|
inline |
For example:
key | a pointer to a key equal to the element being searched for. |
base | a pointer to the start of the array. |
nmemb | the number of elements in the array. |
size | the size of the elements in the array. |
compare | a function used to compare elements in the array. |
userdata | a pointer to pass to the compare function. |
|
inline |
For example:
key | a pointer to a key equal to the element being searched for. |
base | a pointer to the start of the array. |
nmemb | the number of elements in the array. |
size | the size of the elements in the array. |
compare | a function used to compare elements in the array. |
|
inline |
The memory returned by this function must be freed with free().
If either of nmemb
or size
is 0, they will both be set to 1.
If the allocation is successful, the returned pointer is guaranteed to be aligned to either the fundamental alignment (alignof(max_align_t)
in C11 and later) or 2 * sizeof(void *)
, whichever is smaller.
nmemb | the number of elements in the array. |
size | the size of each element of the array. |
|
inline |
The ceiling of x
is the smallest integer y
such that y > x
, i.e x
rounded up to the nearest integer.
Domain: -INF <= x <= INF
Range: -INF <= y <= INF
, y integer
x | floating point value. |
x
.
|
inline |
The ceiling of x
is the smallest integer y
such that y > x
, i.e x
rounded up to the nearest integer.
Domain: -INF <= x <= INF
Range: -INF <= y <= INF
, y integer
x | floating point value. |
x
.
|
constexpr |
If x
is outside the range a values between a
and b
, the returned value will be a
or b
as appropriate. Otherwise, x
is returned.
This function will produce incorrect results if b
is less than a
.
This is a helper function that might be more clear than writing out the comparisons directly, and works with any type that can be compared with the <
and >
operators. However, it double-evaluates all its parameters, so do not use expressions with side-effects here.
x | the value to compare. |
a | the low end value. |
b | the high end value. |
|
inline |
The definition of copysign is that copysign(x, y) = abs(x) * sign(y)
.
Domain: -INF <= x <= INF
, -INF <= y <= f
Range: -INF <= z <= INF
x | floating point value to use as the magnitude. |
y | floating point value to use as the sign. |
|
inline |
The definition of copysign is that copysign(x, y) = abs(x) * sign(y)
.
Domain: -INF <= x <= INF
, -INF <= y <= f
Range: -INF <= z <= INF
x | floating point value to use as the magnitude. |
y | floating point value to use as the sign. |
|
inline |
Domain: -INF <= x <= INF
Range: -1 <= y <= 1
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value, in radians. |
x
.
|
inline |
Domain: -INF <= x <= INF
Range: -1 <= y <= 1
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value, in radians. |
x
.
|
inline |
https://en.wikipedia.org/wiki/Cyclic_redundancy_check
This function can be called multiple times, to stream data to be checksummed in blocks. Each call must provide the previous CRC-16 return value to be updated with the next block. The first call to this function for a set of blocks should pass in a zero CRC value.
crc | the current checksum for this data set, or 0 for a new data set. |
data | a new block of data to add to the checksum. |
len | the size, in bytes, of the new block of data. |
|
inline |
https://en.wikipedia.org/wiki/Cyclic_redundancy_check
This function can be called multiple times, to stream data to be checksummed in blocks. Each call must provide the previous CRC-32 return value to be updated with the next block. The first call to this function for a set of blocks should pass in a zero CRC value.
crc | the current checksum for this data set, or 0 for a new data set. |
data | a new block of data to add to the checksum. |
len | the size, in bytes, of the new block of data. |
|
inline |
The definition of y = exp(x)
is y = e^x
, where e
is the base of the natural logarithm. The inverse is the natural logarithm, log().
Domain: -INF <= x <= INF
Range: 0 <= y <= INF
The output will overflow if exp(x)
is too large to be represented.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. |
e^x
.
|
inline |
The definition of y = exp(x)
is y = e^x
, where e
is the base of the natural logarithm. The inverse is the natural logarithm, log().
Domain: -INF <= x <= INF
Range: 0 <= y <= INF
The output will overflow if exp(x)
is too large to be represented.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. |
e^x
.
|
inline |
The floor of x
is the largest integer y
such that y > x
, i.e x
rounded down to the nearest integer.
Domain: -INF <= x <= INF
Range: -INF <= y <= INF
, y integer
x | floating point value. |
x
.
|
inline |
The floor of x
is the largest integer y
such that y > x
, i.e x
rounded down to the nearest integer.
Domain: -INF <= x <= INF
Range: -INF <= y <= INF
, y integer
x | floating point value. |
x
.
|
inline |
Divides x
by y
, and returns the remainder.
Domain: -INF <= x <= INF
, -INF <= y <= INF
, y != 0
Range: -y <= z <= y
x | the numerator. |
y | the denominator. Must not be 0. |
x / y
.
|
inline |
Divides x
by y
, and returns the remainder.
Domain: -INF <= x <= INF
, -INF <= y <= INF
, y != 0
Range: -y <= z <= y
x | the numerator. |
y | the denominator. Must not be 0. |
x / y
.
|
constexpr |
a | the first ASCII character. |
b | the second ASCII character. |
c | the third ASCII character. |
d | the fourth ASCII character. |
|
inline |
The pointer is no longer valid after this call and cannot be dereferenced anymore.
If mem
is nullptr, this function does nothing.
mem | a pointer to allocated memory, or nullptr. |
|
inline |
This function uses SDL's cached copy of the environment and is thread-safe.
name | the name of the variable to get. |
|
inline |
This function bypasses SDL's cached copy of the environment and is not thread-safe.
name | the name of the variable to get. |
|
inline |
This is initialized at application start and is not affected by setenv() and unsetenv() calls after that point. Use EnvironmentBase.SetVariable() and EnvironmentBase.UnsetVariable() if you want to modify this environment, or setenv_unsafe() or unsetenv_unsafe() if you want changes to persist in the C runtime environment after Quit().
|
inline |
malloc_func | filled with malloc function. |
calloc_func | filled with calloc function. |
realloc_func | filled with realloc function. |
free_func | filled with free function. |
|
inline |
|
inline |
This is what malloc and friends will use by default, if there has been no call to SetMemoryFunctions. This is not necessarily using the C runtime's malloc
functions behind the scenes! Different platforms and build configurations might do any number of unexpected things.
malloc_func | filled with malloc function. |
calloc_func | filled with calloc function. |
realloc_func | filled with realloc function. |
free_func | filled with free function. |
|
inline |
This function converts a buffer or string between encodings in one pass.
The string does not need to be nullptr-terminated; this function operates on the number of bytes specified in inbytesleft
whether there is a nullptr character anywhere in the buffer.
tocode | the character encoding of the output string. Examples are "UTF-8", "UCS-4", etc. |
fromcode | the character encoding of data in inbuf . |
inbuf | the string to convert to a different encoding. |
inbytesleft | the size of the input string in bytes. |
|
inline |
WARNING: Regardless of system locale, this will only treat ASCII values for English 'a-z', 'A-Z', and '0-9' as true.
x | character value to check. |
|
inline |
WARNING: Regardless of system locale, this will only treat ASCII values for English 'a-z' and 'A-Z' as true.
x | character value to check. |
|
inline |
WARNING: Regardless of system locale, this will only treat ASCII values 0x20 (space) or 0x9 (tab) as true.
x | character value to check. |
|
inline |
WARNING: Regardless of system locale, this will only treat ASCII values 0 through 0x1F, and 0x7F, as true.
x | character value to check. |
|
inline |
WARNING: Regardless of system locale, this will only treat ASCII values '0' (0x30) through '9' (0x39), as true.
x | character value to check. |
|
inline |
Be advised that "printable" has a definition that goes back to text terminals from the dawn of computing, making this a sort of special case function that is not suitable for Unicode (or most any) text management.
WARNING: Regardless of system locale, this is equivalent to ‘(isprint(x)) && ((x) != ’ ')`.
x | character value to check. |
|
inline |
x | double-precision floating point value. |
|
inline |
x | floating point value. |
|
inline |
WARNING: Regardless of system locale, this will only treat ASCII values 'a' through 'z' as true.
x | character value to check. |
|
inline |
x | double-precision floating point value. |
|
inline |
x | floating point value. |
|
inline |
Be advised that "printable" has a definition that goes back to text terminals from the dawn of computing, making this a sort of special case function that is not suitable for Unicode (or most any) text management.
WARNING: Regardless of system locale, this will only treat ASCII values ' ' (0x20) through '~' (0x7E) as true.
x | character value to check. |
|
inline |
WARNING: Regardless of system locale, this is equivalent to ((isgraph(x)) && (!isalnum(x)))
.
x | character value to check. |
|
inline |
WARNING: Regardless of system locale, this will only treat the following ASCII values as true:
x | character value to check. |
|
inline |
WARNING: Regardless of system locale, this will only treat ASCII values 'A' through 'Z' as true.
x | character value to check. |
|
inline |
WARNING: Regardless of system locale, this will only treat ASCII values 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
x | character value to check. |
|
inline |
This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2 to 36.
Note that this function will overflow a buffer if str
is not large enough to hold the output! It may be safer to use snprintf to clamp output, or asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget possible negative signs, null terminator bytes, etc).
value | the integer to convert. |
str | the buffer to write the string into. |
radix | the radix to use for string generation. |
str
.
|
inline |
Domain: 0 < x <= INF
Range: -INF <= y <= INF
It is an error for x
to be less than or equal to 0.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. Must be greater than 0. |
x
.
|
inline |
Domain: 0 < x <= INF
Range: -INF <= y <= INF
It is an error for x
to be less than or equal to 0.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. Must be greater than 0. |
x
.
|
inline |
Domain: 0 < x <= INF
Range: -INF <= y <= INF
It is an error for x
to be less than or equal to 0.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. Must be greater than 0. |
x
.
|
inline |
Domain: 0 < x <= INF
Range: -INF <= y <= INF
It is an error for x
to be less than or equal to 0.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. Must be greater than 0. |
x
.
|
inline |
Rounds x
to the nearest integer. Values halfway between integers will be rounded away from zero.
Domain: -INF <= x <= INF
Range: MIN_LONG <= y <= MAX_LONG
x | floating point value. |
x
.
|
inline |
Rounds x
to the nearest integer. Values halfway between integers will be rounded away from zero.
Domain: -INF <= x <= INF
Range: MIN_LONG <= y <= MAX_LONG
x | floating point value. |
x
.
|
inline |
This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2 to 36.
Note that this function will overflow a buffer if str
is not large enough to hold the output! It may be safer to use snprintf to clamp output, or asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget possible negative signs, null terminator bytes, etc).
value | the long integer to convert. |
str | the buffer to write the string into. |
radix | the radix to use for string generation. |
str
.
|
inline |
The allocated memory returned by this function must be freed with free().
If size
is 0, it will be set to 1.
If the allocation is successful, the returned pointer is guaranteed to be aligned to either the fundamental alignment (alignof(max_align_t)
in C11 and later) or 2 * sizeof(void *)
, whichever is smaller. Use aligned_alloc() if you need to allocate memory aligned to an alignment greater than this guarantee.
size | the size to allocate. |
|
constexpr |
This is a helper function that might be more clear than writing out the comparisons directly, and works with any type that can be compared with the >
operator. However, it double-evaluates both its parameters, so do not use expressions with side-effects here.
x | the first value to compare. |
y | the second value to compare. |
x
and y
.
|
inline |
s1 | the first buffer to compare. nullptr is not permitted! |
s2 | the second buffer to compare. nullptr is not permitted! |
len | the number of bytes to compare between the buffers. |
len
bytes.
|
inline |
The memory regions must not overlap. If they do, use memmove() instead.
dst | The destination memory region. Must not be nullptr, and must not overlap with src . |
src | The source memory region. Must not be nullptr, and must not overlap with dst . |
len | The length in bytes of both dst and src . |
dst
.
|
inline |
It is okay for the memory regions to overlap. If you are confident that the regions never overlap, using memcpy() may improve performance.
dst | The destination memory region. Must not be nullptr. |
src | The source memory region. Must not be nullptr. |
len | The length in bytes of both dst and src . |
dst
.
|
inline |
This function will set len
bytes, pointed to by dst
, to the value specified in c
.
Despite c
being an int
instead of a char
, this only operates on bytes; c
must be a value between 0 and 255, inclusive.
dst | the destination memory region. Must not be nullptr. |
c | the byte value to set. |
len | the length, in bytes, to set in dst . |
dst
.
|
inline |
This function will set a buffer of dwords
Uint32 values, pointed to by dst
, to the value specified in val
.
Unlike memset, this sets 32-bit values, not bytes, so it's not limited to a range of 0-255.
dst | the destination memory region. Must not be nullptr. |
val | the Uint32 value to set. |
dwords | the number of Uint32 values to set in dst . |
dst
.
|
constexpr |
This is a helper macro that might be more clear than writing out the comparisons directly, and works with any type that can be compared with the <
operator. However, it double-evaluates both its parameters, so do not use expressions with side-effects here.
x | the first value to compare. |
y | the second value to compare. |
x
and y
.
|
inline |
|
inline |
|
inline |
https://en.wikipedia.org/wiki/MurmurHash
A seed may be specified, which changes the final results consistently, but this does not work like crc16 and crc32: you can't feed a previous result from this function back into itself as the next seed value to calculate a hash in chunks; it won't produce the same hash as it would if the same data was provided in a single call.
If you aren't sure what to provide for a seed, zero is fine. Murmur3 is not cryptographically secure, so it shouldn't be used for hashing top-secret data.
data | the data to be hashed. |
len | the size of data, in bytes. |
seed | a value that alters the final hash value. |
|
inline |
Domain: -INF <= x <= INF
, -INF <= y <= INF
Range: -INF <= z <= INF
If y
is the base of the natural logarithm (e), consider using exp instead.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | the base. |
y | the exponent. |
x
raised to the power y
.
|
inline |
Domain: -INF <= x <= INF
, -INF <= y <= INF
Range: -INF <= z <= INF
If y
is the base of the natural logarithm (e), consider using exp instead.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | the base. |
y | the exponent. |
x
raised to the power y
.
|
inline |
For example:
base | a pointer to the start of the array. |
nmemb | the number of elements in the array. |
size | the size of the elements in the array. |
compare | a function used to compare elements in the array. |
|
inline |
For example:
base | a pointer to the start of the array. |
nmemb | the number of elements in the array. |
size | the size of the elements in the array. |
compare | a function used to compare elements in the array. |
userdata | a pointer to pass to the compare function. |
|
inline |
For example:
base | a pointer to the start of the array. |
nmemb | the number of elements in the array. |
size | the size of the elements in the array. |
compare | a function used to compare elements in the array. |
|
inline |
The method used is faster and of better quality than rand() % n
. Odds are roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and much worse as n gets bigger.
Example: to simulate a d6 use rand(6) + 1
The +1 converts 0..5 to 1..6
If you want to generate a pseudo-random number in the full range of Sint32, you should use: (Sint32)rand_bits()
If you want reproducible output, be sure to initialize with srand() first.
There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.
n | the number of possible outcomes. n must be positive. |
|
inline |
You likely want to use rand() to get a pseudo-random number instead.
There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.
|
inline |
If you want reproducible output, be sure to initialize with srand() first.
There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.
|
inline |
The memory returned by this function must be freed with free().
If size
is 0, it will be set to 1. Note that this is unlike some other C runtime realloc
implementations, which may treat realloc(mem, 0)
the same way as free(mem)
.
If mem
is nullptr, the behavior of this function is equivalent to malloc(). Otherwise, the function can have one of three possible outcomes:
mem
, it means that mem
was resized in place without freeing.mem
was freed and cannot be dereferenced anymore.mem
will remain valid and must still be freed with free().If the allocation is successfully resized, the returned pointer is guaranteed to be aligned to either the fundamental alignment (alignof(max_align_t)
in C11 and later) or 2 * sizeof(void *)
, whichever is smaller.
mem | a pointer to allocated memory to reallocate, or nullptr. |
size | the new size of the memory. |
|
inline |
Rounds x
to the nearest integer. Values halfway between integers will be rounded away from zero.
Domain: -INF <= x <= INF
Range: -INF <= y <= INF
, y integer
x | floating point value. |
x
.
|
inline |
Rounds x
to the nearest integer. Values halfway between integers will be rounded away from zero.
Domain: -INF <= x <= INF
Range: -INF <= y <= INF
, y integer
x | floating point value. |
x
.
|
inline |
Multiplies x
by the n
th power of the floating point radix (always 2).
Domain: -INF <= x <= INF
, n
integer
Range: -INF <= y <= INF
x | floating point value to be scaled. |
n | integer exponent. |
x * 2^n
.
|
inline |
Multiplies x
by the n
th power of the floating point radix (always 2).
Domain: -INF <= x <= INF
, n
integer
Range: -INF <= y <= INF
x | floating point value to be scaled. |
n | integer exponent. |
x * 2^n
.
|
inline |
name | the name of the variable to set. |
value | the value of the variable to set. |
overwrite | 1 to overwrite the variable if it exists, 0 to return success without setting the variable if it already exists. |
|
inline |
It is not safe to call this function once any allocations have been made, as future calls to free will use the new allocator, even if they came from an malloc made with the old one!
If used, usually this needs to be the first call made into the SDL library, if not the very first thing done at program startup time.
malloc_func | custom malloc function. |
calloc_func | custom calloc function. |
realloc_func | custom realloc function. |
free_func | custom free function. |
Error | on failure. |
|
inline |
Domain: -INF <= x <= INF
Range: -1 <= y <= 1
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value, in radians. |
x
.
|
inline |
Domain: -INF <= x <= INF
Range: -1 <= y <= 1
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value, in radians. |
x
.
|
inline |
If a + b
would overflow, return false.
Otherwise store a + b
via ret and return true.
a | the first addend. |
b | the second addend. |
ret | on non-overflow output, stores the addition result, may not be nullptr. |
|
inline |
If a * b
would overflow, return false.
Otherwise store a * b
via ret and return true.
a | the multiplicand. |
b | the multiplier. |
ret | on non-overflow output, stores the multiplication result, may not be nullptr. |
|
inline |
Format a string of up to maxlen
-1 bytes, converting each '' item with values provided through variable arguments.
While some C runtimes differ on how to deal with too-large strings, this function null-terminates the output, by treating the null-terminator as part of the maxlen
count. Note that if maxlen
is zero, however, no bytes will be written at all.
This function returns the number of bytes (not characters) that should be written, excluding the null-terminator character. If this returns a number >= maxlen
, it means the output string was truncated. A negative return value means an error occurred.
Referencing the output string's pointer with a format item is undefined behavior.
text | the buffer to write the string into. Must not be nullptr. |
maxlen | the maximum bytes to write, including the null-terminator. |
fmt | a printf-style format string. Must not be nullptr. |
... | a list of values to be used with the format string. |
|
inline |
Domain: 0 <= x <= INF
Range: 0 <= y <= INF
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. Must be greater than or equal to 0. |
x
.
|
inline |
Domain: 0 <= x <= INF
Range: 0 <= y <= INF
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value. Must be greater than or equal to 0. |
x
.
|
inline |
Reusing the seed number will cause rand() to repeat the same stream of 'random' numbers.
seed | the value to use as a random number seed, or 0 to use GetPerformanceCounter(). |
|
inline |
Scan a string, matching a format string, converting each '' item and storing it to pointers provided through variable arguments.
text | the string to scan. Must not be nullptr. |
fmt | a printf-style format string. Must not be nullptr. |
... | a list of pointers to values to be filled in with scanned items. |
|
inline |
This will go to the start of the previous Unicode codepoint in the string, move *pstr
to that location and return that codepoint.
If *pstr
is already at the start of the string), it will not advance *pstr
at all.
Generally this function is called in a loop until it returns zero, adjusting its parameter each iteration.
If an invalid UTF-8 sequence is encountered, this function returns INVALID_UNICODE_CODEPOINT.
Several things can generate invalid UTF-8 sequences, including overlong encodings, the use of UTF-16 surrogate values, and truncated data. Please refer to RFC3629 for details.
start | a pointer to the beginning of the UTF-8 string. |
pstr | a pointer to a UTF-8 string pointer to be read and adjusted. |
|
inline |
This will return the first Unicode codepoint in the UTF-8 encoded string in *pstr
, and then advance *pstr
past any consumed bytes before returning.
It will not access more than *pslen
bytes from the string. *pslen
will be adjusted, as well, subtracting the number of bytes consumed.
pslen
is allowed to be nullptr, in which case the string must be nullptr-terminated, as the function will blindly read until it sees the nullptr char.
if *pslen
is zero, it assumes the end of string is reached and returns a zero codepoint regardless of the contents of the string buffer.
If the resulting codepoint is zero (a nullptr terminator), or *pslen
is zero, it will not advance *pstr
or *pslen
at all.
Generally this function is called in a loop until it returns zero, adjusting its parameters each iteration.
If an invalid UTF-8 sequence is encountered, this function returns INVALID_UNICODE_CODEPOINT and advances the string/length by one byte (which is to say, a multibyte sequence might produce several INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid UTF-8 sequence).
Several things can generate invalid UTF-8 sequences, including overlong encodings, the use of UTF-16 surrogate values, and truncated data. Please refer to RFC3629 for details.
pstr | a pointer to a UTF-8 string pointer to be read and adjusted. |
pslen | a pointer to the number of bytes in the string, to be read and adjusted. nullptr is allowed. |
|
inline |
This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!
Since this handles Unicode, it expects the string to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.
str1 | the first string to compare. nullptr is not permitted! |
str2 | the second string to compare. nullptr is not permitted! |
|
inline |
This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!
Since this handles Unicode, it expects the strings to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.
haystack | the string to search. Must not be nullptr. |
needle | the string to search for. Must not be nullptr. |
needle
in the string, or nullptr if not found.
|
inline |
The search ends once it finds the requested byte value, or a null terminator byte to end the string.
Note that this looks for bytes, not characters, so you cannot match against a Unicode codepoint > 255, regardless of character encoding.
str | the string to search. Must not be nullptr. |
c | the byte value to search for. |
c
in the string, or nullptr if not found.
|
inline |
Due to the nature of UTF-8 encoding, this will work with Unicode strings, since effectively this function just compares bytes until it hits a null-terminating character. Also due to the nature of UTF-8, this can be used with qsort() to put strings in (roughly) alphabetical order.
str1 | the first string to compare. nullptr is not permitted! |
str2 | the second string to compare. nullptr is not permitted! |
|
inline |
This allocates enough space for a null-terminated copy of str
, using malloc, and then makes a copy of the string into this space.
The returned string is owned by the caller, and should be passed to free when no longer needed.
str | the string to copy. |
|
inline |
This function appends up to maxlen
- strlen(dst) - 1 characters from src
to the end of the string in dst
, then appends a null terminator.
src
and dst
must not overlap.
If maxlen
- strlen(dst) - 1 is less than or equal to 0, then dst
is unmodified.
dst | The destination buffer already containing the first null-terminated string. Must not be nullptr and must not overlap with src . |
src | The second null-terminated string. Must not be nullptr, and must not overlap with dst . |
maxlen | The length (in characters) of the destination buffer. |
dst
plus the length of src
.
|
inline |
This function copies up to maxlen
- 1 characters from src
to dst
, then appends a null terminator.
If maxlen
is 0, no characters are copied and no null terminator is written.
If you want to copy an UTF-8 string but need to ensure that multi-byte sequences are not truncated, consider using utf8strlcpy().
dst | The destination buffer. Must not be nullptr, and must not overlap with src . |
src | The null-terminated string to copy. Must not be nullptr, and must not overlap with dst . |
maxlen | The length (in characters) of the destination buffer. |
src
.
|
inline |
Counts the bytes in str
, excluding the null terminator.
If you need the length of a UTF-8 string, consider using utf8strlen().
str | The null-terminated string to read. Must not be nullptr. |
src
.
|
inline |
WARNING: Regardless of system locale, this will only convert ASCII values 'A' through 'Z' to lowercase.
This function operates on a null-terminated string of bytes–even if it is malformed UTF-8!–and converts ASCII characters 'A' through 'Z' to their lowercase equivalents in-place, returning the original str
pointer.
str | the string to convert in-place. Can not be nullptr. |
str
pointer passed into this function.
|
inline |
This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!
Since this handles Unicode, it expects the string to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.
Note that while this function is intended to be used with UTF-8, maxlen
specifies a byte limit! If the limit lands in the middle of a multi-byte UTF-8 sequence, it may convert a portion of the final character to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow a buffer.
maxlen
specifies a maximum number of bytes to compare; if the strings match to this number of bytes (or both have matched to a null-terminator character before this number of bytes), they will be considered equal.
str1 | the first string to compare. nullptr is not permitted! |
str2 | the second string to compare. nullptr is not permitted! |
maxlen | the maximum number of bytes to compare. |
|
inline |
Due to the nature of UTF-8 encoding, this will work with Unicode strings, since effectively this function just compares bytes until it hits a null-terminating character. Also due to the nature of UTF-8, this can be used with qsort() to put strings in (roughly) alphabetical order.
Note that while this function is intended to be used with UTF-8, it is doing a bytewise comparison, and maxlen
specifies a byte limit! If the limit lands in the middle of a multi-byte UTF-8 sequence, it will only compare a portion of the final character.
maxlen
specifies a maximum number of bytes to compare; if the strings match to this number of bytes (or both have matched to a null-terminator character before this number of bytes), they will be considered equal.
str1 | the first string to compare. nullptr is not permitted! |
str2 | the second string to compare. nullptr is not permitted! |
maxlen | the maximum number of bytes to compare. |
|
inline |
This allocates enough space for a null-terminated copy of str
, up to maxlen
bytes, using malloc, and then makes a copy of the string into this space.
If the string is longer than maxlen
bytes, the returned string will be maxlen
bytes long, plus a null-terminator character that isn't included in the count.
The returned string is owned by the caller, and should be passed to free when no longer needed.
str | the string to copy. |
maxlen | the maximum length of the copied string, not counting the null-terminator character. |
|
inline |
Counts up to a maximum of maxlen
bytes in str
, excluding the null terminator.
If you need the length of a UTF-8 string, consider using utf8strnlen().
str | The null-terminated string to read. Must not be nullptr. |
maxlen | The maximum amount of bytes to count. |
src
but never more than maxlen
.
|
inline |
The search ends once it finds the requested substring, or a null terminator byte to end the string, or maxlen
bytes have been examined. It is possible to use this function on a string without a null terminator.
Note that this looks for strings of bytes, not characters, so it's legal to search for malformed and incomplete UTF-8 sequences.
haystack | the string to search. Must not be nullptr. |
needle | the string to search for. Must not be nullptr. |
maxlen | the maximum number of bytes to search in haystack . |
needle
in the string, or nullptr if not found.
|
inline |
str | The null-terminated string to be searched. Must not be nullptr, and must not overlap with breakset . |
breakset | A null-terminated string containing the list of characters to look for. Must not be nullptr, and must not overlap with str . |
|
inline |
The search must go until it finds a null terminator byte to end the string.
Note that this looks for bytes, not characters, so you cannot match against a Unicode codepoint > 255, regardless of character encoding.
str | the string to search. Must not be nullptr. |
c | the byte value to search for. |
c
in the string, or nullptr if not found.
|
inline |
This reverses a null-terminated string in-place. Only the content of the string is reversed; the null-terminator character remains at the end of the reversed string.
WARNING: This function reverses the bytes of the string, not the codepoints. If str
is a UTF-8 string with Unicode codepoints > 127, this will ruin the string data. You should only use this function on strings that are completely comprised of low ASCII characters.
str | the string to reverse. |
str
.
|
inline |
The search ends once it finds the requested substring, or a null terminator byte to end the string.
Note that this looks for strings of bytes, not characters, so it's legal to search for malformed and incomplete UTF-8 sequences.
haystack | the string to search. Must not be nullptr. |
needle | the string to search for. Must not be nullptr. |
needle
in the string, or nullptr if not found.
|
inline |
This function makes fewer guarantees than the C runtime strtod
:
str | the null-terminated string to read. Must not be nullptr. |
endp | if not nullptr, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer. |
double
, or 0 if no number could be parsed.
|
inline |
Break a string up into a series of tokens.
To start tokenizing a new string, str
should be the non-nullptr address of the string to start tokenizing. Future calls to get the next token from the same string should specify a nullptr.
Note that this function will overwrite pieces of str
with null chars to split it into tokens. This function cannot be used with const/read-only strings!
saveptr
just needs to point to a char *
that can be overwritten; SDL will use this to save tokenizing state between calls. It is initialized if str
is non-nullptr, and used to resume tokenizing when str
is nullptr.
str | the string to tokenize, or nullptr to continue tokenizing. |
delim | the delimiter string that separates tokens. |
saveptr | pointer to a char *, used for ongoing state. |
|
inline |
If str
starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.
If the parsed number does not fit inside a long
, the result is clamped to the minimum and maximum representable long
values.
str | The null-terminated string to read. Must not be nullptr. |
endp | If not nullptr, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer. |
base | The base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise). |
long
, or 0 if no number could be parsed.
|
inline |
If str
starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.
If the parsed number does not fit inside an unsigned long
, the result is clamped to the maximum representable unsigned long
value.
str | The null-terminated string to read. Must not be nullptr. |
endp | If not nullptr, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer. |
base | The base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise). |
unsigned long
, or 0 if no number could be parsed.
|
inline |
WARNING: Regardless of system locale, this will only convert ASCII values 'A' through 'Z' to uppercase.
This function operates on a null-terminated string of bytes–even if it is malformed UTF-8!–and converts ASCII characters 'a' through 'z' to their uppercase equivalents in-place, returning the original str
pointer.
str | the string to convert in-place. Can not be nullptr. |
str
pointer passed into this function.
|
inline |
Format a wide string of up to maxlen
-1 wchar_t values, converting each '' item with values provided through variable arguments.
While some C runtimes differ on how to deal with too-large strings, this function null-terminates the output, by treating the null-terminator as part of the maxlen
count. Note that if maxlen
is zero, however, no wide characters will be written at all.
This function returns the number of wide characters (not codepoints) that should be written, excluding the null-terminator character. If this returns a number >= maxlen
, it means the output string was truncated. A negative return value means an error occurred.
Referencing the output string's pointer with a format item is undefined behavior.
text | the buffer to write the wide string into. Must not be nullptr. |
maxlen | the maximum wchar_t values to write, including the null-terminator. |
fmt | a printf-style format string. Must not be nullptr. |
... | a list of values to be used with the format string. |
|
inline |
Domain: -INF <= x <= INF
Range: -INF <= y <= INF
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value, in radians. |
x
.
|
inline |
Domain: -INF <= x <= INF
Range: -INF <= y <= INF
This function operates on single-precision floating point values, use tan for double-precision floats.
This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.
x | floating point value, in radians. |
x
.
|
inline |
WARNING: Regardless of system locale, this will only convert ASCII values 'A' through 'Z' to lowercase.
This function returns the lowercase equivalent of x
. If a character cannot be converted, or is already lowercase, this function returns x
.
x | character value to check. |
|
inline |
WARNING: Regardless of system locale, this will only convert ASCII values 'a' through 'z' to uppercase.
This function returns the uppercase equivalent of x
. If a character cannot be converted, or is already uppercase, this function returns x
.
x | character value to check. |
|
inline |
Rounds x
to the next closest integer to 0. This is equivalent to removing the fractional part of x
, leaving only the integer part.
Domain: -INF <= x <= INF
Range: -INF <= y <= INF
, y integer
x | floating point value. |
x
truncated to an integer.
|
inline |
Rounds x
to the next closest integer to 0. This is equivalent to removing the fractional part of x
, leaving only the integer part.
Domain: -INF <= x <= INF
Range: -INF <= y <= INF
, y integer
x | floating point value. |
x
truncated to an integer.
|
inline |
The buffer pointed to by dst
must be at least 4 bytes long, as this function may generate between 1 and 4 bytes of output.
This function returns the first byte after the newly-written UTF-8 sequence, which is useful for encoding multiple codepoints in a loop, or knowing where to write a nullptr-terminator character to end the string (in either case, plan to have a buffer of more than 4 bytes!).
If codepoint
is an invalid value (outside the Unicode range, or a UTF-16 surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the codepoint instead, and not set an error.
If dst
is nullptr, this returns nullptr immediately without writing to the pointer and without setting an error.
codepoint | a Unicode codepoint to convert to UTF-8. |
dst | the location to write the encoded UTF-8. Must point to at least 4 bytes! |
|
inline |
This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2 to 36.
Note that this function will overflow a buffer if str
is not large enough to hold the output! It may be safer to use snprintf to clamp output, or asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget null terminator bytes, etc).
value | the unsigned integer to convert. |
str | the buffer to write the string into. |
radix | the radix to use for string generation. |
str
.
|
inline |
This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2 to 36.
Note that this function will overflow a buffer if str
is not large enough to hold the output! It may be safer to use snprintf to clamp output, or asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget null terminator bytes, etc).
value | the unsigned long integer to convert. |
str | the buffer to write the string into. |
radix | the radix to use for string generation. |
str
.
|
inline |
name | the name of the variable to unset. |
|
inline |
This function copies up to dst_bytes
- 1 bytes from src
to dst
while also ensuring that the string written to dst
does not end in a truncated multi-byte sequence. Finally, it appends a null terminator.
src
and dst
must not overlap.
Note that unlike strlcpy(), this function returns the number of bytes written, not the length of src
.
dst | The destination buffer. Must not be nullptr, and must not overlap with src . |
src | The null-terminated UTF-8 string to copy. Must not be nullptr, and must not overlap with dst . |
dst_bytes | The length (in bytes) of the destination buffer. Must not be 0. |
|
inline |
Counts the codepoints, not bytes, in str
, excluding the null terminator.
If you need to count the bytes in a string instead, consider using strlen().
Since this handles Unicode, it expects the strings to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the count by several replacement characters.
str | The null-terminated UTF-8 string to read. Must not be nullptr. |
src
.
|
inline |
Counts the codepoints, not bytes, in str
, excluding the null terminator.
If you need to count the bytes in a string instead, consider using strnlen().
The counting stops at bytes
bytes (not codepoints!). This seems counterintuitive, but makes it easy to express the total size of the string's buffer.
Since this handles Unicode, it expects the strings to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the count by several replacement characters.
str | The null-terminated UTF-8 string to read. Must not be nullptr. |
bytes | The maximum amount of bytes to count. |
src
but never more than maxlen
.
|
inline |
Functions identically to asprintf(), except it takes a va_list
instead of using ...
variable arguments.
strp | on output, is set to the new string. Must not be nullptr. |
fmt | a printf-style format string. Must not be nullptr. |
ap | a va_list values to be used with the format string. |
|
inline |
Functions identically to snprintf(), except it takes a va_list
instead of using ...
variable arguments.
text | the buffer to write the string into. Must not be nullptr. |
maxlen | the maximum bytes to write, including the null-terminator. |
fmt | a printf-style format string. Must not be nullptr. |
ap | a va_list values to be used with the format string. |
|
inline |
Functions identically to sscanf(), except it takes a va_list
instead of using ...
variable arguments.
text | the string to scan. Must not be nullptr. |
fmt | a printf-style format string. Must not be nullptr. |
ap | a va_list of pointers to values to be filled in with scanned items. |
|
inline |
Functions identically to swprintf(), except it takes a va_list
instead of using ...
variable arguments.
text | the buffer to write the string into. Must not be nullptr. |
maxlen | the maximum wide characters to write, including the null-terminator. |
fmt | a printf-style format wide string. Must not be nullptr. |
ap | a va_list values to be used with the format string. |
|
inline |
This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!
Depending on your platform, "wchar_t" might be 2 bytes, and expected to be UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this handles Unicode, it expects the string to be well-formed and not a null-terminated string of arbitrary bytes. Characters that are not valid UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.
str1 | the first string to compare. nullptr is not permitted! |
str2 | the second string to compare. nullptr is not permitted! |
|
inline |
This only compares wchar_t values until it hits a null-terminating character; it does not care if the string is well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size), or uses valid Unicode values.
str1 | the first string to compare. nullptr is not permitted! |
str2 | the second string to compare. nullptr is not permitted! |
|
inline |
This allocates enough space for a null-terminated copy of wstr
, using malloc, and then makes a copy of the string into this space.
The returned string is owned by the caller, and should be passed to free when no longer needed.
wstr | the string to copy. |
|
inline |
This function appends up to maxlen
- wcslen(dst) - 1 wide characters from src
to the end of the wide string in dst
, then appends a null terminator.
src
and dst
must not overlap.
If maxlen
- wcslen(dst) - 1 is less than or equal to 0, then dst
is unmodified.
dst | The destination buffer already containing the first null-terminated wide string. Must not be nullptr and must not overlap with src . |
src | The second null-terminated wide string. Must not be nullptr, and must not overlap with dst . |
maxlen | The length (in wide characters) of the destination buffer. |
dst
plus the length of src
.
|
inline |
This function copies maxlen
- 1 wide characters from src
to dst
, then appends a null terminator.
src
and dst
must not overlap.
If maxlen
is 0, no wide characters are copied and no null terminator is written.
dst | The destination buffer. Must not be nullptr, and must not overlap with src . |
src | The null-terminated wide string to copy. Must not be nullptr, and must not overlap with dst . |
maxlen | The length (in wide characters) of the destination buffer. |
src
.
|
inline |
Counts the number of wchar_t values in wstr
, excluding the null terminator.
Like strlen only counts bytes and not codepoints in a UTF-8 string, this counts wchar_t values in a string, even if the string's encoding is of variable width, like UTF-16.
Also be aware that wchar_t is different sizes on different platforms (4 bytes on Linux, 2 on Windows, etc).
wstr | The null-terminated wide string to read. Must not be nullptr. |
wstr
.
|
inline |
This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!
Depending on your platform, "wchar_t" might be 2 bytes, and expected to be UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this handles Unicode, it expects the string to be well-formed and not a null-terminated string of arbitrary bytes. Characters that are not valid UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.
Note that while this function might deal with variable-sized characters, maxlen
specifies a wchar limit! If the limit lands in the middle of a multi-byte UTF-16 sequence, it may convert a portion of the final character to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow a buffer.
maxlen
specifies a maximum number of wchar_t values to compare; if the strings match to this number of wchar_t (or both have matched to a null-terminator character before this number of bytes), they will be considered equal.
str1 | the first string to compare. nullptr is not permitted! |
str2 | the second string to compare. nullptr is not permitted! |
maxlen | the maximum number of wchar_t values to compare. |
|
inline |
This only compares wchar_t values; it does not care if the string is well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size), or uses valid Unicode values.
Note that while this function is intended to be used with UTF-16 (or UTF-32, depending on your platform's definition of wchar_t), it is comparing raw wchar_t values and not Unicode codepoints: maxlen
specifies a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16 sequence, it will only compare a portion of the final character.
maxlen
specifies a maximum number of wchar_t to compare; if the strings match to this number of wide chars (or both have matched to a null-terminator character before this count), they will be considered equal.
str1 | the first string to compare. nullptr is not permitted! |
str2 | the second string to compare. nullptr is not permitted! |
maxlen | the maximum number of wchar_t to compare. |
|
inline |
Counts up to a maximum of maxlen
wchar_t values in wstr
, excluding the null terminator.
Like strnlen only counts bytes and not codepoints in a UTF-8 string, this counts wchar_t values in a string, even if the string's encoding is of variable width, like UTF-16.
Also be aware that wchar_t is different sizes on different platforms (4 bytes on Linux, 2 on Windows, etc).
Also, maxlen
is a count of wide characters, not bytes!
wstr | The null-terminated wide string to read. Must not be nullptr. |
maxlen | The maximum amount of wide characters to count. |
wstr
but never more than maxlen
.
|
inline |
The search ends once it finds the requested substring, or a null terminator value to end the string, or maxlen
wide character have been examined. It is possible to use this function on a wide string without a null terminator.
Note that this looks for strings of wide characters, not codepoints, so it's legal to search for malformed and incomplete UTF-16 sequences.
haystack | the wide string to search. Must not be nullptr. |
needle | the wide string to search for. Must not be nullptr. |
maxlen | the maximum number of wide characters to search in haystack . |
needle
in the string, or nullptr if not found.
|
inline |
The search ends once it finds the requested substring, or a null terminator byte to end the string.
Note that this looks for strings of wide characters, not codepoints, so it's legal to search for malformed and incomplete UTF-16 sequences.
haystack | the wide string to search. Must not be nullptr. |
needle | the wide string to search for. Must not be nullptr. |
needle
in the string, or nullptr if not found.
|
inline |
If str
starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.
If the parsed number does not fit inside a long
, the result is clamped to the minimum and maximum representable long
values.
str | The null-terminated wide string to read. Must not be nullptr. |
endp | If not nullptr, the address of the first invalid wide character (i.e. the next character after the parsed number) will be written to this pointer. |
base | The base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise). |
long
, or 0 if no number could be parsed.
|
inline |
This is wrapper over memset that handles calculating the object size, so there's no chance of copy/paste errors, and the code is cleaner.
This requires an object, not a pointer to an object, nor an array.
x | the object to clear. |
|
inline |
This is wrapper over memset that handles calculating the array size, so there's no chance of copy/paste errors, and the code is cleaner.
This requires an array, not an object, nor a pointer to an object.
x | an array to clear. |
|
inline |
This is wrapper over memset that handles calculating the object size, so there's no chance of copy/paste errors, and the code is cleaner.
This requires a pointer to an object, not an object itself, nor an array.
x | a pointer to the object to clear. |
|
constexpr |
StepUTF8() and StepBackUTF8() report this codepoint when they encounter a UTF-8 string with encoding errors.
This tends to render as something like a question mark in most places.
|
constexpr |