Man page - detect(3)
Packages contains this manual
apt-get install libchardet-dev
Available languages:
en koManual
detect
์ด ๋ฆ์ฌ ์ฉ ๋ฒ
์ค ๋ช
API ์ ๊ท ๋จผ ํธ
๋ฐ ํ ๊ฐ
์ ์
์ ์
๋ฒ ๊ทธ ๋ฆฌ ํฌ ํธ
์ฐธ ๊ณ
์ด ๋ฆ
detect, detect_r - ๋ฌธ ์ ์ด ์ ๋ฌธ ์ ์ ๊ณผ ์ ํ ๋ ๋ฅผ ์ธก ์
์ฌ ์ฉ ๋ฒ
#include <chardet.h>
short detect (char * inbuf, DetectObj ** outbuf);
short detect_r (char * inbuf, size_t inlen, DetectObj ** outbuf);
์ค ๋ช
inbuf ์ ๋ฌธ ์ ์ ๊ณผ ์ ํ ๋ ๋ฅผ outbuf์ ์ ์ฅ ํ ๋ค .
detect API๋ binary safe ๋ฌธ ์ ๋ก ๋ ์ด ์ ์ฌ ์ฉ ์ ๊ถ ์ฅ ํ ์ง ์ ์ต ๋ ๋ค . detect_r API๋ฅผ ์ด ์ฉ ํ ์ญ ์ ์ค .
API ์ ๊ท ๋จผ ํธ
|
inbuf |
๋ฌธ ์ ์ ๊ณผ ์ ํ ๋ ๋ฅผ ์ธก ์ ํ ์ ๋ ฅ ๋ฌธ ์ ์ด
inlen
๋ฌธ ์ ์
๊ณผ ์ ํ
๋ ๋ฅผ ์ธก ์ ํ ์
๋ ฅ ๋ฌธ ์ ์ด ์ ๊ธธ
์ด
|
outbuf |
inbuf ์ ๋ฌธ ์ ์ ๊ณผ ์ ํ ๋ ๋ฅผ ๊ตฌ ํ ์ฌ ์ ์ฅ ์ ํ ๋ค . outbuf ์ ๊ตฌ ์กฐ ๋ ๋ค ์ ๊ณผ ๊ฐ ๋ค .
typedef struct DetectObject {
|
char * encoding; |
|||
|
float confidence; |
|||
|
short bom; |
|||
|
} DetectObj; |
outbuf๋ detect_obj_init api๋ฅผ ์ด ์ฉ ํ ์ฌ ์ด ๊ธฐ ํ ๋ฅผ ํ ํ ์ detect api๋ก ๋ ๊ฒจ ์ค ์ผ ํ ๋ค .
๋ฐ ํ ๊ฐ
๊ฒฝ
์ฐ ์ ๋ฐ ๋ผ ์ ๋
์ ์ ํ ๋ฅผ ๋ฐ ํ
ํ ๋ค .
CHARDET_SUCCESS
์ฑ ๊ณต
CHARDET_NO_RESULT
ํ ์ง ํ ์ง ๋ชป ํ ์ ๊ฒฝ ์ฐ
CHARDET_NULL_OBJECT
outbuf ์ chardet_obj_init api๋ฅผ ์ด ์ฉ ํ ์ฌ ๋ฉ ๋ชจ ๋ฆฌ ํ ๋น ์ ํ ์ง ์ ์ ์ ๊ฒฝ ์ฐ .
CHARDET_OUT_OF_MEMORY
๋ด ๋ถ API์ ์ out of memory ๊ฐ ๋ฐ ์ ํ ์ ๊ฒฝ ์ฐ
์ ์
#include <chardet.h>
int main (void) {
|
DetectObj *obj; |
||||||
|
if ( (obj = detect_obj_init ()) == NULL ) { |
||||||
|
fprintf (stderr, "Memory Allocation failed\n"); |
||||||
|
return CHARDET_MEM_ALLOCATED_FAIL; |
||||||
|
} |
||||||
|
//switch (detect ("์ ๋ ํ ์ธ ์ ", &obj)) |
||||||
|
switch (detect_r ("์ ๋ ํ ์ธ ์ ", 10, &obj)) |
||||||
|
{ |
||||||
|
case CHARDET_OUT_OF_MEMORY : |
||||||
|
fprintf (stderr, "On handle processing, occured out of memory\n"); |
||||||
|
detect_obj_free (&obj); |
||||||
|
return CHARDET_OUT_OF_MEMORY; |
||||||
|
case CHARDET_NULL_OBJECT : |
||||||
|
fprintf (stderr, |
||||||
|
"2st argument of chardet() is must memory allocation " |
||||||
|
"with detect_obj_init API\n"); |
||||||
|
return CHARDET_NULL_OBJECT; |
||||||
|
} |
||||||
|
# obj-bom ์ CHARDET_BOM_CHECK ์ ์ ์ง ์ ์ฌ ๋ถ ๋ก ์ง ์ ์ ํ ๋จ ํ ์ ์ ์ต ๋ ๋ค . |
||||||
|
printf ("encoding: %s, confidence: %f, exists bom: %d\n", obj->encoding, obj->confidence, obj->bom); |
||||||
|
detect_obj_free (&obj); |
return 0;
}
์ ์
๊น ์ ๊ท
๋ฒ ๊ทธ ๋ฆฌ ํฌ ํธ
https://github.com/Joungkyun/libchardet/issues
์ฐธ ๊ณ
detect_handledata(3), detect_obj_init(3), detect_obj_free(3)