Doxyfy ircd_string.h and ircd_string.c.
[ircu2.10.12-pk.git] / include / ircd_string.h
1 /** @file ircd_string.h
2  * @brief Public declarations and APIs for string operations.
3  * @version $Id$
4  */
5 #ifndef INCLUDED_ircd_string_h
6 #define INCLUDED_ircd_string_h
7 #ifndef INCLUDED_ircd_chattr_h
8 #include "ircd_chattr.h"
9 #endif
10
11 struct irc_in_addr;
12
13 /*
14  * Macros
15  */
16 /** Check whether \a x is a NULL or empty string. */
17 #define EmptyString(x) (!(x) || !(*x))
18
19 /*
20  * initialize recognizers
21  */
22 extern int init_string(void);
23
24 extern int string_is_hostname(const char* str);
25 extern int string_is_address(const char* str);
26 extern int string_has_wildcards(const char* str);
27
28 extern char*       ircd_strncpy(char* dest, const char* src, size_t len);
29 extern int         ircd_strcmp(const char *a, const char *b);
30 extern int         ircd_strncmp(const char *a, const char *b, size_t n);
31 extern int         unique_name_vector(char* names, char token,
32                                       char** vector, int size);
33 extern int         token_vector(char* names, char token,
34                                 char** vector, int size);
35 extern const char* ircd_ntoa(const struct irc_in_addr* addr);
36 extern const char* ircd_ntoa_r(char* buf, const struct irc_in_addr* addr);
37 extern int         ircd_aton(struct irc_in_addr *addr, const char *str);
38 extern char*       host_from_uh(char* buf, const char* userhost, size_t len);
39 extern char*       ircd_strtok(char** save, char* str, char* fs);
40
41 extern char*       canonize(char* buf);
42
43 /** Make \a y a duplicate \a x, a la strdup(). */
44 #define DupString(x, y)  (strcpy((x = (char*) MyMalloc(strlen(y) + 1)), y))
45
46
47 /* String classification pseudo-functions, when others are needed add them,
48    strIsXxxxx(s) is true when IsXxxxx(c) is true for every char in s */
49
50 /** Test whether all characters in \a s are alphanumeric. */
51 #define strIsAlnum(s)     (strChattr(s) & NTL_ALNUM)
52 /** Test whether all characters in \a s are alphabetic. */
53 #define strIsAlpha(s)     (strChattr(s) & NTL_ALPHA)
54 /** Test whether all characters in \a s are digits. */
55 #define strIsDigit(s)     (strChattr(s) & NTL_DIGIT)
56 /** Test whether all characters in \a s are lower case. */
57 #define strIsLower(s)     (strChattr(s) & NTL_LOWER)
58 /** Test whether all characters in \a s are whitespace. */
59 #define strIsSpace(s)     (strChattr(s) & NTL_SPACE)
60 /** Test whether all characters in \a s are upper case. */
61 #define strIsUpper(s)     (strChattr(s) & NTL_UPPER)
62
63 /** Test whether all characters in \a s are channel name characters. */
64 #define strIsIrcCh(s)     (strChattr(s) & NTL_IRCCH)
65 /** Test whether all characters in \a s are forced to lower-case in channel names. */
66 #define strIsIrcCl(s)     (strChattr(s) & NTL_IRCCL)
67 /** Test whether all characters in \a s are valid in nicknames. */
68 #define strIsIrcNk(s)     (strChattr(s) & NTL_IRCNK)
69 /** Test whether all characters in \a s are valid in a user field. */
70 #define strIsIrcUi(s)     (strChattr(s) & NTL_IRCUI)
71 /** Test whether all characters in \a s are valid in host names. */
72 #define strIsIrcHn(s)     (strChattr(s) & NTL_IRCHN)
73 /** Test whether all characters in \a s are valid in IP addresses. */
74 #define strIsIrcIp(s)     (strChattr(s) & NTL_IRCIP)
75
76 /*
77  * Critical small functions to inline even in separate compilation
78  * when FORCEINLINE is defined (provided you have a compiler that supports
79  * `inline').
80  */
81
82 /** Declaration for strChattr(). */
83 #define NTL_HDR_strChattr   unsigned int strChattr(const char *s)
84
85 /** Body for strChattr(). */
86 #define NTL_SRC_strChattr   const char *rs = s; \
87                             unsigned int x = ~0; \
88                             while(*rs) \
89                               x &= IRCD_CharAttrTab[*rs++ - CHAR_MIN]; \
90                             return x;
91
92 /*
93  * XXX - bleah should return 1 if different 0 if the same
94  */
95 /** Declaration for strCasediff(). */
96 #define NTL_HDR_strCasediff int strCasediff(const char *a, const char *b)
97
98 /** Body for strCasediff(). */
99 #define NTL_SRC_strCasediff const char *ra = a; \
100                             const char *rb = b; \
101                             while(ToLower(*ra) == ToLower(*rb++)) \
102                               if(!*ra++) \
103                                 return 0; \
104                             return 1;
105
106 #ifndef FORCEINLINE
107 extern NTL_HDR_strChattr;
108 extern NTL_HDR_strCasediff;
109
110 #else /* FORCEINLINE */
111 #ifdef __cplusplus
112 inline NTL_HDR_strChattr { NTL_SRC_strChattr }
113 inline NTL_HDR_strCasediff { NTL_SRC_strCasediff }
114 #else
115 static __inline__ NTL_HDR_strChattr { NTL_SRC_strChattr }
116 static __inline__ NTL_HDR_strCasediff { NTL_SRC_strCasediff }
117 #endif
118 #endif /* FORCEINLINE */
119
120 /*
121  * Proto types of other externally visible functions
122  */
123 extern int strnChattr(const char *s, const size_t n);
124
125 #endif /* INCLUDED_ircd_string_h */
126