Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
00001 /******************************************************************************** 00002 * * 00003 * C h a r a c t e r S e t s * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2000,2004 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.14 2004/02/08 17:17:33 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXCHARSET_H 00025 #define FXCHARSET_H 00026 00027 namespace FX { 00028 00029 /// A set of characters 00030 class FXAPI FXCharset { 00031 private: 00032 FXuint s[8]; // Because 8*32 is 256 characters 00033 private: 00034 FXCharset(FXuint a,FXuint b,FXuint c,FXuint d,FXuint e,FXuint f,FXuint g,FXuint h){ 00035 s[0]=a;s[1]=b;s[2]=c;s[3]=d;s[4]=e;s[5]=f;s[6]=g;s[7]=h; 00036 } 00037 public: 00038 00039 /// Initialize to empty set 00040 FXCharset(){clear();} 00041 00042 /// Copy constructor 00043 FXCharset(const FXCharset& a){ 00044 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]; 00045 } 00046 00047 /// Initialize with one character 00048 FXCharset(FXchar ch){ 00049 clear(); s[((FXuchar)ch)>>5] |= (1<<(ch&31)); 00050 } 00051 00052 /// Initialize set with set of characters 00053 FXCharset(const FXString& characters); 00054 00055 /// Convert to characters 00056 operator FXString(); 00057 00058 /// See if character ch is member of set 00059 FXbool has(FXchar ch) const { 00060 return (s[((FXuchar)ch)>>5] & (1<<(ch&31)))!=0; 00061 } 00062 00063 /// Clear the set 00064 FXCharset& clear(){ 00065 s[0]=s[1]=s[2]=s[3]=s[4]=s[5]=s[6]=s[7]=0; 00066 return *this; 00067 } 00068 00069 /// Assignment of one character 00070 FXCharset& operator=(FXchar ch){ 00071 clear(); s[((FXuchar)ch)>>5] |= (1<<(ch&31)); 00072 return *this; 00073 } 00074 00075 /// Include character ch into set 00076 FXCharset& operator+=(FXchar ch){ 00077 s[((FXuchar)ch)>>5] |= (1<<(ch&31)); 00078 return *this; 00079 } 00080 00081 /// Exclude character ch from set 00082 FXCharset& operator-=(FXchar ch){ 00083 s[((FXuchar)ch)>>5] &= ~(1<<(ch&31)); 00084 return *this; 00085 } 00086 00087 /// Assignment with characters 00088 FXCharset& operator=(const FXString& characters); 00089 00090 /// Include characters into set 00091 FXCharset& operator+=(const FXString& characters); 00092 00093 /// Exclude characters from set 00094 FXCharset& operator-=(const FXString& characters); 00095 00096 /// Assigning one set to this one 00097 FXCharset& operator=(const FXCharset& a){ 00098 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]; 00099 return *this; 00100 } 00101 00102 /// Union set with this one 00103 FXCharset& operator+=(const FXCharset& a){ 00104 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]; 00105 return *this; 00106 } 00107 00108 /// Remove set from this one 00109 FXCharset& operator-=(const FXCharset& a){ 00110 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]; 00111 return *this; 00112 } 00113 00114 /// Interset set with this one 00115 FXCharset& operator*=(const FXCharset& a){ 00116 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]; 00117 return *this; 00118 } 00119 00120 /// Negate set 00121 friend FXAPI FXCharset operator-(const FXCharset& a){ 00122 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]); 00123 } 00124 00125 /// Union sets a and b 00126 friend FXAPI FXCharset operator+(const FXCharset& a,const FXCharset& b){ 00127 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]); 00128 } 00129 00130 /// Set a less b 00131 friend FXAPI FXCharset operator-(const FXCharset& a,const FXCharset& b){ 00132 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]); 00133 } 00134 00135 /// Intersect set a and b 00136 friend FXAPI FXCharset operator*(const FXCharset& a,const FXCharset& b){ 00137 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]); 00138 } 00139 00140 /// Equality tests 00141 friend FXAPI int operator==(const FXCharset& a,const FXCharset& b){ 00142 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]; 00143 } 00144 00145 friend FXAPI int operator!=(const FXCharset& a,const FXCharset& b){ 00146 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]; 00147 } 00148 00149 /// Save set to a stream 00150 friend FXAPI FXStream& operator<<(FXStream& store,const FXCharset& cs); 00151 00152 /// Load set from a stream 00153 friend FXAPI FXStream& operator>>(FXStream& store,FXCharset& cs); 00154 00155 }; 00156 00157 } 00158 00159 #endif
Copyright © 1997-2004 Jeroen van der Zijp |