Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXCharset.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                           C h a r a c t e r   S e t s                         *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2000,2002 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXCharset.h,v 1.7 2002/01/18 22:42:51 jeroen Exp $                       *
00023 ********************************************************************************/
00024 #ifndef FXCHARSET_H
00025 #define FXCHARSET_H
00026 
00027 
00028 /// A set of characters
00029 class FXAPI FXCharset {
00030 private:
00031   FXuint s[8];              // Because 8*32 is 256 characters
00032 private:
00033   FXCharset(FXuint a,FXuint b,FXuint c,FXuint d,FXuint e,FXuint f,FXuint g,FXuint h){
00034     s[0]=a;s[1]=b;s[2]=c;s[3]=d;s[4]=e;s[5]=f;s[6]=g;s[7]=h;
00035     }
00036 public:
00037 
00038   /// Initialize to empty set
00039   FXCharset(){clear();}
00040 
00041   /// Copy constructor
00042   FXCharset(const FXCharset& a){
00043     s[0]=a.s[0];s[1]=a.s[1];s[2]=a.s[2];s[3]=a.s[3];s[4]=a.s[4];s[5]=a.s[5];s[6]=a.s[6];s[7]=a.s[7];
00044     }
00045 
00046   /// Initialize with one character
00047   FXCharset(FXchar ch){
00048     clear(); s[((FXuchar)ch)>>5] |= (1<<(ch&31));
00049     }
00050 
00051   /// Initialize set with set of characters
00052   FXCharset(const FXString& characters);
00053 
00054   /// Convert to characters
00055   operator FXString();
00056 
00057   /// See if character ch is member of set
00058   FXbool has(FXchar ch) const {
00059     return (s[((FXuchar)ch)>>5] & (1<<(ch&31)))!=0;
00060     }
00061 
00062   /// Clear the set
00063   FXCharset& clear(){
00064     s[0]=s[1]=s[2]=s[3]=s[4]=s[5]=s[6]=s[7]=0;
00065     return *this;
00066     }
00067 
00068   /// Assignment of one character
00069   FXCharset& operator=(FXchar ch){
00070     clear(); s[((FXuchar)ch)>>5] |= (1<<(ch&31));
00071     return *this;
00072     }
00073 
00074   /// Include character ch into set
00075   FXCharset& operator+=(FXchar ch){
00076     s[((FXuchar)ch)>>5] |= (1<<(ch&31));
00077     return *this;
00078     }
00079 
00080   /// Exclude character ch from set
00081   FXCharset& operator-=(FXchar ch){
00082     s[((FXuchar)ch)>>5] &= ~(1<<(ch&31));
00083     return *this;
00084     }
00085 
00086   /// Assignment with characters
00087   FXCharset& operator=(const FXString& characters);
00088 
00089   /// Include characters into set
00090   FXCharset& operator+=(const FXString& characters);
00091 
00092   /// Exclude characters from set
00093   FXCharset& operator-=(const FXString& characters);
00094 
00095   /// Assigning one set to this one
00096   FXCharset& operator=(const FXCharset& a){
00097     s[0]=a.s[0];s[1]=a.s[1];s[2]=a.s[2];s[3]=a.s[3];s[4]=a.s[4];s[5]=a.s[5];s[6]=a.s[6];s[7]=a.s[7];
00098     return *this;
00099     }
00100 
00101   /// Union set with this one
00102   FXCharset& operator+=(const FXCharset& a){
00103     s[0]|=a.s[0];s[1]|=a.s[1];s[2]|=a.s[2];s[3]|=a.s[3];s[4]|=a.s[4];s[5]|=a.s[5];s[6]|=a.s[6];s[7]|=a.s[7];
00104     return *this;
00105     }
00106 
00107   /// Remove set from this one
00108   FXCharset& operator-=(const FXCharset& a){
00109     s[0]&=~a.s[0];s[1]&=~a.s[1];s[2]&=~a.s[2];s[3]&=~a.s[3];s[4]&=~a.s[4];s[5]&=~a.s[5];s[6]&=~a.s[6];s[7]&=~a.s[7];
00110     return *this;
00111     }
00112 
00113   /// Interset set with this one
00114   FXCharset& operator*=(const FXCharset& a){
00115     s[0]&=a.s[0];s[1]&=a.s[1];s[2]&=a.s[2];s[3]&=a.s[3];s[4]&=a.s[4];s[5]&=a.s[5];s[6]&=a.s[6];s[7]&=a.s[7];
00116     return *this;
00117     }
00118 
00119   /// Negate set
00120   friend FXAPI FXCharset operator-(const FXCharset& a){
00121     return FXCharset(~a.s[0],~a.s[1],~a.s[2],~a.s[3],~a.s[4],~a.s[5],~a.s[6],~a.s[7]);
00122     }
00123 
00124   /// Union sets a and b
00125   friend FXAPI FXCharset operator+(const FXCharset& a,const FXCharset& b){
00126     return FXCharset(a.s[0]|b.s[0],a.s[1]|b.s[1],a.s[2]|b.s[2],a.s[3]|b.s[3],a.s[4]|b.s[4],a.s[5]|b.s[5],a.s[6]|b.s[6],a.s[7]|b.s[7]);
00127     }
00128 
00129   /// Set a less b
00130   friend FXAPI FXCharset operator-(const FXCharset& a,const FXCharset& b){
00131     return FXCharset(a.s[0]&~b.s[0],a.s[1]&~b.s[1],a.s[2]&~b.s[2],a.s[3]&~b.s[3],a.s[4]&~b.s[4],a.s[5]&~b.s[5],a.s[6]&~b.s[6],a.s[7]&~b.s[7]);
00132     }
00133 
00134   /// Intersect set a and b
00135   friend FXAPI FXCharset operator*(const FXCharset& a,const FXCharset& b){
00136     return FXCharset(a.s[0]&b.s[0],a.s[1]&b.s[1],a.s[2]&b.s[2],a.s[3]&b.s[3],a.s[4]&b.s[4],a.s[5]&b.s[5],a.s[6]&b.s[6],a.s[7]&b.s[7]);
00137     }
00138 
00139   /// Equality tests
00140   friend FXAPI int operator==(const FXCharset& a,const FXCharset& b){
00141     return a.s[0]==b.s[0] && a.s[1]==b.s[1] && a.s[2]==b.s[2] && a.s[3]==b.s[3] && a.s[4]==b.s[4] && a.s[5]==b.s[5] && a.s[6]==b.s[6] && a.s[7]==b.s[7];
00142     }
00143 
00144   friend FXAPI int operator!=(const FXCharset& a,const FXCharset& b){
00145     return a.s[0]!=b.s[0] || a.s[1]!=b.s[1] || a.s[2]!=b.s[2] || a.s[3]!=b.s[3] || a.s[4]!=b.s[4] || a.s[5]!=b.s[5] || a.s[6]!=b.s[6] || a.s[7]!=b.s[7];
00146     }
00147 
00148   /// Save set to a stream
00149   friend FXAPI FXStream& operator<<(FXStream& store,const FXCharset& cs);
00150 
00151   /// Load set from a stream
00152   friend FXAPI FXStream& operator>>(FXStream& store,FXCharset& cs);
00153   };
00154 
00155 
00156 #endif