1 /* $NetBSD: stringops.h,v 1.4 2022/10/08 16:12:50 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 *mystrtokdq(char **, const char *); 36 extern char *translit(char *, const char *, const char *); 37 38 #define printable(string, replacement) \ 39 printable_except((string), (replacement), (char *) 0) 40 41 #ifndef HAVE_BASENAME 42 #define basename postfix_basename 43 extern char *basename(const char *); 44 45 #endif 46 extern char *sane_basename(VSTRING *, const char *); 47 extern char *sane_dirname(VSTRING *, const char *); 48 extern VSTRING *unescape(VSTRING *, const char *); 49 extern VSTRING *escape(VSTRING *, const char *, ssize_t); 50 extern int alldig(const char *); 51 extern int allalnum(const char *); 52 extern int allprint(const char *); 53 extern int allspace(const char *); 54 extern int allascii_len(const char *, ssize_t); 55 extern const char *WARN_UNUSED_RESULT split_nameval(char *, char **, char **); 56 extern const char *WARN_UNUSED_RESULT split_qnameval(char *, char **, char **); 57 extern int valid_utf8_string(const char *, ssize_t); 58 extern size_t balpar(const char *, const char *); 59 extern char *WARN_UNUSED_RESULT extpar(char **, const char *, int); 60 extern int strcasecmp_utf8x(int, const char *, const char *); 61 extern int strncasecmp_utf8x(int, const char *, const char *, ssize_t); 62 63 #define EXTPAR_FLAG_NONE (0) 64 #define EXTPAR_FLAG_STRIP (1<<0) /* "{ text }" -> "text" */ 65 #define EXTPAR_FLAG_EXTRACT (1<<1) /* hint from caller's caller */ 66 67 #define CASEF_FLAG_UTF8 (1<<0) 68 #define CASEF_FLAG_APPEND (1<<1) 69 70 /* 71 * Convenience wrappers for most-common use cases. 72 */ 73 #define allascii(s) allascii_len((s), -1) 74 #define casefold(dst, src) \ 75 casefoldx(util_utf8_enable ? CASEF_FLAG_UTF8 : 0, (dst), (src), -1) 76 #define casefold_len(dst, src, len) \ 77 casefoldx(util_utf8_enable ? CASEF_FLAG_UTF8 : 0, (dst), (src), (len)) 78 #define casefold_append(dst, src) \ 79 casefoldx((util_utf8_enable ? CASEF_FLAG_UTF8 : 0) | CASEF_FLAG_APPEND, \ 80 (dst), (src), -1) 81 82 #define strcasecmp_utf8(s1, s2) \ 83 strcasecmp_utf8x(util_utf8_enable ? CASEF_FLAG_UTF8 : 0, (s1), (s2)) 84 #define strncasecmp_utf8(s1, s2, l) \ 85 strncasecmp_utf8x(util_utf8_enable ? CASEF_FLAG_UTF8 : 0, (s1), (s2), (l)) 86 87 /* 88 * Use STRREF(x) instead of x, to shut up compiler warnings when the operand 89 * is a string literal. 90 */ 91 #define STRREF(x) (&x[0]) 92 93 /* LICENSE 94 /* .ad 95 /* .fi 96 /* The Secure Mailer license must be distributed with this software. 97 /* AUTHOR(S) 98 /* Wietse Venema 99 /* IBM T.J. Watson Research 100 /* P.O. Box 704 101 /* Yorktown Heights, NY 10598, USA 102 /* 103 /* Wietse Venema 104 /* Google, Inc. 105 /* 111 8th Avenue 106 /* New York, NY 10011, USA 107 /*--*/ 108 109 #endif 110