Glib string processing @ GTK + 2.0 Chinese tutorial serialization

Source: Internet
Author: User
<Previous Glib Next >>>
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.