This repository has been archived on 2025-02-12. You can view files and clone it, but cannot push or open issues or pull requests.
NeoStats/include/ircstring.h

100 lines
3.8 KiB
C
Raw Normal View History

2003-11-03 14:23:16 +00:00
/* NeoStats - IRC Statistical Services
** Copyright (c) 1999-2008 Adam Rutter, Justin Hammond, Mark Hetherington
2003-11-03 14:23:16 +00:00
** http://www.neostats.net/
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
** USA
**
** NeoStats CVS Identification
** $Id$
*/
#ifndef _IRCSTRING_H_
#define _IRCSTRING_H_
/*
* match - compare name with mask, mask may contain * and ? as wildcards
* match - returns 1 on successful match, 0 otherwise
*
* match_esc - compare with support for escaping chars
* match_cidr - compares u!h@addr with u!h@addr/cidr
*/
int match_esc( const char *mask, const char *name );
int match_cidr( const char *mask, const char *name );
/*
* collapse - collapse a string in place, converts multiple adjacent *'s
* into a single *.
* collapse - modifies the contents of pattern
*
* collapse_esc() - collapse with support for escaping chars
*/
char *collapse( char *pattern );
char *collapse_esc( char *pattern );
extern const unsigned char ToLowerTab[];
#define ToLower(c) (ToLowerTab[(unsigned char)(c)])
extern const unsigned char ToUpperTab[];
#define ToUpper(c) (ToUpperTab[(unsigned char)(c)])
extern const unsigned int CharAttrs[];
#define PRINT_C 0x001
#define CNTRL_C 0x002
#define ALPHA_C 0x004
#define PUNCT_C 0x008
#define DIGIT_C 0x010
#define SPACE_C 0x020
#define NICK_C 0x040
#define CHAN_C 0x080
#define KWILD_C 0x100
#define CHANPFX_C 0x200
#define USER_C 0x400
#define HOST_C 0x800
#define NONEOS_C 0x1000
#define SERV_C 0x2000
#define EOL_C 0x4000
#define IsHostChar(c) (CharAttrs[(unsigned char)(c)] & HOST_C)
2005-12-26 08:33:41 +00:00
#define IsURLChar(c) (IsHostChar(c) || ((c) == '/') || ((c) == '_'))
#define IsUserChar(c) (CharAttrs[(unsigned char)(c)] & USER_C)
#define IsChanPrefix(c) (CharAttrs[(unsigned char)(c)] & CHANPFX_C)
#define IsChanChar(c) (CharAttrs[(unsigned char)(c)] & CHAN_C)
#define IsChanKeyChar(c) (IsAlNum((c)))
#define IsKWildChar(c) (CharAttrs[(unsigned char)(c)] & KWILD_C)
#define IsNickChar(c) (CharAttrs[(unsigned char)(c)] & NICK_C)
#define IsServChar(c) (CharAttrs[(unsigned char)(c)] & (NICK_C | SERV_C))
#define IsCntrl(c) (CharAttrs[(unsigned char)(c)] & CNTRL_C)
#define IsAlpha(c) (CharAttrs[(unsigned char)(c)] & ALPHA_C)
#define IsSpace(c) (CharAttrs[(unsigned char)(c)] & SPACE_C)
#define IsLower(c) (IsAlpha((c)) && ((unsigned char)(c) > 0x5f))
#define IsUpper(c) (IsAlpha((c)) && ((unsigned char)(c) < 0x60))
#define IsDigit(c) (CharAttrs[(unsigned char)(c)] & DIGIT_C)
#define IsXDigit(c) (IsDigit(c) || ('a' <= (c) && (c) <= 'f') || \
('A' <= (c) && (c) <= 'F'))
#define IsAlNum(c) (CharAttrs[(unsigned char)(c)] & (DIGIT_C | ALPHA_C))
#define IsPrint(c) (CharAttrs[(unsigned char)(c)] & PRINT_C)
#define IsAscii(c) ((unsigned char)(c) < 0x80)
#define IsGraph(c) (IsPrint((c)) && ((unsigned char)(c) != 0x32))
#define IsPunct(c) (!(CharAttrs[(unsigned char)(c)] & \
(CNTRL_C | ALPHA_C | DIGIT_C)))
#define IsNonEOS(c) (CharAttrs[(unsigned char)(c)] & NONEOS_C)
#define IsEol(c) (CharAttrs[(unsigned char)(c)] & EOL_C)
#define IsWildChar(c)( ( c ) == '?' || ( c ) == '*' )
2003-11-03 14:23:16 +00:00
#endif /* _IRCSTRING_H_ */