sgdk
string.h File Reference

String manipulations. More...

Go to the source code of this file.

Defines

#define _STRING_H_
#define isdigit(c)   ((c) >= '0' && (c) <= '9')
 Test if specified character is a digit or not.
#define va_start(v, l)   __builtin_va_start(v,l)
#define va_end(v)   __builtin_va_end(v)
#define va_arg(v, l)   __builtin_va_arg(v,l)

Typedefs

typedef void * __gnuc_va_list
typedef __gnuc_va_list va_list

Functions

u16 strlen (const char *str)
 Calculate the length of a string (limited to 65535 characters maximum).
u16 strnlen (const char *str, u16 maxlen)
 Compute the length of a string, to a maximum number of bytes.
s16 strcmp (const char *str1, const char *str2)
 Compare the 2 strings.
char * strcpy (char *dest, const char *src)
 Copy a string.
char * strncpy (char *dest, const char *src, u16 len)
 Copy the first 'len' character of string.
char * strcat (char *dest, const char *src)
 Concatenate two strings.
u16 sprintf (char *buffer, const char *fmt,...) __attribute__((format(printf
 Composes a string with the same text that would be printed if format was used on printf, but instead of being printed, the content is stored as a C string in the buffer pointed by str.
u16 char * strclr (char *str)
 Clear a string.
char * strreplacechar (char *str, char oldc, char newc)
 Replace the given character in a string.
u16 intToStr (s32 value, char *str, u16 minsize)
 Convert a s32 value to string (input value should be in [-500000000..500000000] range).
u16 uintToStr (u32 value, char *str, u16 minsize)
 Convert a u32 value to string (input value should be in [0..500000000] range).
u16 intToHex (u32 value, char *str, u16 minsize)
 Convert a u32 value to hexadecimal string.
void fix32ToStr (fix32 value, char *str, u16 numdec)
 Convert a fix32 value to string.
void fix16ToStr (fix16 value, char *str, u16 numdec)
 Convert a fix16 value to string.

Detailed Description

String manipulations.

Author:
Stephane Dallongeville
Paspallas Dev
Jack Nolddor
Jesus Alonso (doragasu)
Date:
08/2011

This unit provides basic null terminated string operations and type conversions.


Function Documentation

void fix16ToStr ( fix16  value,
char *  str,
u16  numdec 
)

Convert a fix16 value to string.

Parameters:
valueThe fix16 value to convert to string.
strDestination string (it must be large enough to receive result).
numdecNumber of wanted decimal.

Converts the specified fix16 value to string.

void fix32ToStr ( fix32  value,
char *  str,
u16  numdec 
)

Convert a fix32 value to string.

Parameters:
valueThe fix32 value to convert to string.
strDestination string (it must be large enough to receive result).
numdecNumber of wanted decimal.

Converts the specified fix32 value to string.

u16 intToHex ( u32  value,
char *  str,
u16  minsize 
)

Convert a u32 value to hexadecimal string.

Parameters:
valueThe u32 integer value to convert to hexadecimal string.
strDestination string (it must be large enough to receive result).
minsizeMinimum size of resulting string.
Returns:
string length

Converts the specified u32 value to hexadecimal string.
If resulting value is shorter than requested minsize the method prepends result with '0' character.

u16 intToStr ( s32  value,
char *  str,
u16  minsize 
)

Convert a s32 value to string (input value should be in [-500000000..500000000] range).

Parameters:
valueThe s32 integer value to convert to string (input value should be in [-500000000..500000000] range).
strDestination string (it must be large enough to receive result).
minsizeMinimum size of resulting string.
Returns:
string length

Converts the specified s32 value to string.
If resulting value is shorter than requested minsize the method prepends result with '0' character.

u16 sprintf ( char *  buffer,
const char *  fmt,
  ... 
)

Composes a string with the same text that would be printed if format was used on printf, but instead of being printed, the content is stored as a C string in the buffer pointed by str.

Parameters:
bufferDestination string (it must be large enough to receive result).
fmtC string that contains the text to be written to destination string.
It can optionally contain embedded format specifiers.
...(additional arguments) Depending on the format string, the function may expect a sequence of additional arguments,
each containing a value to be used to replace a format specifier in the format string.

There should be at least as many of these arguments as the number of values specified in the format specifiers.
Additional arguments are ignored by the function.

Returns:
On success, the total number of characters written is returned..

Copy the string pointed by 'fmt' param to the 'buffer' param.
If 'fmt' includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers

char* strcat ( char *  dest,
const char *  src 
)

Concatenate two strings.

Parameters:
destDestination string (it must be large enough to receive appending).
srcSource string.
Returns:
pointer on destination string.

Appends the source string to the destination string.

u16 char* strclr ( char *  str)

Clear a string.

Parameters:
strstring to clear.
Returns:
pointer on the given string.

Clear the specified string.

s16 strcmp ( const char *  str1,
const char *  str2 
)

Compare the 2 strings.

Parameters:
str1The string we want to compare.
str2The string we want to compare.
Returns:
an integral value indicating the relationship between the strings:
A zero value indicates that both strings are equal.
A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2
A value less than zero indicates the opposite.

This function starts comparing the first character of each string.
If they are equal to each other, it continues with the following pairs until the characters differ or until a terminating null-character is reached.

char* strcpy ( char *  dest,
const char *  src 
)

Copy a string.

Parameters:
destDestination string (it must be large enough to receive the copy).
srcSource string.
Returns:
pointer on destination string.

Copies the source string to destination.

u16 strlen ( const char *  str)

Calculate the length of a string (limited to 65535 characters maximum).

Parameters:
strThe string we want to calculate the length.
Returns:
length of string

This function calculates and returns the length of the specified string (limited to 65535 characters maximum).

char* strncpy ( char *  dest,
const char *  src,
u16  len 
)

Copy the first 'len' character of string.

Parameters:
destDestination string (its size must be >= (len + 1)).
srcSource string.
lenMaximum number of character to copy.
Returns:
pointer on destination string.

Copies the source string to destination.

u16 strnlen ( const char *  str,
u16  maxlen 
)

Compute the length of a string, to a maximum number of bytes.

Parameters:
strThe string whose length you want to calculate.
maxlenThe maximum length to check.
Returns:
The minimum of 'maxlen' and the number of characters that precede the terminating null character.

The strnlen() function computes the length of the string pointed to by 'str', not including the terminating null character ('\0'),
up to a maximum of 'maxlen' bytes. The function doesn't check any more than the first 'maxlen' bytes.

char* strreplacechar ( char *  str,
char  oldc,
char  newc 
)

Replace the given character in a string.

Parameters:
strThe string to operate on.
oldcThe character being replaced.
newcThe character 'oldc' is replaced with.
Returns:
pointer to the null byte at the end of 'str'.

Replace all occurrences of character in a null-terminated string.

u16 uintToStr ( u32  value,
char *  str,
u16  minsize 
)

Convert a u32 value to string (input value should be in [0..500000000] range).

Parameters:
valueThe u32 integer value to convert to string (input value should be in [0..500000000] range).
strDestination string (it must be large enough to receive result).
minsizeMinimum size of resulting string.
Returns:
string length

Converts the specified u32 value to string.
If resulting value is shorter than requested minsize the method prepends result with '0' character.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines