xref: /netbsd-src/external/ibm-public/postfix/dist/src/util/stringops.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: stringops.h,v 1.2 2017/02/14 01:16:49 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(char *, int);
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 #ifndef HAVE_BASENAME
38 #define basename postfix_basename
39 extern char *basename(const char *);
40 
41 #endif
42 extern char *sane_basename(VSTRING *, const char *);
43 extern char *sane_dirname(VSTRING *, const char *);
44 extern VSTRING *unescape(VSTRING *, const char *);
45 extern VSTRING *escape(VSTRING *, const char *, ssize_t);
46 extern int alldig(const char *);
47 extern int allprint(const char *);
48 extern int allspace(const char *);
49 extern int allascii_len(const char *, ssize_t);
50 extern const char *WARN_UNUSED_RESULT split_nameval(char *, char **, char **);
51 extern int valid_utf8_string(const char *, ssize_t);
52 extern size_t balpar(const char *, const char *);
53 extern char *WARN_UNUSED_RESULT extpar(char **, const char *, int);
54 extern int strcasecmp_utf8x(int, const char *, const char *);
55 extern int strncasecmp_utf8x(int, const char *, const char *, ssize_t);
56 
57 #define EXTPAR_FLAG_NONE	(0)
58 #define EXTPAR_FLAG_STRIP	(1<<0)	/* "{ text }" -> "text" */
59 #define EXTPAR_FLAG_EXTRACT	(1<<1)	/* hint from caller's caller */
60 
61 #define CASEF_FLAG_UTF8		(1<<0)
62 #define CASEF_FLAG_APPEND	(1<<1)
63 
64  /*
65   * Convenience wrappers for most-common use cases.
66   */
67 #define allascii(s)	allascii_len((s), -1)
68 #define casefold(dst, src) \
69     casefoldx(util_utf8_enable ? CASEF_FLAG_UTF8 : 0, (dst), (src), -1)
70 #define casefold_len(dst, src, len) \
71     casefoldx(util_utf8_enable ? CASEF_FLAG_UTF8 : 0, (dst), (src), (len))
72 #define casefold_append(dst, src) \
73     casefoldx((util_utf8_enable ? CASEF_FLAG_UTF8 : 0) | CASEF_FLAG_APPEND, \
74 		(dst), (src), -1)
75 
76 #define strcasecmp_utf8(s1, s2) \
77     strcasecmp_utf8x(util_utf8_enable ? CASEF_FLAG_UTF8 : 0, (s1), (s2))
78 #define strncasecmp_utf8(s1, s2, l) \
79     strncasecmp_utf8x(util_utf8_enable ? CASEF_FLAG_UTF8 : 0, (s1), (s2), (l))
80 
81 /* LICENSE
82 /* .ad
83 /* .fi
84 /*	The Secure Mailer license must be distributed with this software.
85 /* AUTHOR(S)
86 /*	Wietse Venema
87 /*	IBM T.J. Watson Research
88 /*	P.O. Box 704
89 /*	Yorktown Heights, NY 10598, USA
90 /*--*/
91 
92 #endif
93