Search code examples
cgccfile-iounicodeglib

How to read a unicode file line by line using glib


There are tons of example of reading unicode file in C, but could not find anything specific to using glib library in a platform independent way. I am totally newbie in this stuff (coming from .net world). My requirement is to read a Unicode file using glib. I am using gcc as compiler.


Solution

  • Perhaps you're having trouble because unicode has several different encodings, and reading each one is a bit different. The most popular these days is UTF-8, and you can use something like g_data_input_stream_read_line for that. For other encodings you could use g_data_input_stream_read_upto (just pass the byte sequence for newline as stop_chars, and the width as stop_chars_len).