1 /* $OpenBSD: utf8-combined.c,v 1.4 2025/01/01 15:17:36 nicm Exp $ */ 2 3 /* 4 * Copyright (c) 2023 Nicholas Marriott <nicholas.marriott@gmail.com> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <sys/types.h> 20 21 #include <stdlib.h> 22 #include <string.h> 23 #include <wchar.h> 24 25 #include "tmux.h" 26 27 /* Has this got a zero width joiner at the end? */ 28 int 29 utf8_has_zwj(const struct utf8_data *ud) 30 { 31 if (ud->size < 3) 32 return (0); 33 return (memcmp(ud->data + ud->size - 3, "\342\200\215", 3) == 0); 34 } 35 36 /* Is this a zero width joiner? */ 37 int 38 utf8_is_zwj(const struct utf8_data *ud) 39 { 40 if (ud->size != 3) 41 return (0); 42 return (memcmp(ud->data, "\342\200\215", 3) == 0); 43 } 44 45 /* Is this a variation selector? */ 46 int 47 utf8_is_vs(const struct utf8_data *ud) 48 { 49 if (ud->size != 3) 50 return (0); 51 return (memcmp(ud->data, "\357\270\217", 3) == 0); 52 } 53 54 /* Is this in the modifier table? */ 55 int 56 utf8_is_modifier(const struct utf8_data *ud) 57 { 58 wchar_t wc; 59 60 if (utf8_towc(ud, &wc) != UTF8_DONE) 61 return (0); 62 switch (wc) { 63 case 0x1F1E6: 64 case 0x1F1E7: 65 case 0x1F1E8: 66 case 0x1F1E9: 67 case 0x1F1EA: 68 case 0x1F1EB: 69 case 0x1F1EC: 70 case 0x1F1ED: 71 case 0x1F1EE: 72 case 0x1F1EF: 73 case 0x1F1F0: 74 case 0x1F1F1: 75 case 0x1F1F2: 76 case 0x1F1F3: 77 case 0x1F1F4: 78 case 0x1F1F5: 79 case 0x1F1F6: 80 case 0x1F1F7: 81 case 0x1F1F8: 82 case 0x1F1F9: 83 case 0x1F1FA: 84 case 0x1F1FB: 85 case 0x1F1FC: 86 case 0x1F1FD: 87 case 0x1F1FE: 88 case 0x1F1FF: 89 case 0x1F3FB: 90 case 0x1F3FC: 91 case 0x1F3FD: 92 case 0x1F3FE: 93 case 0x1F3FF: 94 return (1); 95 } 96 return (0); 97 } 98