SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
string.h File Reference

String manipulations. More...

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

Go to the source code of this file.

Macros

#define _STRING_H_
 
#define isdigit(c)
 Test if specified character is a digit or not.
 
#define va_start(v, l)
 
#define va_end(v)
 
#define 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.
 
int vsprintf (char *buffer, const char *fmt, va_list args)
 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.
 
int 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.
 
int 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 fix16ToStr (fix16 value, char *str, u16 numdec)
 Convert a fix16 value to string.
 
void fix32ToStr (fix32 value, char *str, u16 numdec)
 Convert a fix32 value to string.
 
void fastFix16ToStr (fastfix16 value, char *str, u16 numdec)
 Convert a fastfix16 value to string.
 
void fastFix32ToStr (fastfix32 value, char *str, u16 numdec)
 Convert a fastfix32 value to string.
 
void F16_toStr (fix16 value, char *str, u16 numdec)
 Same as fix16ToStr(..)
 
void F32_toStr (fix32 value, char *str, u16 numdec)
 Same as fix32ToStr(..)
 
void FF16_toStr (fastfix16 value, char *str, u16 numdec)
 Same as fastFix16ToStr(..)
 
void FF32_toStr (fastfix32 value, char *str, u16 numdec)
 Same as fastFix32ToStr(..)
 

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.

Macro Definition Documentation

◆ isdigit

#define isdigit ( c)
Value:
((c) >= '0' && (c) <= '9')

Test if specified character is a digit or not.

◆ va_arg

#define va_arg ( v,
l )
Value:
__builtin_va_arg(v,l)

◆ va_end

#define va_end ( v)
Value:
__builtin_va_end(v)

◆ va_start

#define va_start ( v,
l )
Value:
__builtin_va_start(v,l)

Function Documentation

◆ F16_toStr()

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

Same as fix16ToStr(..)

See also
fix16ToStr

◆ F32_toStr()

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

Same as fix32ToStr(..)

See also
fix32ToStr

◆ fastFix16ToStr()

void fastFix16ToStr ( fastfix16 value,
char * str,
u16 numdec )

Convert a fastfix16 value to string.

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

Converts the specified fastfix16 value to string.

◆ fastFix32ToStr()

void fastFix32ToStr ( fastfix32 value,
char * str,
u16 numdec )

Convert a fastfix32 value to string.

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

Converts the specified fastfix32 value to string.

◆ FF16_toStr()

void FF16_toStr ( fastfix16 value,
char * str,
u16 numdec )

Same as fastFix16ToStr(..)

See also
fastFix16ToStr

◆ FF32_toStr()

void FF32_toStr ( fastfix32 value,
char * str,
u16 numdec )

Same as fastFix32ToStr(..)

See also
fastFix32ToStr

◆ fix16ToStr()

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.

◆ fix32ToStr()

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.

◆ intToHex()

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.

◆ intToStr()

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.

◆ sprintf()

int 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

◆ strcat()

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.

◆ strclr()

int char * strclr ( char * str)

Clear a string.

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

Clear the specified string.

◆ strcmp()

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.

◆ strcpy()

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.

◆ strlen()

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

◆ strncpy()

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.

◆ strnlen()

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.

◆ strreplacechar()

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.

◆ uintToStr()

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.

◆ vsprintf()

int vsprintf ( char * buffer,
const char * fmt,
va_list args )

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
bufDestination 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.
argsOptional argument(s). 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