About character encoding G_convert (), G_locale_to_utf8 () __ Encoding

Source: Internet
Author: User
Tags gtk

In GTK, the default form of character encoding is UTF-8, where all of the displayed strings need to be UTF8 encoded for normal display.

As a result, several character-coded conversion functions become important. Of course, the function of character encoding conversion is also important in some other development frameworks. These work determines whether our program will display garbled characters when it is executed.

The following are several conversion functions in G_lib.

In the use of these functions, the first to understand the local character encoding format, so, to write a good transplant program, pay attention to the localized control code, that is, need to study the locale of things.

Gchar *g_locale_to_utf8 (const Gchar *opsysstring, Gssize len, Gsize *bytes_read, Gsize *bytes_written, GError **error);

Gchar *g_locale_from_utf8 (const Gchar *utf8string,gssize len, gsize *bytes_read, Gsize *bytes_written, GError **error);
These two functions convert the encoded format of a string into utf8 and local encodings.

Char *_ (char *string)
{
Return (G_locale_to_utf8 (string,-1, NULL, NULL, NULL));
}


Char *__ (char *string)
{
Return (G_locale_from_utf8 (string,-1, NULL, NULL, NULL));
}

This is the effect of encapsulation, the direct use of the call _ ("we") can be transformed.

If you want to display Chinese characters on the GTK + widget, use G_convert ("China", -1, "UTF-8", "GB2312", null,null,null);

In the GTK + program to read a file containing a Chinese character path in the console display or fopen (), use the

G_convert ("China", -1, "GB2312", "UTF-8", Null,null,null).

Of course, not necessarily is GB2312, this is to be based on local specific circumstances to set.

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.