String processing
Glib
Defines a new type called gstring, which is similar to the Standard C
But can automatically increase. String data ends with null. This type can prevent buffer overflow errors in programs. This is a very important feature, so I recommend using
Gstring. Gstring has a simple definition:
Struct gstring { Gchar * STR;/* indicates the string ending with '/0. */ Gint Len;/* Current length */ }; |
As you expected, there are many operations on a gstring string.
GString *g_string_new( gchar *init ); |
This function constructs a gstring. It copies the string value pointed to by init to the gstring and returns a pointer to it. If you create a gstring with an initial null value, a null value is passed as the parameter.
void g_string_free( GString *string, gint free_segment ); |
This function releases the storage space of a given gstring. If the free_segment parameter is true, its character data is also released.
GString *g_string_assign( GString *lval, const gchar *rval ); |
This function copies the characters in rval to lval to overwrite the previous content in lval. Note that for the string to be copied, lval will become longer, which is different from the standard strcpy () number.
The functions of the following functions are quite obvious (the version with _ c accepts a character rather than a string ):
GString *g_string_truncate( GString *string, gint len );
GString *g_string_append( GString *string, gchar *val );
GString *g_string_append_c( GString *string, gchar c );
GString *g_string_prepend( GString *string, gchar *val );
GString *g_string_prepend_c( GString *string, gchar c );
void g_string_sprintf( GString *string, gchar *fmt, ...);
void g_string_sprintfa ( GString *string, gchar *fmt, ... ); |
| <Previous |
Home |
Next >>> |
| Timer |
Up |
Utilities and error handling functions |