detect_obj_init(3)

πŸ“¦
version 1.0.6 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

detect_obj_init β€” bestie, this is the one that gets your DetectObject structure all set up and ready to slay ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <chardet.h>
DetectObj chardet_obj_init (void);

🌸 DESCRIPTION 🌸

Okay so real talk: detect_obj_init initializes the DetectObj structure β€” the lil container that's holding all your chardet info. You literally cannot start the party without it, no cap. It sets up the struct so it's ready to store what chardet finds out about your text πŸ’…


πŸŽ€ RETURN VALUE πŸŽ€

It returns a DetectObject structure. That's the good news.

The important part though? The return value must be freed by the chardet_obj_free api. Like, do not ghost that step, bestie β€” if you don't free it, that's a leak and we don't do leaks in this house 🫢

Here's the struct you're getting, in all its glory:

typedef struct DetectObject {
     char * encoding;
     float confidence;
     short bom;
} DetectObj;

✨ EXAMPLE ✨

Here's the whole vibe, copy-paste ready:

#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)) {
          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;
     }

     # check support obj->bom with CHARDET_BOM_CHECK constant
     printf ("encoding: %s, confidence: %f, exists bom: %d\n", obj->encoding, obj->confidence, obj->bom);
     detect_obj_free (&obj);

    return 0;
}

πŸ‘‘ AUTHORS πŸ‘‘

JoungKyun.Kim <http://oops.org> β€” iconic behavior, honestly πŸ™ˆ


πŸ’€ BUG REPORTS πŸ’€

Found something cursed? Use the QnA board on https://github.com/Joungkyun/libchardet/issues β€” go tell them, fr fr πŸ›


🌈 SEE ALSO 🌈


And that's the whole page, bestie 🧚✨ this was the detect_obj_init(3) page from the libchardet manuals, dated 2019-08-01 β€” go forth and detect responsibly πŸ’œ

πŸ“¦ where this page comes from