[ Home ]

wtstring.c File Reference

String functions done in a portable manner. More...

#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "wtstring.h"
#include "../common/common_utils.h"
#include "../memory/memory.h"

Include dependency graph for wtstring.c:


Functions

PUBLIC 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.
PUBLIC size_t wt_strlcat (char *dest, const char *source, size_t nMaxLength)
 Appends one string to another.
PUBLIC SW32 wt_strnicmp (const char *string1, const char *string2, size_t count)
 Compare characters of two strings without regard to case.
PUBLIC SW32 wt_stricmp (const char *string1, const char *string2)
 Perform a lowercase comparison of strings.
PUBLIC void wt_snprintf (char *dest, size_t size, const char *format,...)
 Write formatted data to a string.
PUBLIC char * wt_strupr (char *string)
 Convert a string to uppercase.
PUBLIC char * wt_strlwr (char *string)
 Convert a string to lowercase.
PUBLIC char * wt_strCopy (const char *source)
 Create another copy of string.

Detailed Description

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

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

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

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

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

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

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

PUBLIC 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

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