11556Srgrimes// -*- C++ -*- 21556Srgrimes/* Copyright (C) 1989, 1990, 1991, 1992, 2004 Free Software Foundation, Inc. 31556Srgrimes Written by James Clark (jjc@jclark.com) 41556Srgrimes 51556SrgrimesThis file is part of groff. 61556Srgrimes 71556Srgrimesgroff is free software; you can redistribute it and/or modify it under 81556Srgrimesthe terms of the GNU General Public License as published by the Free 91556SrgrimesSoftware Foundation; either version 2, or (at your option) any later 101556Srgrimesversion. 111556Srgrimes 121556Srgrimesgroff is distributed in the hope that it will be useful, but WITHOUT ANY 131556SrgrimesWARRANTY; without even the implied warranty of MERCHANTABILITY or 141556SrgrimesFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 151556Srgrimesfor more details. 161556Srgrimes 171556SrgrimesYou should have received a copy of the GNU General Public License along 181556Srgrimeswith groff; see the file COPYING. If not, write to the Free Software 191556SrgrimesFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 201556Srgrimes 211556Srgrimes/* $FreeBSD: releng/10.3/contrib/groff/src/libs/libgroff/cset.cpp 151503 2005-10-20 10:53:15Z ru $ */ 221556Srgrimes 231556Srgrimes#include <ctype.h> 241556Srgrimes#ifdef __FreeBSD__ 251556Srgrimes#include <locale.h> 261556Srgrimes#endif 271556Srgrimes 281556Srgrimes#include "lib.h" 291556Srgrimes#include "cset.h" 301556Srgrimes 311556Srgrimescset csalpha(CSET_BUILTIN); 321556Srgrimescset csupper(CSET_BUILTIN); 331556Srgrimescset cslower(CSET_BUILTIN); 341556Srgrimescset csdigit(CSET_BUILTIN); 351556Srgrimescset csxdigit(CSET_BUILTIN); 361556Srgrimescset csspace(CSET_BUILTIN); 37114433Sobriencset cspunct(CSET_BUILTIN); 381556Srgrimescset csalnum(CSET_BUILTIN); 3920425Sstevecset csprint(CSET_BUILTIN); 401556Srgrimescset csgraph(CSET_BUILTIN); 411556Srgrimescset cscntrl(CSET_BUILTIN); 421556Srgrimes 431556Srgrimes#if defined(isascii) && !defined(__FreeBSD__) 441556Srgrimes#define ISASCII(c) isascii(c) 4536150Scharnier#else 46114433Sobrien#define ISASCII(c) (1) 4736150Scharnier#endif 4899110Sobrien 4999110Sobrienvoid cset::clear() 501556Srgrimes{ 511556Srgrimes char *p = v; 521556Srgrimes for (int i = 0; i <= UCHAR_MAX; i++) 531556Srgrimes p[i] = 0; 541556Srgrimes} 551556Srgrimes 5678469Sdescset::cset() 5717987Speter{ 581556Srgrimes clear(); 591556Srgrimes} 601556Srgrimes 611556Srgrimescset::cset(const char *s) 621556Srgrimes{ 631556Srgrimes clear(); 641556Srgrimes while (*s) 651556Srgrimes v[(unsigned char)*s++] = 1; 661556Srgrimes} 671556Srgrimes 6817987Spetercset::cset(const unsigned char *s) 6917987Speter{ 7017987Speter clear(); 7117987Speter while (*s) 7217987Speter v[*s++] = 1; 7317987Speter} 7417987Speter 7517987Spetercset::cset(cset_builtin) 7617987Speter{ 7717987Speter // these are initialised by cset_init::cset_init() 7817987Speter} 7917987Speter 8017987Spetercset &cset::operator|=(const cset &cs) 8117987Speter{ 8217987Speter for (int i = 0; i <= UCHAR_MAX; i++) 831556Srgrimes if (cs.v[i]) 841556Srgrimes v[i] = 1; 851556Srgrimes return *this; 861556Srgrimes} 871556Srgrimes 881556Srgrimes 891556Srgrimesint cset_init::initialised = 0; 901556Srgrimes 9117987Spetercset_init::cset_init() 9217987Speter{ 9317987Speter if (initialised) 9417987Speter return; 9517987Speter initialised = 1; 9617987Speter#ifdef __FreeBSD__ 971556Srgrimes (void) setlocale(LC_CTYPE, ""); 981556Srgrimes#endif 9917987Speter for (int i = 0; i <= UCHAR_MAX; i++) { 1001556Srgrimes csalpha.v[i] = ISASCII(i) && isalpha(i); 1011556Srgrimes csupper.v[i] = ISASCII(i) && isupper(i); 1021556Srgrimes cslower.v[i] = ISASCII(i) && islower(i); 1031556Srgrimes csdigit.v[i] = ISASCII(i) && isdigit(i); 1041556Srgrimes csxdigit.v[i] = ISASCII(i) && isxdigit(i); 1051556Srgrimes csspace.v[i] = ISASCII(i) && isspace(i); 10617987Speter cspunct.v[i] = ISASCII(i) && ispunct(i); 10717987Speter csalnum.v[i] = ISASCII(i) && isalnum(i); 10817987Speter csprint.v[i] = ISASCII(i) && isprint(i); 10917987Speter csgraph.v[i] = ISASCII(i) && isgraph(i); 11017987Speter cscntrl.v[i] = ISASCII(i) && iscntrl(i); 11117987Speter } 11217987Speter} 1131556Srgrimes