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