1detect(3) Library Functions Manual detect(3)
2
3
4
6 detect, detect_r - Detecting character set and measuring accuracy of
7 charset
8
9
11 #include <chardet.h>
12
13 short detect (char * inbuf, DetectObj ** outbuf);
14
15 short detect_r (char * inbuf, size_t inlen, DetectObj ** outbuf);
16
17
19 Storing charset and accuracy of inbuf to outbuf
20
21 The detect API is deprecated becase this api is not binary safe. Use or
22 replace to detect_r api.
23
24
25 Arguments:
26 inbuf
27 input string for detecting
28
29
30 inlen
31 length of input string for detecting
32
33
34 outbuf
35 Stroing inforamtion of inbuf. The structure of outbuf is fol‐
36 lows.
37
38 typedef struct DetectObject {
39 char * encoding;
40 float confidence;
41 } DetectObj;
42
43 The outbuf variable is must initialized by detect_obj_init API
44 before calling this detect api.
45
46
48 Returns following condition as case by case.
49
50
51 CHARDET_SUCCESS
52 Detecting success
53
54
55 CHARDET_NO_RESULT
56 Detection failure
57
58
59 CHARDET_NULL_OBJECT
60 Don't initializing outbuf with chardet_obj_init
61
62
63 CHARDET_OUT_OF_MEMORY
64 Occuring out of memory at internal API
65
66
68 #include <chardet.h>
69
70 int main (void) {
71 DetectObj *obj;
72 char * checkstr = "안녕하세요";
73
74 if ( (obj = detect_obj_init ()) == NULL ) {
75 fprintf (stderr, "Memory Allocation failed\n");
76 return CHARDET_MEM_ALLOCATED_FAIL;
77 }
78
79 //switch (detect (checkstr, &obj))
80 switch (detect_r (checkstr, strlen (checkstr), &obj))
81 {
82 case CHARDET_OUT_OF_MEMORY :
83 fprintf (stderr, "On handle processing, occured out of memory\n");
84 detect_obj_free (&obj);
85 return CHARDET_OUT_OF_MEMORY;
86 case CHARDET_NULL_OBJECT :
87 fprintf (stderr,
88 "2st argument of chardet() is must memory allocation "
89 "with detect_obj_init API\n");
90 return CHARDET_NULL_OBJECT;
91 }
92
93 printf ("encoding: %s, confidence: %f\n", obj->encoding, obj->confidence);
94 detect_obj_free (&obj);
95
96 return 0;
97 }
98
99
101 JoungKyun.Kim <http://oops.org>
102
103
105 Use QnA board on http://oops.org
106
107
109 detect_handledata(3), detect_obj_init(3), detect_obj_free(3)
110
111
112
113libchardet manuals 2015-12-11 detect(3)