1 /** @file ircd_string.h
2 * @brief Public declarations and APIs for string operations.
3 * @version $Id: ircd_string.h,v 1.11 2005/09/12 03:40:17 entrope Exp $
5 #ifndef INCLUDED_ircd_string_h
6 #define INCLUDED_ircd_string_h
8 #include <string.h> /* for DupString()'s strcpy, strlen */
10 #ifndef INCLUDED_ircd_chattr_h
11 #include "ircd_chattr.h"
19 /** Check whether \a x is a NULL or empty string. */
20 #define EmptyString(x) (!(x) || !(*x))
22 extern int string_has_wildcards(const char* str
);
24 extern char* ircd_strncpy(char* dest
, const char* src
, size_t len
);
25 extern int ircd_strcmp(const char *a
, const char *b
);
26 extern int ircd_strncmp(const char *a
, const char *b
, size_t n
);
27 extern int unique_name_vector(char* names
, char token
,
28 char** vector
, int size
);
29 extern int token_vector(char* names
, char token
,
30 char** vector
, int size
);
31 extern const char* ircd_ntoa(const struct irc_in_addr
* addr
);
32 extern const char* ircd_ntoa_r(char* buf
, const struct irc_in_addr
* addr
);
33 #define ircd_aton(ADDR, STR) ipmask_parse((STR), (ADDR), NULL)
34 extern int ipmask_parse(const char *in
, struct irc_in_addr
*mask
, unsigned char *bits_ptr
);
35 extern char* host_from_uh(char* buf
, const char* userhost
, size_t len
);
36 extern char* ircd_strtok(char** save
, char* str
, char* fs
);
38 extern char* canonize(char* buf
);
40 /** Make \a y a duplicate \a x, a la strdup(). */
41 #define DupString(x, y) (strcpy((x = (char*) MyMalloc(strlen(y) + 1)), y))
44 /* String classification pseudo-functions, when others are needed add them,
45 strIsXxxxx(s) is true when IsXxxxx(c) is true for every char in s */
47 /** Test whether all characters in \a s are alphanumeric. */
48 #define strIsAlnum(s) (strChattr(s) & NTL_ALNUM)
49 /** Test whether all characters in \a s are alphabetic. */
50 #define strIsAlpha(s) (strChattr(s) & NTL_ALPHA)
51 /** Test whether all characters in \a s are digits. */
52 #define strIsDigit(s) (strChattr(s) & NTL_DIGIT)
53 /** Test whether all characters in \a s are lower case. */
54 #define strIsLower(s) (strChattr(s) & NTL_LOWER)
55 /** Test whether all characters in \a s are whitespace. */
56 #define strIsSpace(s) (strChattr(s) & NTL_SPACE)
57 /** Test whether all characters in \a s are upper case. */
58 #define strIsUpper(s) (strChattr(s) & NTL_UPPER)
60 /** Test whether all characters in \a s are channel name characters. */
61 #define strIsIrcCh(s) (strChattr(s) & NTL_IRCCH)
62 /** Test whether all characters in \a s are forced to lower-case in channel names. */
63 #define strIsIrcCl(s) (strChattr(s) & NTL_IRCCL)
64 /** Test whether all characters in \a s are valid in nicknames. */
65 #define strIsIrcNk(s) (strChattr(s) & NTL_IRCNK)
66 /** Test whether all characters in \a s are valid in a user field. */
67 #define strIsIrcUi(s) (strChattr(s) & NTL_IRCUI)
68 /** Test whether all characters in \a s are valid in host names. */
69 #define strIsIrcHn(s) (strChattr(s) & NTL_IRCHN)
70 /** Test whether all characters in \a s are valid in IP addresses. */
71 #define strIsIrcIp(s) (strChattr(s) & NTL_IRCIP)
74 * Critical small functions to inline even in separate compilation
75 * when FORCEINLINE is defined (provided you have a compiler that supports
79 /** Declaration for strChattr(). */
80 #define NTL_HDR_strChattr unsigned int strChattr(const char *s)
82 /** Body for strChattr(). */
83 #define NTL_SRC_strChattr const char *rs = s; \
84 unsigned int x = ~0; \
86 x &= IRCD_CharAttrTab[*rs++ - CHAR_MIN]; \
90 * XXX - bleah should return 1 if different 0 if the same
92 /** Declaration for strCasediff(). */
93 #define NTL_HDR_strCasediff int strCasediff(const char *a, const char *b)
95 /** Body for strCasediff(). */
96 #define NTL_SRC_strCasediff const char *ra = a; \
98 while(ToLower(*ra) == ToLower(*rb++)) \
104 extern NTL_HDR_strChattr
;
105 extern NTL_HDR_strCasediff
;
107 #else /* FORCEINLINE */
109 inline NTL_HDR_strChattr
{ NTL_SRC_strChattr
}
110 inline NTL_HDR_strCasediff
{ NTL_SRC_strCasediff
}
112 static __inline__ NTL_HDR_strChattr
{ NTL_SRC_strChattr
}
113 static __inline__ NTL_HDR_strCasediff
{ NTL_SRC_strCasediff
}
115 #endif /* FORCEINLINE */
117 #endif /* INCLUDED_ircd_string_h */