diff src/libvterm/src/utf8.h @ 11621:b8299e742f41 v8.0.0693

patch 8.0.0693: no terminal emulator support commit https://github.com/vim/vim/commit/e4f25e4a8db2c8a8a71a4ba2a68540b3ab341e42 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jul 7 11:54:15 2017 +0200 patch 8.0.0693: no terminal emulator support Problem: No terminal emulator support. Cannot properly run commands in the GUI. Cannot run a job interactively with an ssh connection. Solution: Very early implementation of the :terminal command. Includes libvterm converted to ANSI C. Many parts still missing.
author Christian Brabandt <cb@256bit.org>
date Fri, 07 Jul 2017 12:00:04 +0200
parents
children 2449b6ce1456
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/src/libvterm/src/utf8.h
@@ -0,0 +1,47 @@
+/* The following functions copied and adapted from libtermkey
+ *
+ * http://www.leonerd.org.uk/code/libtermkey/
+ */
+unsigned int utf8_seqlen(long codepoint);
+
+#if defined(DEFINE_INLINES) || USE_INLINE
+INLINE unsigned int utf8_seqlen(long codepoint)
+{
+  if(codepoint < 0x0000080) return 1;
+  if(codepoint < 0x0000800) return 2;
+  if(codepoint < 0x0010000) return 3;
+  if(codepoint < 0x0200000) return 4;
+  if(codepoint < 0x4000000) return 5;
+  return 6;
+}
+#endif
+
+/* Does NOT NUL-terminate the buffer */
+int fill_utf8(long codepoint, char *str);
+
+#if defined(DEFINE_INLINES) || USE_INLINE
+INLINE int fill_utf8(long codepoint, char *str)
+{
+  int nbytes = utf8_seqlen(codepoint);
+
+  /* This is easier done backwards */
+  int b = nbytes;
+  while(b > 1) {
+    b--;
+    str[b] = 0x80 | (codepoint & 0x3f);
+    codepoint >>= 6;
+  }
+
+  switch(nbytes) {
+    case 1: str[0] =        (codepoint & 0x7f); break;
+    case 2: str[0] = 0xc0 | (codepoint & 0x1f); break;
+    case 3: str[0] = 0xe0 | (codepoint & 0x0f); break;
+    case 4: str[0] = 0xf0 | (codepoint & 0x07); break;
+    case 5: str[0] = 0xf8 | (codepoint & 0x03); break;
+    case 6: str[0] = 0xfc | (codepoint & 0x01); break;
+  }
+
+  return nbytes;
+}
+#endif
+/* end copy */