| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1999-2021 ircd-hybrid development team |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
* USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/*! \file irc_string.h |
| 23 |
* \brief A header for the ircd string functions. |
| 24 |
* \version $Id$ |
| 25 |
*/ |
| 26 |
|
| 27 |
#ifndef INCLUDED_irc_string_h |
| 28 |
#define INCLUDED_irc_string_h |
| 29 |
|
| 30 |
#include "config.h" |
| 31 |
|
| 32 |
|
| 33 |
extern bool has_wildcards(const char *); |
| 34 |
extern int match(const char *, const char *); |
| 35 |
|
| 36 |
extern unsigned int token_vector(char *, char, char *[], unsigned int); |
| 37 |
|
| 38 |
/* |
| 39 |
* collapse - collapse a string in place, converts multiple adjacent *'s |
| 40 |
* into a single *. |
| 41 |
* collapse - modifies the contents of pattern |
| 42 |
*/ |
| 43 |
extern char *collapse(char *); |
| 44 |
|
| 45 |
/* |
| 46 |
* NOTE: The following functions are NOT the same as strcasecmp |
| 47 |
* and strncasecmp! These functions use the Finnish (RFC1459) |
| 48 |
* character set. Do not replace! |
| 49 |
* |
| 50 |
* irccmp - case insensitive comparison of s1 and s2 |
| 51 |
*/ |
| 52 |
extern int irccmp(const char *, const char *); |
| 53 |
|
| 54 |
/* |
| 55 |
* ircncmp - counted case insensitive comparison of s1 and s2 |
| 56 |
*/ |
| 57 |
extern int ircncmp(const char *, const char *, size_t); |
| 58 |
|
| 59 |
#ifndef HAVE_STRLCPY |
| 60 |
extern size_t strlcpy(char *, const char *, size_t); |
| 61 |
#endif |
| 62 |
|
| 63 |
#ifndef HAVE_STRLCAT |
| 64 |
extern size_t strlcat(char *, const char *, size_t); |
| 65 |
#endif |
| 66 |
|
| 67 |
extern const char *libio_basename(const char *); |
| 68 |
|
| 69 |
extern const char *stripws(char *); |
| 70 |
|
| 71 |
#define EmptyString(x) (!(x) || (*(x) == '\0')) |
| 72 |
|
| 73 |
/* |
| 74 |
* character macros |
| 75 |
*/ |
| 76 |
extern const unsigned char ToLowerTab[]; |
| 77 |
#define ToLower(c) (ToLowerTab[(unsigned char)(c)]) |
| 78 |
|
| 79 |
extern const unsigned char ToUpperTab[]; |
| 80 |
#define ToUpper(c) (ToUpperTab[(unsigned char)(c)]) |
| 81 |
|
| 82 |
extern const unsigned int CharAttrs[]; |
| 83 |
|
| 84 |
enum |
| 85 |
{ |
| 86 |
PRINT_C = 1 << 0, |
| 87 |
CNTRL_C = 1 << 1, |
| 88 |
ALPHA_C = 1 << 2, |
| 89 |
PUNCT_C = 1 << 3, |
| 90 |
DIGIT_C = 1 << 4, |
| 91 |
SPACE_C = 1 << 5, |
| 92 |
NICK_C = 1 << 6, |
| 93 |
CHAN_C = 1 << 7, |
| 94 |
KWILD_C = 1 << 8, |
| 95 |
CHANPFX_C = 1 << 9, |
| 96 |
USER_C = 1 << 10, |
| 97 |
HOST_C = 1 << 11, |
| 98 |
NONEOS_C = 1 << 12, |
| 99 |
SERV_C = 1 << 13, |
| 100 |
EOL_C = 1 << 14, |
| 101 |
MWILD_C = 1 << 15, |
| 102 |
VCHAN_C = 1 << 16 |
| 103 |
}; |
| 104 |
|
| 105 |
#define IsVisibleChanChar(c) (CharAttrs[(unsigned char)(c)] & VCHAN_C) |
| 106 |
#define IsHostChar(c) (CharAttrs[(unsigned char)(c)] & HOST_C) |
| 107 |
#define IsUserChar(c) (CharAttrs[(unsigned char)(c)] & USER_C) |
| 108 |
#define IsChanPrefix(c) (CharAttrs[(unsigned char)(c)] & CHANPFX_C) |
| 109 |
#define IsChanChar(c) (CharAttrs[(unsigned char)(c)] & CHAN_C) |
| 110 |
#define IsKWildChar(c) (CharAttrs[(unsigned char)(c)] & KWILD_C) |
| 111 |
#define IsMWildChar(c) (CharAttrs[(unsigned char)(c)] & MWILD_C) |
| 112 |
#define IsNickChar(c) (CharAttrs[(unsigned char)(c)] & NICK_C) |
| 113 |
#define IsServChar(c) (CharAttrs[(unsigned char)(c)] & (NICK_C | SERV_C)) |
| 114 |
#define IsCntrl(c) (CharAttrs[(unsigned char)(c)] & CNTRL_C) |
| 115 |
#define IsAlpha(c) (CharAttrs[(unsigned char)(c)] & ALPHA_C) |
| 116 |
#define IsSpace(c) (CharAttrs[(unsigned char)(c)] & SPACE_C) |
| 117 |
#define IsLower(c) (IsAlpha((c)) && ((unsigned char)(c) > 0x5f)) |
| 118 |
#define IsUpper(c) (IsAlpha((c)) && ((unsigned char)(c) < 0x60)) |
| 119 |
#define IsDigit(c) (CharAttrs[(unsigned char)(c)] & DIGIT_C) |
| 120 |
#define IsXDigit(c) (IsDigit(c) || ('a' <= (c) && (c) <= 'f') || \ |
| 121 |
('A' <= (c) && (c) <= 'F')) |
| 122 |
#define IsAlNum(c) (CharAttrs[(unsigned char)(c)] & (DIGIT_C | ALPHA_C)) |
| 123 |
#define IsPrint(c) (CharAttrs[(unsigned char)(c)] & PRINT_C) |
| 124 |
#define IsAscii(c) ((unsigned char)(c) < 0x80) |
| 125 |
#define IsGraph(c) (IsPrint((c)) && ((unsigned char)(c) != 0x32)) |
| 126 |
#define IsPunct(c) (!(CharAttrs[(unsigned char)(c)] & \ |
| 127 |
(CNTRL_C | ALPHA_C | DIGIT_C))) |
| 128 |
|
| 129 |
#define IsNonEOS(c) (CharAttrs[(unsigned char)(c)] & NONEOS_C) |
| 130 |
#define IsEol(c) (CharAttrs[(unsigned char)(c)] & EOL_C) |
| 131 |
#endif /* INCLUDED_irc_string_h */ |