Melee Modding Library
2.0.0
A C library for modding Super Smash Bros Melee
|
Handle all string operations. More...
#include "gctypes.h"
Go to the source code of this file.
Functions | |
void * | memchr (const void *ptr, int value, size_t num) |
Locate character in block of memory. More... | |
int | memcmp (const void *ptr1, const void *ptr2, size_t num) |
Compare two blocks of memory. More... | |
char * | strchr (const char *str, int character) |
Locate first occurrence of character in string. More... | |
int | strcmp (const char *str1, const char *str2) |
Compare two strings. More... | |
int | strncmp (const char *str1, const char *str2, size_t num) |
Compare characters of two strings. More... | |
char * | strcpy (char *destination, const char *source) |
char * | strncpy (char *destination, const char *source, size_t num) |
Copy characters from string. More... | |
size_t | strlen (const char *str) |
Get string length. More... | |
char * | itoa (s32 n, char *s) |
void * | memcpy (void *destination, const void *source, size_t num) |
Copy block of memory. More... | |
void * | memset (void *ptr, int value, size_t num) |
Fill block of memory. More... | |
char * | strcat (char *destination, const char *source) |
Concatenate strings. More... | |
Handle all string operations.
void* memchr | ( | const void * | ptr, |
int | value, | ||
size_t | num | ||
) |
Locate character in block of memory.
Searches within the first num
bytes of the block of memory pointed by ptr
for the first occurrence of value
(interpreted as an unsigned
char
), and returns a pointer to it.
Both value
and each of the bytes checked on the the ptr
array are interpreted as unsigned
char
for the comparison.
ptr | - Pointer to the block of memory where the search is performed. |
value | - Value to be located. The value is passed as an int , but the function performs a byte per byte search using the unsigned char conversion of this value. |
num | - Number of bytes to be analyzed. |
value
in the block of memory pointed by ptr
. If the value is not found, the function returns a null pointer.int memcmp | ( | const void * | ptr1, |
const void * | ptr2, | ||
size_t | num | ||
) |
Compare two blocks of memory.
Compares the first num
bytes of the block of memory pointed by
ptr1 to the first num
bytes pointed by ptr2
, returning zero if they all match or a value different from zero representing which is greater if they do not.
Notice that, unlike strcmp, the function does not stop comparing after finding a null character
ptr1 | - Pointer to block of memory |
ptr2 | - Point to block of memory |
num | - Number of bytes to compare |
char* strchr | ( | const char * | str, |
int | character | ||
) |
Locate first occurrence of character in string.
Returns a pointer to the first occurrence of character
in the C string str.
The terminating null-character is considered part of the C string. Therefore, it can also be located in order to retrieve a pointer to the end of a string.
str | - C string |
character | - Character to be located. It is passed as its int promotion, but it is internally converted back to char for the comparison. |
character
in str
. If the character is not found, the function returns a null pointer.int strcmp | ( | const char * | str1, |
const char * | str2 | ||
) |
Compare two strings.
Compares the C string str1
to the C string str2
.
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.
str1 | - C string to be compared |
str2 | - C string to be compared |
int strncmp | ( | const char * | str1, |
const char * | str2, | ||
size_t | num | ||
) |
Compare characters of two strings.
Compares up to num
characters of the C string str1
to those of the C string str2
. 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, until a terminating null-character is reached, or until num
characters match in both strings, whichever happens first.
str1 | - C string to be compared |
str2 | - C string to be compared |
num | - Maximum number of characters to compare |
char* strcpy | ( | char * | destination, |
const char * | source | ||
) |
Copy string
Copies the C string pointed by source
into the array pointed by destination
, including the terminating null character (and stopping at that point).
To avoid overflows, the size of the array pointed by destination
shall be long enough to contain the same C string as source (including the terminating null character), and should not overlap in memory with source
.
destination | - Pointer to the destination array where the content is to be copied. |
source | - C string to be copied. |
char* strncpy | ( | char * | destination, |
const char * | source, | ||
size_t | num | ||
) |
Copy characters from string.
Copies the first num
characters of source to destination
. If the end of the source
C string (which is signaled by a null-character) is found before num
characters have been copied, destination
is padded with zeros until a total of num
characters have been written to it.
No null-character is implicitly appended at the end of destination
if source is longer than num
. Thus, in this case, destination
shall not be considered a null terminated C string (reading it as such would overflow).
destination and source shall not overlap
destination | - Pointer to the destination array where the content is to be copied. |
source | - C string to be copied. |
num | - Maximum number of characters to be copied from source. |
size_t strlen | ( | const char * | str | ) |
Get string length.
Returns the length of the C string str.
The length of a C string is determined by the terminating null-character: A C string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself).
This should not be confused with the size of the array that holds the string. For example:
char
mystr
[100]="test string";
defines an array of characters with a size of 100 chars, but the C string with which mystr has been initialized has a length of only 11 characters. Therefore, while sizeof(mystr)
evaluates to 100, strlen(mystr)
returns 11.
str | - C string. |
char* itoa | ( | s32 | n, |
char * | s | ||
) |
Convert integer to string
Converts an integer value to a null-terminated string using base 10 and stores the result in the array given by s
.
s
should be an array long enough to contain any possible value, i.e. 33 bits in a 32-bit platform.
n | - Value to be converted to a string. |
s | - Array in memory where to store the resulting null-terminated string. |
s
.void* memcpy | ( | void * | destination, |
const void * | source, | ||
size_t | num | ||
) |
Copy block of memory.
Copies the values of num
bytes from the location pointed to by source
directly to the memory block pointed to by destination
.
The underlying type of the objects pointed to by both the source and destination pointers are irrelevant for this function; The result is a binary copy of the data.
To avoid overflows, the size of the arrays pointed to by both the destination and source parameters, shall be at least num bytes, and should not overlap (for overlapping memory blocks, memmove is a safer approach).
destination | - Pointer to the destination array where the content is to be copied, type-casted to a pointer of type void* . |
source | - Pointer to the source of data to be copied, type-casted to a pointer of type const void* . |
num | - Number of bytes to copy. |
destination
is returned.void* memset | ( | void * | ptr, |
int | value, | ||
size_t | num | ||
) |
Fill block of memory.
Sets the first num
bytes of the block of memory pointed by ptr
to the specified value
(interpreted as an unsigned
char
).
ptr | - Pointer to the block of memory to fill. |
value | - Value to be set. The value if passed as an int , but the function fills the block of memory using the unsigned char conversion of this value. |
num | - Number of bytes to be set to the value |
ptr
is returnedchar* strcat | ( | char * | destination, |
const char * | source | ||
) |
Concatenate strings.
Appends a copy of the source
string to the destination
string. The terminating null character in destination
is overwritten by the first character of source, and a null-character is included at the end of the new string formed by the concatenation of both in destination
.
destination
and source
shall not overlap.
destination | - Pointer to the destination array, which should contain a C string, and be large enough to contain the resulting string. |
source | - C string to be appended |
destination
is returned.