[ Home ]

wtstring.h File Reference

Common string functions done in a portable manner. More...

#include <stdlib.h>
#include "../common/platform.h"

Include dependency graph for wtstring.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ISSPACE(c)   ( ( c ) == ' ' || ( c ) == '\f' || ( c ) == '\n' || ( c ) == '\r' || ( c ) == '\t' || ( c ) == '\v' )
#define ISUPPER(c)   ( ( c ) >= 'A' && ( c ) <= 'Z' )
#define ISLOWER(c)   ( ( c ) >= 'a' && ( c ) <= 'z' )
#define ISALPHA(c)   ( ISUPPER( c ) || ISLOWER( c ) )
#define TOUPPER(c)   ( ISLOWER( c ) ? (c) - 'a' + 'A' : ( c ) )
#define TOLOWER(c)   ( ISUPPER( c ) ? (c) - 'A' + 'a' : ( c ) )
#define ISNUMERIC(c)   ( ( c ) >= '0' && ( c ) <= '9' )
#define ISALPHANUMERIC(c)   ( ISALPHA( c ) || ISNUMERIC( c ) )
#define SCE_NON_NUMERIC   (1 << 0)
#define SCE_BUFFER_OVERFLOW   (1 << 1)
#define SCE_NULL_VALUE   (1 << 2)

Functions

size_t wt_strlcpy (char *dest, const char *source, size_t nMaxLength)
 Copies a specified number of characters from a source string into a buffer.
size_t wt_strlcat (char *dest, const char *source, size_t nMaxLength)
 Appends one string to another.
SW32 wt_stricmp (const char *string1, const char *string2)
 Perform a lowercase comparison of strings.
SW32 wt_strnicmp (const char *string1, const char *string2, size_t count)
 Compare characters of two strings without regard to case.
void wt_snprintf (char *dest, size_t size, const char *format,...)
 Write formatted data to a string.
char * wt_strCopy (const char *source)
 Create another copy of string.
W32 wt_strhash (const char *string, W32 length, W32 mask)
 Generates a hash value from string.
char * wt_strupr (char *string)
 Convert a string to uppercase.
char * wt_strlwr (char *string)
 Convert a string to lowercase.
SW32 StringToInteger (const char *string, W32 *error)
 Convert string to integer.
double StringToFloat (const char *string, W32 *error)
 Convert string to float.


Detailed Description

Common string functions done in a portable manner.

Author:
Michael Liebscher

Todd C. Miller

Date:
2004-2006
Note:
Portion of this code was derived from code that was originally written by Todd C. Miller.

Function Documentation

double StringToFloat ( const char *  string,
W32 *  error 
)

Convert string to float.

Parameters:
[in] string The String to be converted to a float.
[out] error Error code. See header.
Returns:
A float value.

Here is the call graph for this function:

SW32 StringToInteger ( const char *  string,
W32 *  error 
)

Convert string to integer.

Parameters:
[in] string The String to be converted to an Integer.
[out] error Error code. See header.
Returns:
An integer value.

Here is the caller graph for this function:

void wt_snprintf ( char *  dest,
size_t  size,
const char *  format,
  ... 
)

Write formatted data to a string.

Parameters:
[out] dest Storage location for output.
[in] size Maximum number of characters to store.
[in] format Format-control string.
[in] ... Optional arguments.
Note:
If the format string is longer than 32768 truncation will occur. Also, if format is longer than dest truncation will occur.

Here is the call graph for this function:

Here is the caller graph for this function:

char* wt_strCopy ( const char *  source  ) 

Create another copy of string.

Parameters:
[in] source NUL-terminated string to copy.
Returns:
Pointer to copy, otherwise NULL.
Note:
Caller is responsible for freeing allocated data by calling MM_FREE

Here is the call graph for this function:

W32 wt_strhash ( const char *  string,
W32  length,
W32  mask 
)

Generates a hash value from string.

Parameters:
[in] string NUL-terminated string to hash.
Returns:
Returns hash value

SW32 wt_stricmp ( const char *  string1,
const char *  string2 
)

Perform a lowercase comparison of strings.

Parameters:
[in] string1 NUL-terminated strings to compare.
[in] string2 NUL-terminated strings to compare.
Returns:
The return value indicates the relation of string1 to string2 as follows.
  • <0 string1 less than string2
  • 0 string1 identical to string2
  • >0 string1 greater than string2

Here is the caller graph for this function:

size_t wt_strlcat ( char *  dest,
const char *  source,
size_t  nMaxLength 
)

Appends one string to another.

Parameters:
[in,out] dest Pointer to a NUL-terminated string. The buffer must be large enough to contain both strings or else truncation will occur.
[in] source Pointer to a NUL-terminated string from which the function copies characters.
[in] nMaxLength Full size of dest, not space left.
Returns:
Returns strlen( source ) + MIN( nMaxLength, strlen( initial dest ) ). If retval >= nMaxLength, truncation occurred.
Note:
At most nMaxLength-1 characters will be copied. Always NUL-terminates (unless nMaxLength == 0).

Here is the caller graph for this function:

size_t wt_strlcpy ( char *  dest,
const char *  source,
size_t  nMaxLength 
)

Copies a specified number of characters from a source string into a buffer.

Parameters:
[in,out] dest Pointer to a buffer into which the function copies characters.
[in] source Pointer to a NUL-terminated string from which the function copies characters.
[in] nMaxLength Specifies the number of bytes to be copied from the string pointed to by source into the buffer pointed to by dest.
Returns:
Returns the string length of source. If retval >= nMaxLength, truncation occurred.
Note:
At most nMaxLength-1 characters will be copied. Always NUL-terminates (unless nMaxLength == 0).

Here is the caller graph for this function:

char* wt_strlwr ( char *  string  ) 

Convert a string to lowercase.

Parameters:
[in,out] string NUL-terminated string to convert to lowercase.
Returns:
This functions returns a pointer to the converted string. Because the modification is done in place, the pointer returned is the same as the pointer passed as the input argument. No return value is reserved to indicate an error.

Here is the caller graph for this function:

SW32 wt_strnicmp ( const char *  string1,
const char *  string2,
size_t  count 
)

Compare characters of two strings without regard to case.

Parameters:
[in] string1 NUL-terminated strings to compare.
[in] string2 NUL-terminated strings to compare.
[in] count Number of characters to compare.
Returns:
The return value indicates the relationship between the substrings as follows.
  • <0 string1 substring less than string2 substring
  • 0 string1 substring identical to string2 substring
  • >0 string1 substring greater than string2 substring

char* wt_strupr ( char *  string  ) 

Convert a string to uppercase.

Parameters:
[in,out] string NUL-terminated string to capitalize.
Returns:
This functions returns a pointer to the converted string. Because the modification is done in place, the pointer returned is the same as the pointer passed as the input argument. No return value is reserved to indicate an error.

Here is the caller graph for this function: