#include "SYS_API.h"
#include "SYS_Inline.h"
#include "SYS_Types.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
|
char * | SYSstrtok (char *string, const char *delimit, char **context) |
|
size_t | SYSstrlcpy (char *dest, const char *src, size_t size) |
|
size_t | SYSstrlcat (char *dest, const char *src, size_t size) |
|
int | SYSstrcasecmp (const char *a, const char *b) |
|
int | SYSstrcmp (const char *a, const char *b) |
|
int | SYSstrncasecmp (const char *a, const char *b, size_t n) |
|
char * | SYSstrcasestr (const char *haystack, const char *needle) |
| Replacement for strcasestr, since no equivalent exists on Win32. More...
|
|
char * | SYSstrndup (const char *s, size_t n) |
|
SYS_FORCE_INLINE bool | SYSisprint (unsigned char c) |
|
#define CREATE_SYSisspace |
( |
|
TYPE | ) |
|
Value:inline bool \
{ \
return false; \
\
return (
c ==
' ' || (c <= '\xd' && c >=
'\x9')); \
}
Definition at line 444 of file SYS_String.h.
#define SYS_IS_WRAPPER |
( |
|
TEST | ) |
|
Value:
SYS##TEST(
unsigned char c) \
{ \
} \
Definition at line 378 of file SYS_String.h.
#define WRAP_NULLTEST |
( |
|
FUNCTION | ) |
|
Value:
#define WRAP_NULLTEST_C(FUNCTION, CONST)
Definition at line 258 of file SYS_String.h.
#define WRAP_NULLTEST_C |
( |
|
FUNCTION, |
|
|
|
CONST |
|
) |
| |
Value:inline CONST char * \
SYS##FUNCTION(CONST
char *
s,
int c) \
if (!
s) return
nullptr; \
return ::FUNCTION(
s,
c); \
} \
Definition at line 249 of file SYS_String.h.
int SYSstrcasecmp |
( |
const char * |
a, |
|
|
const char * |
b |
|
) |
| |
|
inline |
char* SYSstrcasestr |
( |
const char * |
haystack, |
|
|
const char * |
needle |
|
) |
| |
|
inline |
Replacement for strcasestr, since no equivalent exists on Win32.
Definition at line 290 of file SYS_String.h.
int SYSstrcmp |
( |
const char * |
a, |
|
|
const char * |
b |
|
) |
| |
|
inline |
size_t SYSstrlcat |
( |
char * |
dest, |
|
|
const char * |
src, |
|
|
size_t |
size |
|
) |
| |
|
inline |
The following implements the strlcpy() function from OpenBSD. The differences between strlcpy() and strncpy() are:
- The buffer will not be filled with null
- The size passed in is the full length of the buffer (not remaining length)
- The dest will always be null terminated (unless it is already larger than the size passed in) The function returns strln(src) + SYSmin(size, strlen(dest)) If rcode >= size, truncation occurred
Definition at line 205 of file SYS_String.h.
size_t SYSstrlcpy |
( |
char * |
dest, |
|
|
const char * |
src, |
|
|
size_t |
size |
|
) |
| |
|
inline |
The semantics for strncpy() leave a little to be desired
- If the buffer limit is hit, the string isn't guaranteed to be null terminated.
- If the buffer limit isn't hit, the entire remainder of the string is filled with nulls (which can be costly with large buffers). The following implements the strlcpy() function from OpenBSD. The function is very similar to strncpy() but The return code is the length of the src string The resulting string is always null terminated (unless size == 0) The remaining buffer is not touched It's possible to check for errors by testing rcode >= size.
The size is the size of the buffer, not the portion of the sub-string to copy. If you want to only copy a portion of a string, make sure that the size
passed in is one larger than the length of the string since SYSstrlcpy() will always ensure the string is null terminated.
It is invalid to pass a size of 0.
Examples:
strncpy(buf, "dog", 8)
strncpy(buf, "dog", 2)
Definition at line 180 of file SYS_String.h.
int SYSstrncasecmp |
( |
const char * |
a, |
|
|
const char * |
b, |
|
|
size_t |
n |
|
) |
| |
|
inline |
char* SYSstrndup |
( |
const char * |
s, |
|
|
size_t |
n |
|
) |
| |
|
inline |
char* SYSstrtok |
( |
char * |
string, |
|
|
const char * |
delimit, |
|
|
char ** |
context |
|
) |
| |
|
inline |
A standard name for a strtok that doesn't maintain state between calls. This version is thus both reentrant and threadsafe. SYSstrtok parses a string into a sequence of tokens. On the first call to SYSstrtok, the string to be parsed must be specified as the parameter 'string'. This parameter will be modified (destroying your copy). 'delimit' specifies an array of single characters that will be used as delimiters. 'context' is a char * variable used internally by SYSstrtok to maintain context between calls. Subsequent calls must specify the same unchanged context variable as the first call. To use SYSstrtok, on the first call first pass in your string as the parameter 'string'; on subsequent calls, pass it in as nullptr. SYSstrtok returns non-empty strings pointing to the first non-delimiter character of each token, or nullptr if no further tokens are available. Example:
char *string = strdup(getString());
char *context;
char *token =
SYSstrtok(
string, MY_DELIMITERS, &context);
while (token)
{
do_some_stuff();
}
free(strptr);
Definition at line 106 of file SYS_String.h.