1 #ifndef _STRINGOPS_H_INCLUDED_
2 #define _STRINGOPS_H_INCLUDED_
3 
4 /*++
5 /* NAME
6 /*	stringops 3h
7 /* SUMMARY
8 /*	string operations
9 /* SYNOPSIS
10 /*	#include <stringops.h>
11 /* DESCRIPTION
12 /* .nf
13 
14  /*
15   * Utility library.
16   */
17 #include <vstring.h>
18 
19  /*
20   * External interface.
21   */
22 extern int util_utf8_enable;
23 extern char *printable_except(char *, int, const char *);
24 extern char *neuter(char *, const char *, int);
25 extern char *lowercase(char *);
26 extern char *casefoldx(int, VSTRING *, const char *, ssize_t);
27 extern char *uppercase(char *);
28 extern char *skipblanks(const char *);
29 extern char *trimblanks(char *, ssize_t);
30 extern char *concatenate(const char *,...);
31 extern char *mystrtok(char **, const char *);
32 extern char *mystrtokq(char **, const char *, const char *);
33 extern char *mystrtokdq(char **, const char *);
34 extern char *translit(char *, const char *, const char *);
35 
36 #define printable(string, replacement) \
37 	printable_except((string), (replacement), (char *) 0)
38 
39 #ifndef HAVE_BASENAME
40 #define basename postfix_basename
41 extern char *basename(const char *);
42 
43 #endif
44 extern char *sane_basename(VSTRING *, const char *);
45 extern char *sane_dirname(VSTRING *, const char *);
46 extern VSTRING *unescape(VSTRING *, const char *);
47 extern VSTRING *escape(VSTRING *, const char *, ssize_t);
48 extern int alldig(const char *);
49 extern int allalnum(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  /*
86   * Use STRREF(x) instead of x, to shut up compiler warnings when the operand
87   * is a string literal.
88   */
89 #define STRREF(x)		(&x[0])
90 
91 /* LICENSE
92 /* .ad
93 /* .fi
94 /*	The Secure Mailer license must be distributed with this software.
95 /* AUTHOR(S)
96 /*	Wietse Venema
97 /*	IBM T.J. Watson Research
98 /*	P.O. Box 704
99 /*	Yorktown Heights, NY 10598, USA
100 /*
101 /*	Wietse Venema
102 /*	Google, Inc.
103 /*	111 8th Avenue
104 /*	New York, NY 10011, USA
105 /*--*/
106 
107 #endif
108