1 /* $NetBSD: stringops.h,v 1.3 2020/03/18 19:05:22 christos Exp $ */ 2 3 #ifndef _STRINGOPS_H_INCLUDED_ 4 #define _STRINGOPS_H_INCLUDED_ 5 6 /*++ 7 /* NAME 8 /* stringops 3h 9 /* SUMMARY 10 /* string operations 11 /* SYNOPSIS 12 /* #include <stringops.h> 13 /* DESCRIPTION 14 /* .nf 15 16 /* 17 * Utility library. 18 */ 19 #include <vstring.h> 20 21 /* 22 * External interface. 23 */ 24 extern int util_utf8_enable; 25 extern char *printable_except(char *, int, const char *); 26 extern char *neuter(char *, const char *, int); 27 extern char *lowercase(char *); 28 extern char *casefoldx(int, VSTRING *, const char *, ssize_t); 29 extern char *uppercase(char *); 30 extern char *skipblanks(const char *); 31 extern char *trimblanks(char *, ssize_t); 32 extern char *concatenate(const char *,...); 33 extern char *mystrtok(char **, const char *); 34 extern char *mystrtokq(char **, const char *, const char *); 35 extern char *translit(char *, const char *, const char *); 36 37 #define printable(string, replacement) \ 38 printable_except((string), (replacement), (char *) 0) 39 40 #ifndef HAVE_BASENAME 41 #define basename postfix_basename 42 extern char *basename(const char *); 43 44 #endif 45 extern char *sane_basename(VSTRING *, const char *); 46 extern char *sane_dirname(VSTRING *, const char *); 47 extern VSTRING *unescape(VSTRING *, const char *); 48 extern VSTRING *escape(VSTRING *, const char *, ssize_t); 49 extern int alldig(const char *); 50 extern int allprint(const char *); 51 extern int allspace(const char *); 52 extern int allascii_len(const char *, ssize_t); 53 extern const char *WARN_UNUSED_RESULT split_nameval(char *, char **, char **); 54 extern const char *WARN_UNUSED_RESULT split_qnameval(char *, char **, char **); 55 extern int valid_utf8_string(const char *, ssize_t); 56 extern size_t balpar(const char *, const char *); 57 extern char *WARN_UNUSED_RESULT extpar(char **, const char *, int); 58 extern int strcasecmp_utf8x(int, const char *, const char *); 59 extern int strncasecmp_utf8x(int, const char *, const char *, ssize_t); 60 61 #define EXTPAR_FLAG_NONE (0) 62 #define EXTPAR_FLAG_STRIP (1<<0) /* "{ text }" -> "text" */ 63 #define EXTPAR_FLAG_EXTRACT (1<<1) /* hint from caller's caller */ 64 65 #define CASEF_FLAG_UTF8 (1<<0) 66 #define CASEF_FLAG_APPEND (1<<1) 67 68 /* 69 * Convenience wrappers for most-common use cases. 70 */ 71 #define allascii(s) allascii_len((s), -1) 72 #define casefold(dst, src) \ 73 casefoldx(util_utf8_enable ? CASEF_FLAG_UTF8 : 0, (dst), (src), -1) 74 #define casefold_len(dst, src, len) \ 75 casefoldx(util_utf8_enable ? CASEF_FLAG_UTF8 : 0, (dst), (src), (len)) 76 #define casefold_append(dst, src) \ 77 casefoldx((util_utf8_enable ? CASEF_FLAG_UTF8 : 0) | CASEF_FLAG_APPEND, \ 78 (dst), (src), -1) 79 80 #define strcasecmp_utf8(s1, s2) \ 81 strcasecmp_utf8x(util_utf8_enable ? CASEF_FLAG_UTF8 : 0, (s1), (s2)) 82 #define strncasecmp_utf8(s1, s2, l) \ 83 strncasecmp_utf8x(util_utf8_enable ? CASEF_FLAG_UTF8 : 0, (s1), (s2), (l)) 84 85 /* LICENSE 86 /* .ad 87 /* .fi 88 /* The Secure Mailer license must be distributed with this software. 89 /* AUTHOR(S) 90 /* Wietse Venema 91 /* IBM T.J. Watson Research 92 /* P.O. Box 704 93 /* Yorktown Heights, NY 10598, USA 94 /* 95 /* Wietse Venema 96 /* Google, Inc. 97 /* 111 8th Avenue 98 /* New York, NY 10011, USA 99 /*--*/ 100 101 #endif 102