|
char * | HqStrCopy (char *dest, const char *src, ptrdiff_t destsize) |
|
char * | HqStrCopyTrunc (char *dest, const char *src, ptrdiff_t destsize) |
|
static size_t | u8_strlen (const uint8 *u8str) |
|
static void | strcpy_cu (char *to, const uint8 *from) |
|
static void | strcpy_uc (uint8 *to, const char *from) |
|
static void | strcpy_uu (uint8 *to, const uint8 *from) |
|
static void | strncpy_cu (char *to, const uint8 *from, size_t len) |
|
static void | strncpy_uc (uint8 *to, const char *from, size_t len) |
|
static void | strncpy_uu (uint8 *to, const uint8 *from, size_t len) |
|
static int | strcmp_cu (const char *to, const uint8 *from) |
|
static int | strcmp_uc (const uint8 *to, const char *from) |
|
static int | strcmp_uu (const uint8 *to, const uint8 *from) |
|
static int | strncmp_cu (const char *to, const uint8 *from, size_t len) |
|
static int | strncmp_uc (const uint8 *to, const char *from, size_t len) |
|
static int | strncmp_uu (const uint8 *to, const uint8 *from, size_t len) |
|
static void | strcat_cu (char *to, const uint8 *from) |
|
static void | strcat_uc (uint8 *to, const char *from) |
|
static void | strcat_uu (uint8 *to, const uint8 *from) |
|
Harlequin C-String utilities for zero-terminated strings.
Usually (when you know the size of the destination storage):
- HqStrCopy - use to copy strings (asserts if truncated);
- HqStrCopyTrunc - when you want strings silently truncated to fit;
Copyright (C) 2023 Global Graphics Software Ltd. All rights reserved. This source code contains the confidential and trade secret information of Global Graphics Software Ltd. It may not be used, copied or distributed for any reason except as set forth in the applicable Global Graphics license agreement.
char* HqStrCopy |
( |
char * |
dest, |
|
|
const char * |
src, |
|
|
ptrdiff_t |
destsize |
|
) |
| |
Copy a zero-terminated string into a destination buffer, ensuring truncation and termination with asserts if oversize.
- Parameters
-
[out] | dest | Pointer to memory to copy string into. |
[in] | src | Zero-terminated string to copy data from. |
| destsize | Size in bytes of the memory pointed to by dest. |
- Returns
- The original destination pointer, like strncpy().
This function is like 'strncpy', but guarantees termination of dest string; and asserts on truncation or overlap.
Remember that destsize is a SIZE, ie. the number of bytes of storage space available at dest for the string characters and the terminating null character. A string of LENGTH (n) requires storage SIZE of at least (n+1). If destsize is zero, no bytes are read or written; dest is returned. Note that destsize is a size_t, and is therefore unsigned (in ANSI-C).
Behaviour:
- never reads beyond src+strlen(src);
- never reads beyond src+destsize-1;
- always writes exactly destsize bytes to dest, including termination;
- always terminates the dest string;
- src string is allowed to be shorter than destsize-1: if so, extra null characters are used to complete the dest string, until exactly destsize bytes have been written.
Restrictions:
- destsize must be < INT_MAX [HQASSERTed]; (this should catch attempts to pass a negative destsize: remember that destsize is a size_t, which is unsigned)
- src string must fit in dest storage ie. destsize must be >= strlen(src)+1 [HQASSERTed]; (if violated: the excess part of src will not get copied, and the dest string will be a correctly terminated but truncated copy)
- dest storage and src string must not overlap ie. there must be no overlap between dest,...,(dest+destsize-1) and src,...,(src+min(destsize-1,strlen(src))) [HQASSERTed]. (if violated, behaviour of strncpy undefined !)
char* HqStrCopyTrunc |
( |
char * |
dest, |
|
|
const char * |
src, |
|
|
ptrdiff_t |
destsize |
|
) |
| |
Copy a zero-terminated string into a destination buffer, ensuring truncation and termination without asserts if oversize.
- Parameters
-
[out] | dest | Pointer to memory to copy string into. |
[in] | src | Zero-terminated string to copy data from. |
| destsize | Size in bytes of the memory pointed to by dest. |
- Returns
- The original destination pointer, like strncpy().
This function is just like HqStrCopy, with most of its behaviour and restrictions, but without the restriction that "src string must fit in
dest storage": if src string is longer than destsize-1, the excess part of src string will not get copied, and the dest string will be a truncated copy terminated with a null character at dest+destsize-1.