1 /** @file ircd_string.h
2 * @brief Public declarations and APIs for string operations.
5 #ifndef INCLUDED_ircd_string_h
6 #define INCLUDED_ircd_string_h
7 #ifndef INCLUDED_ircd_chattr_h
8 #include "ircd_chattr.h"
16 /** Check whether \a x is a NULL or empty string. */
17 #define EmptyString(x) (!(x) || !(*x))
19 extern int string_has_wildcards(const char* str);
21 extern char* ircd_strncpy(char* dest, const char* src, size_t len);
22 extern int ircd_strcmp(const char *a, const char *b);
23 extern int ircd_strncmp(const char *a, const char *b, size_t n);
24 extern int unique_name_vector(char* names, char token,
25 char** vector, int size);
26 extern int token_vector(char* names, char token,
27 char** vector, int size);
28 extern const char* ircd_ntoa(const struct irc_in_addr* addr);
29 extern const char* ircd_ntoa_r(char* buf, const struct irc_in_addr* addr);
30 extern int ircd_aton(struct irc_in_addr *addr, const char *str);
31 extern char* host_from_uh(char* buf, const char* userhost, size_t len);
32 extern char* ircd_strtok(char** save, char* str, char* fs);
34 extern char* canonize(char* buf);
36 /** Make \a y a duplicate \a x, a la strdup(). */
37 #define DupString(x, y) (strcpy((x = (char*) MyMalloc(strlen(y) + 1)), y))
40 /* String classification pseudo-functions, when others are needed add them,
41 strIsXxxxx(s) is true when IsXxxxx(c) is true for every char in s */
43 /** Test whether all characters in \a s are alphanumeric. */
44 #define strIsAlnum(s) (strChattr(s) & NTL_ALNUM)
45 /** Test whether all characters in \a s are alphabetic. */
46 #define strIsAlpha(s) (strChattr(s) & NTL_ALPHA)
47 /** Test whether all characters in \a s are digits. */
48 #define strIsDigit(s) (strChattr(s) & NTL_DIGIT)
49 /** Test whether all characters in \a s are lower case. */
50 #define strIsLower(s) (strChattr(s) & NTL_LOWER)
51 /** Test whether all characters in \a s are whitespace. */
52 #define strIsSpace(s) (strChattr(s) & NTL_SPACE)
53 /** Test whether all characters in \a s are upper case. */
54 #define strIsUpper(s) (strChattr(s) & NTL_UPPER)
56 /** Test whether all characters in \a s are channel name characters. */
57 #define strIsIrcCh(s) (strChattr(s) & NTL_IRCCH)
58 /** Test whether all characters in \a s are forced to lower-case in channel names. */
59 #define strIsIrcCl(s) (strChattr(s) & NTL_IRCCL)
60 /** Test whether all characters in \a s are valid in nicknames. */
61 #define strIsIrcNk(s) (strChattr(s) & NTL_IRCNK)
62 /** Test whether all characters in \a s are valid in a user field. */
63 #define strIsIrcUi(s) (strChattr(s) & NTL_IRCUI)
64 /** Test whether all characters in \a s are valid in host names. */
65 #define strIsIrcHn(s) (strChattr(s) & NTL_IRCHN)
66 /** Test whether all characters in \a s are valid in IP addresses. */
67 #define strIsIrcIp(s) (strChattr(s) & NTL_IRCIP)
70 * Critical small functions to inline even in separate compilation
71 * when FORCEINLINE is defined (provided you have a compiler that supports
75 /** Declaration for strChattr(). */
76 #define NTL_HDR_strChattr unsigned int strChattr(const char *s)
78 /** Body for strChattr(). */
79 #define NTL_SRC_strChattr const char *rs = s; \
80 unsigned int x = ~0; \
82 x &= IRCD_CharAttrTab[*rs++ - CHAR_MIN]; \
86 * XXX - bleah should return 1 if different 0 if the same
88 /** Declaration for strCasediff(). */
89 #define NTL_HDR_strCasediff int strCasediff(const char *a, const char *b)
91 /** Body for strCasediff(). */
92 #define NTL_SRC_strCasediff const char *ra = a; \
94 while(ToLower(*ra) == ToLower(*rb++)) \
100 extern NTL_HDR_strChattr;
101 extern NTL_HDR_strCasediff;
103 #else /* FORCEINLINE */
105 inline NTL_HDR_strChattr { NTL_SRC_strChattr }
106 inline NTL_HDR_strCasediff { NTL_SRC_strCasediff }
108 static __inline__ NTL_HDR_strChattr { NTL_SRC_strChattr }
109 static __inline__ NTL_HDR_strCasediff { NTL_SRC_strCasediff }
111 #endif /* FORCEINLINE */
113 #endif /* INCLUDED_ircd_string_h */