sgdk: string.h File Reference

sgdk

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

Defines | Typedefs | Functions
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).
void | 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:

  value | The fix16 value to convert to string.
  str | Destination string (it must be large enough to receive result).
  numdec | Number 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:

  value | The fix32 value to convert to string.
  str | Destination string (it must be large enough to receive result).
  numdec | Number of wanted decimal.

Converts the specified fix32 value to string.

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

Convert a u32 value to hexadecimal string.

Parameters:

  value | The u32 integer value to convert to hexadecimal string.
  str | Destination string (it must be large enough to receive result).
  minsize | Minimum size of resulting string.

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:

  value | The s32 integer value to convert to string (input value should be in [-500000000..500000000] range).
  str | Destination string (it must be large enough to receive result).
  minsize | Minimum 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:

  buffer | Destination string (it must be large enough to receive result).
  fmt | C 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:

  dest | Destination string (it must be large enough to receive appending).
  src | Source string.

Returns:
  pointer on destination string.

Appends the source string to the destination string.

u16 char* strclr | ( | char * | str | ) |

Clear a string.

Parameters:

  str | string 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:

  str1 | The string we want to compare.
  str2 | The 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:

  dest | Destination string (it must be large enough to receive the copy).
  src | Source 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:

  str | The 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:

  dest | Destination string (its size must be >= (len + 1)).
  src | Source string.
  len | Maximum 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:

  str | The string whose length you want to calculate.
  maxlen | The 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:

  str | The string to operate on.
  oldc | The character being replaced.
  newc | The 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:

  value | The u32 integer value to convert to string (input value should be in [0..500000000] range).
  str | Destination string (it must be large enough to receive result).
  minsize | Minimum 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