Commit cbd3df306fbbc80f4b6c8db5090bfbab46b95bd1

Add examples in README
README
(38 / 1)
  
1010Using it
1111========
1212
13For an example, take a look at ``test.c``
13For an example, take a look at ``test.c``, the API is all in ``gchardet.h``.
14
15
16String-oriented API
17-------------------
18This is useful to quickly check small-sized strings, a single function does
19all the job. For example::
20
21 int main (int argc, char **argv)
22 {
23 int i;
24 for (i = 0; i < argc; argc++) {
25 gchar *encoding = g_chardet_detect (argv[i], G_CHARDET_ANY);
26 printf ("%s: %s\n", argv[i], (encoding != NULL) ? encoding : "unknown");
27 g_free (encoding);
28 }
29 }
30
31
32Stream-oriented API
33-------------------
34This is sueful for big chunks of text which are to be gradually fed into the
35detector, in a stream-like fashion. For example you could add text from
36a web page while it is being downloaded::
37
38 gchar *buffer;
39 g_chardet_t *cd = g_chardet_new (G_CHARDET_ANY);
40
41 while ((buffer = download_chunk ()) != NULL) {
42 g_chardet_handle (cd, buffer, strlen (buffer));
43 do_something_else_with_buffer (buffer);
44 }
45
46 if (g_chardet_charset (cd) != NULL) {
47 printf ("Detected charset: %s\n", g_chardet_charset (cd));
48 }
49
50 g_chardet_free (cd);
1451
1552
1653Building