6 #ifndef INCLUDED_ircd_string_h
7 #define INCLUDED_ircd_string_h
8 #ifndef INCLUDED_ircd_chattr_h
9 #include "ircd_chattr.h"
15 #define EmptyString(x) (!(x) || !(*x))
18 * initialize recognizers
20 extern int init_string(void);
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);
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);
36 extern char* sprintf_irc(char* str, const char* format, ...);
38 extern char* canonize(char* buf);
40 #define DupString(x, y) (strcpy((x = (char*) MyMalloc(strlen(y) + 1)), y))
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 */
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)
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)
61 * Critical small functions to inline even in separate compilation
62 * when FORCEINLINE is defined (provided you have a compiler that supports
66 #define NTL_HDR_strChattr unsigned int strChattr(const char *s)
68 #define NTL_SRC_strChattr const char *rs = s; \
69 unsigned int x = ~0; \
71 x &= IRCD_CharAttrTab[*rs++ - CHAR_MIN]; \
75 * XXX - bleah should return 1 if different 0 if the same
77 #define NTL_HDR_strCasediff int strCasediff(const char *a, const char *b)
79 #define NTL_SRC_strCasediff const char *ra = a; \
81 while(ToLower(*ra) == ToLower(*rb++)) \
87 extern NTL_HDR_strChattr;
88 extern NTL_HDR_strCasediff;
90 #else /* FORCEINLINE */
92 inline NTL_HDR_strChattr { NTL_SRC_strChattr }
93 inline NTL_HDR_strCasediff { NTL_SRC_strCasediff }
95 static __inline__ NTL_HDR_strChattr { NTL_SRC_strChattr }
96 static __inline__ NTL_HDR_strCasediff { NTL_SRC_strCasediff }
98 #endif /* FORCEINLINE */
101 * Proto types of other externally visible functions
103 extern int strnChattr(const char *s, const size_t n);
105 #endif /* INCLUDED_ircd_string_h */