Commit cbd3df306fbbc80f4b6c8db5090bfbab46b95bd1
- Diff rendering mode:
- inline
- side by side
README
(38 / 1)
|   | |||
| 10 | 10 | Using it | |
| 11 | 11 | ======== | |
| 12 | 12 | ||
| 13 | For an example, take a look at ``test.c`` | ||
| 13 | For an example, take a look at ``test.c``, the API is all in ``gchardet.h``. | ||
| 14 | |||
| 15 | |||
| 16 | String-oriented API | ||
| 17 | ------------------- | ||
| 18 | This is useful to quickly check small-sized strings, a single function does | ||
| 19 | all 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 | |||
| 32 | Stream-oriented API | ||
| 33 | ------------------- | ||
| 34 | This is sueful for big chunks of text which are to be gradually fed into the | ||
| 35 | detector, in a stream-like fashion. For example you could add text from | ||
| 36 | a 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); | ||
| 14 | 51 | ||
| 15 | 52 | ||
| 16 | 53 | Building |

