diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-11-09 23:19:53 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-11-09 23:19:53 +0100 |
| commit | 1566b6faa8534118c3566188181367cd0868468f (patch) | |
| tree | 1de8d4b369efb5e592685a31088f798a6b63ffa1 /examples/dte/encoding.h | |
| parent | 349991bf6efe473ab9a5cbdae0a8114d72b997e3 (diff) | |
| download | crep-1566b6faa8534118c3566188181367cd0868468f.tar.gz | |
Added partial matching and introduced threads
Diffstat (limited to 'examples/dte/encoding.h')
| -rw-r--r-- | examples/dte/encoding.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/dte/encoding.h b/examples/dte/encoding.h new file mode 100644 index 0000000..bb4cf67 --- /dev/null +++ b/examples/dte/encoding.h @@ -0,0 +1,46 @@ +#ifndef ENCODING_ENCODING_H +#define ENCODING_ENCODING_H + +#include <stdbool.h> +#include <stddef.h> +#include "util/macros.h" + +typedef enum { + UTF8, + UTF16BE, + UTF16LE, + UTF32BE, + UTF32LE, + UNKNOWN_ENCODING, + NR_ENCODING_TYPES, + + // This value is used by the "open" command to instruct other + // routines that no specific encoding was requested and that + // it should be detected instead. It is always replaced by + // some other value by the time a file is successfully opened. + ENCODING_AUTODETECT +} EncodingType; + +typedef struct { + EncodingType type; + // An interned encoding name compatible with iconv_open(3) + const char *name; +} Encoding; + +typedef struct { + const unsigned char bytes[4]; + unsigned int len; +} ByteOrderMark; + +static inline bool same_encoding(const Encoding *a, const Encoding *b) +{ + return a->type == b->type && a->name == b->name; +} + +Encoding encoding_from_type(EncodingType type); +Encoding encoding_from_name(const char *name) NONNULL_ARGS; +EncodingType lookup_encoding(const char *name) NONNULL_ARGS; +EncodingType detect_encoding_from_bom(const unsigned char *buf, size_t size); +const ByteOrderMark *get_bom_for_encoding(EncodingType encoding); + +#endif |
