INGOR
|
String related utility routines. More...
#include <ytStr.h>
Public Member Functions | |
char * | ytStr_substr (const char *str, size_t length) |
Extracts the substring. | |
char * | ytStr_substr2 (const char *str, const char *end) |
Extracts the substring. | |
char * | ytStr_trim (char *str) |
Removes white spaces from the both ends of the given string. | |
char * | ytStr_copy (const char *str) |
Returns the copy of the string. | |
size_t | ytStr_size (const char *value) |
Returns the serialized size of the string. | |
void | ytStr_serialize (const char *value, ytByte **pptr) |
Serializes the character string. | |
ytStrArray * | ytStr_split (char *str, const char delim, ytStrArray *ar) |
Splits the string into tokens. | |
ytIntArray * | ytStr_splitPos (char *str, const char delim, ytIntArray *ar) |
Splits the string into tokens and returns their positions. | |
String related utility routines.
char * ytStr_copy | ( | const char * | str | ) |
Returns the copy of the string.
This allocates the new memory for the given string and copy it in the memory.
str | pointer to the string to copy. |
void ytStr_serialize | ( | const char * | value, |
ytByte ** | pptr | ||
) |
Serializes the character string.
value | pointer to the character string. NULL acceptable. If so, it is regarded an empty string, i.e, a string whose length is 0. |
pptr |
size_t ytStr_size | ( | const char * | value | ) |
Returns the serialized size of the string.
value | NULL acceptable. If so, it is regarded an empty string. |
ytStrArray * ytStr_split | ( | char * | str, |
const char | delim, | ||
ytStrArray * | ar | ||
) |
Splits the string into tokens.
Note that this modifies the contents of the given string. Split tokens stored in the array are pointer to somewhere in the given str, and therefore tokens are not copies of str.
The empty string is regarded a single token that is empty.
ar | If NULL, new ytStrArray instance is generated, otherwise this clears the given array and use it. |
ytIntArray * ytStr_splitPos | ( | char * | str, |
const char | delim, | ||
ytIntArray * | ar | ||
) |
Splits the string into tokens and returns their positions.
This replaces the delimiters in str with NULL characters so that the each cell can be treated as a NULL-terminated independent string. The start posotions of split tokens will be stored in the given array ar.
str | NULL terminated string to split. |
ar | If NULL is given, a new ytIntArray instance is generated and returned. |
char * ytStr_substr | ( | const char * | str, |
size_t | length | ||
) |
Extracts the substring.
If the string is shorter than the specified length, the returning string will be the same string.
This allocates the new memory for copying the substring, therefore user is responsible to manage it.
char * ytStr_substr2 | ( | const char * | str, |
const char * | end | ||
) |
Extracts the substring.
This specifies the end position of the substring by a pointer that points to the next address of the last character of the substring.
str | first position of the substring to extract. |
end | next position of the last character of the substring to extract. NULL is acceptable. If so, this copies the entire string. |
char * ytStr_trim | ( | char * | str | ) |
Removes white spaces from the both ends of the given string.
A white space here is one of the followings: space, tab, and newline.
This simply returns the first position of the given string that are not one of white spaces listed above, and modifies the string by putting '0' to removes white spaces at the end of the string. Thus, do not free the returned pointer directly. It does not point to the original address.
str | pointer to the string in which white spaces in the both ends are removed. |