1 /* $MirOS: src/include/utf.h,v 1.2 2013/10/31 20:06:09 tg Exp $ */ 2 3 /*- 4 * Copyright (c) 2008, 2013 5 * Thorsten Glaser <tg@mirbsd.org> 6 * 7 * Provided that these terms and disclaimer and all copyright notices 8 * are retained or reproduced in an accompanying document, permission 9 * is granted to deal in this work without restriction, including un- 10 * limited rights to use, publicly perform, distribute, sell, modify, 11 * merge, give away, or sublicence. 12 * 13 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to 14 * the utmost extent permitted by applicable law, neither express nor 15 * implied; without malicious intent or gross negligence. In no event 16 * may a licensor, author or contributor be held liable for indirect, 17 * direct, other damage, loss, or other issues arising in any way out 18 * of dealing in the work, even if advised of the possibility of such 19 * damage or existence of a defect, except proven that it results out 20 * of said person's immediate fault when using the work as intended. 21 *- 22 * Interface for Plan 9’s Rune API, slightly modified yet compatible 23 */ 24 25 #ifndef _UTF_H_ 26 #define _UTF_H_ 27 28 #include <sys/cdefs.h> 29 30 #if !defined(_GCC_SIZE_T) 31 #define _GCC_SIZE_T 32 typedef __SIZE_TYPE__ size_t; 33 #endif 34 35 #if !defined(_GCC_WCHAR_T) && !defined(__cplusplus) 36 #define _GCC_WCHAR_T 37 typedef __WCHAR_TYPE__ wchar_t; 38 #endif 39 40 #if !defined(_GCC_WINT_T) 41 #define _GCC_WINT_T 42 typedef __WINT_TYPE__ wint_t; 43 #endif 44 45 typedef wchar_t Rune; 46 47 enum { 48 UTFmax = 3, /* maximum number of octets per Rune */ 49 Runesync = 0x80, /* cannot represent part of UTF sequence (<) */ 50 Runeself = 0x80, /* rune and UTF sequences are the same (<) */ 51 Runeerror = 0xFFFE /* decoding error in UTF */ 52 }; 53 54 __BEGIN_DECLS 55 size_t chartorune(Rune *, const char *) 56 __attribute__((__nonnull__(1, 2))); 57 int fullrune(const char *, size_t) 58 __attribute__((__nonnull__(1))) 59 __attribute__((__bounded__(__string__, 1, 2))); 60 int isalpharune(Rune); 61 int islowerrune(Rune); 62 int isspacerune(Rune); 63 int istitlerune(Rune); 64 int isupperrune(Rune); 65 size_t runelen(wint_t); 66 size_t runenlen(const Rune *, size_t) 67 __attribute__((__nonnull__(1))); 68 Rune *runestrcat(Rune *, const Rune *) 69 __attribute__((__nonnull__(1, 2))); 70 Rune *runestrchr(Rune *, Rune) 71 __attribute__((__nonnull__(1))); 72 int runestrcmp(const Rune *, const Rune *) 73 __attribute__((__nonnull__(1, 2))); 74 Rune *runestrcpy(Rune *, const Rune *) 75 __attribute__((__nonnull__(1, 2))); 76 Rune *runestrdup(const Rune *) 77 __attribute__((__nonnull__(1))); 78 Rune *runestrecpy(Rune *, Rune *, const Rune *) 79 __attribute__((__nonnull__(1, 2, 3))); 80 size_t runestrlen(const Rune *) 81 __attribute__((__nonnull__(1))); 82 Rune *runestrncat(Rune *, const Rune *, size_t) 83 __attribute__((__nonnull__(1, 2))); 84 int runestrncmp(const Rune *, const Rune *, size_t) 85 __attribute__((__nonnull__(1, 2))); 86 Rune *runestrncpy(Rune *, const Rune *, size_t) 87 __attribute__((__nonnull__(1, 2))); 88 Rune *runestrrchr(Rune *, Rune) 89 __attribute__((__nonnull__(1))); 90 Rune *runestrstr(Rune *, const Rune *) 91 __attribute__((__nonnull__(1, 2))); 92 size_t runetochar(char *, const Rune *) 93 __attribute__((__nonnull__(1, 2))) 94 __attribute__((__bounded__(__minbytes__, 1, 3))); 95 Rune tolowerrune(Rune); 96 Rune totitlerune(Rune); 97 Rune toupperrune(Rune); 98 char *utfecpy(char *, char *, const char *) 99 __attribute__((__nonnull__(1, 2, 3))); 100 size_t utflen(const char *) 101 __attribute__((__nonnull__(1))); 102 size_t utfnlen(const char *, size_t); 103 __attribute__((__nonnull__(1))) 104 __attribute__((__bounded__(__string__, 1, 2))); 105 char *utfrrune(char *, wint_t) 106 __attribute__((__nonnull__(1))); 107 char *utfrune(char *, wint_t) 108 __attribute__((__nonnull__(1))); 109 char *utfutf(char *, const char *) 110 __attribute__((__nonnull__(1))); 111 __END_DECLS 112 113 #endif 114