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