1detect_handledata(3) Library Functions Manual detect_handledata(3)
2
3
4
6 detect_handledata, detect_handledata_r - Detecting character set and
7 measuring accuracy of charset
8
9
11 #include <chardet.h>
12
13 short chardet_handledata (Detect ** handle, const char * inbuf, Detec‐
14 tObj ** outbuf);
15
16 short chardet_handledata_r (Detect ** handle, const char * inbuf,
17 size_t inlen, DetectObj ** outbuf);
18
19
21 Storing charset and accuracy of inbuf to outbuf
22
23 The detect_handledata API is deprecated becase this api is not binary
24 safe. Use or replace to detect_handledata_r api.
25
26
27 Arguments:
28 handle
29 Detect handle resource that allocated by detect_init api.
30
31
32 inbuf
33 input string for detecting
34
35
36 inlen
37 length of input string for detecting
38
39
40 outbuf
41 Stroing inforamtion of inbuf. The structure of outbuf is fol‐
42 lows.
43
44 typedef struct DetectObject {
45 char * encoding;
46 float confidence;
47 } DetectObj;
48
49 The outbuf variable is must initialized by detect_obj_init API
50 before calling this detect api.
51
52
54 Returns following condition as case by case.
55
56
57 CHARDET_SUCCESS
58 Detecting success
59
60
61 CHARDET_NO_RESULT
62 Detection failure
63
64
65 CHARDET_NULL_OBJECT
66 Don't initializing outbuf with chardet_obj_init
67
68
69 CHARDET_OUT_OF_MEMORY
70 Occuring out of memory at internal API
71
72
74 #include <chardet.h>
75
76 int main (void) {
77 Detect * d;
78 DetectObj * obj;
79 int i, arrayNum;
80 char *str[] = {
81 "this is ascii",
82 "이건 euc-kr 입니다."
83 };
84
85 arrayNum = sizeof (str) / sizeof (str[0]);
86
87 if ( (d = detect_init ()) == NULL ) {
88 fprintf (stderr, "chardet handle initialize failed\n");
89 return CHARDET_MEM_ALLOCATED_FAIL;
90 }
91
92 for ( i=0; i<arrayNum; i++ ) {
93 detect_reset (&d);
94
95 if ( (obj = detect_obj_init ()) == NULL ) {
96 fprintf (stderr, "Memory Allocation failed\n");
97 return CHARDET_MEM_ALLOCATED_FAIL;
98 }
99
100 //switch (detect_handledata (&d, str[i], &obj))
101 switch (detect_handledata (&d, str[i], strlen(str[i]), &obj))
102 {
103 case CHARDET_OUT_OF_MEMORY :
104 fprintf (stderr, "On handle processing, occured out of memory\n");
105 detect_obj_free (&obj);
106 return CHARDET_OUT_OF_MEMORY;
107 case CHARDET_NULL_OBJECT :
108 fprintf (stderr,
109 "2st argument of chardet() is must memory allocation "
110 "with detect_obj_init API\n");
111 return CHARDET_NULL_OBJECT;
112 }
113
114 printf ("encoding: %s, confidence: %f\n", obj->encoding, obj->confidence);
115 detect_obj_free (&obj);
116 }
117 detect_destroy (&d);
118
119 return 0;
120 }
121
122
124 JoungKyun.Kim <http://oops.org>
125
126
128 Use QnA board on http://oops.org
129
130
132 detect_obj_init(3), detect_obj_free(3), detect_init(3),
133 detect_reset(3), detect_destroy(3)
134
135
136
137libchardet manuals 2015-12-11 detect_handledata(3)