summaryrefslogtreecommitdiff
path: root/examples/dte/encoding.h
diff options
context:
space:
mode:
Diffstat (limited to 'examples/dte/encoding.h')
-rw-r--r--examples/dte/encoding.h46
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