HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SYS_String.h File Reference
#include "SYS_API.h"
#include "SYS_Inline.h"
#include "SYS_Types.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
+ Include dependency graph for SYS_String.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SYS_IS_WRAPPER(TEST)
 
#define CREATE_SYSisspace(TYPE)
 

Functions

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 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)
 

Macro Definition Documentation

#define CREATE_SYSisspace (   TYPE)
Value:
inline bool \
SYSisspace(TYPE c) \
{ \
/* Fastest exit for non-spaces. */ \
if (c > ' ') \
return false; \
/* Either equal to space, or between tab and carriage return */ \
return (c == ' ' || (c <= '\xd' && c >= '\x9')); \
}
if(rank==1) return rank

Definition at line 357 of file SYS_String.h.

#define SYS_IS_WRAPPER (   TEST)
Value:
SYS##TEST(unsigned char c) \
{ \
return TEST(c); \
} \
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45

Definition at line 325 of file SYS_String.h.

Function Documentation

int SYSstrcasecmp ( const char *  a,
const char *  b 
)
inline

Definition at line 227 of file SYS_String.h.

char* SYSstrcasestr ( const char *  haystack,
const char *  needle 
)
inline

Replacement for strcasestr, since no equivalent exists on Win32.

Definition at line 248 of file SYS_String.h.

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 212 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:

char buf[8];
strncpy(buf, "dog", 8) // buf == ['d','o','g',0,0,0,0,0]
SYSstrlcpy(buf, "dog", 8) // buf == ['d','o','g',0,?,?,?,?]
strncpy(buf, "dog", 2) // buf == ['d','o',0,0,0,0,0,0]
SYSstrlcpy(buf, "dog", 2) // buf == ['d',0,?,?,?,?,?,?]
SYSstrlcpy(buf, "dog", 3) // buf == ['d','o',0,?,?,?,?]

Definition at line 187 of file SYS_String.h.

int SYSstrncasecmp ( const char *  a,
const char *  b,
size_t  n 
)
inline

Definition at line 237 of file SYS_String.h.

char* SYSstrndup ( const char *  s,
size_t  n 
)
inline

Definition at line 290 of file SYS_String.h.

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 *strptr = string;
char *context;
char *token = SYSstrtok(string, MY_DELIMITERS, &context);
while (token)
{
do_some_stuff();
SYSstrtok(nullptr, MY_DELIMITERS, &context);
}
free(strptr);

Definition at line 113 of file SYS_String.h.