aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mbyte.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/mbyte.h')
-rw-r--r--src/nvim/mbyte.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/nvim/mbyte.h b/src/nvim/mbyte.h
index 2c92a0fbb2..bf6ccb13a5 100644
--- a/src/nvim/mbyte.h
+++ b/src/nvim/mbyte.h
@@ -1,7 +1,14 @@
#ifndef NVIM_MBYTE_H
#define NVIM_MBYTE_H
+#include <stdint.h>
#include <stdbool.h>
+#include <string.h>
+
+#include "nvim/iconv.h"
+#include "nvim/func_attr.h"
+#include "nvim/os/os_defs.h" // For WCHAR, indirect
+#include "nvim/types.h" // for char_u
/*
* Return byte length of character that starts with byte "b".
@@ -12,6 +19,9 @@
#define MB_BYTE2LEN(b) utf8len_tab[b]
#define MB_BYTE2LEN_CHECK(b) (((b) < 0 || (b) > 255) ? 1 : utf8len_tab[b])
+// max length of an unicode char
+#define MB_MAXCHAR 6
+
/* properties used in enc_canon_table[] (first three mutually exclusive) */
#define ENC_8BIT 0x01
#define ENC_DBCS 0x02
@@ -40,7 +50,43 @@
#define mb_ptr2char utf_ptr2char
#define mb_head_off utf_head_off
+/// Flags for vimconv_T
+typedef enum {
+ CONV_NONE = 0,
+ CONV_TO_UTF8 = 1,
+ CONV_9_TO_UTF8 = 2,
+ CONV_TO_LATIN1 = 3,
+ CONV_TO_LATIN9 = 4,
+ CONV_ICONV = 5,
+} ConvFlags;
+
+/// Structure used for string conversions
+typedef struct {
+ int vc_type; ///< Zero or more ConvFlags.
+ int vc_factor; ///< Maximal expansion factor.
+# ifdef USE_ICONV
+ iconv_t vc_fd; ///< Value for CONV_ICONV.
+# endif
+ bool vc_fail; ///< What to do with invalid characters: if true, fail,
+ ///< otherwise use '?'.
+} vimconv_T;
+
+extern const uint8_t utf8len_tab_zero[256];
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "mbyte.h.generated.h"
#endif
+
+static inline int mb_strcmp_ic(bool ic, const char *s1, const char *s2)
+ REAL_FATTR_NONNULL_ALL REAL_FATTR_PURE REAL_FATTR_WARN_UNUSED_RESULT;
+
+/// Compare strings
+///
+/// @param[in] ic True if case is to be ignored.
+///
+/// @return 0 if s1 == s2, <0 if s1 < s2, >0 if s1 > s2.
+static inline int mb_strcmp_ic(bool ic, const char *s1, const char *s2)
+{
+ return (ic ? mb_stricmp(s1, s2) : strcmp(s1, s2));
+}
#endif // NVIM_MBYTE_H