INGOR
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ytStr Class Reference

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.
 
ytStrArrayytStr_split (char *str, const char delim, ytStrArray *ar)
 Splits the string into tokens.
 
ytIntArrayytStr_splitPos (char *str, const char delim, ytIntArray *ar)
 Splits the string into tokens and returns their positions.
 

Detailed Description

String related utility routines.

Member Function Documentation

◆ ytStr_copy()

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.

Parameters
strpointer to the string to copy.
Returns
newly allocated pointer of the string.

◆ ytStr_serialize()

void ytStr_serialize ( const char *  value,
ytByte **  pptr 
)

Serializes the character string.

Parameters
valuepointer to the character string. NULL acceptable. If so, it is regarded an empty string, i.e, a string whose length is 0.
pptr

◆ ytStr_size()

size_t ytStr_size ( const char *  value)

Returns the serialized size of the string.

Parameters
valueNULL acceptable. If so, it is regarded an empty string.

◆ ytStr_split()

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.

Parameters
arIf NULL, new ytStrArray instance is generated, otherwise this clears the given array and use it.

◆ ytStr_splitPos()

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.

Parameters
strNULL terminated string to split.
arIf NULL is given, a new ytIntArray instance is generated and returned.

◆ ytStr_substr()

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.

Go to Top

◆ ytStr_substr2()

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.

Parameters
strfirst position of the substring to extract.
endnext position of the last character of the substring to extract. NULL is acceptable. If so, this copies the entire string.
Returns
newly allocated memory that contains the substring.
See also
ytStr_substr().

◆ ytStr_trim()

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.

Parameters
strpointer to the string in which white spaces in the both ends are removed.
Returns
pointer to the first position of the given string, that is not a white space.
Go to Top

The documentation for this class was generated from the following file: