WvStreams
|
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 2005 Net Integration Technologies, Inc. 00004 * 00005 * Implementation of an efficient lookup for a set characters. 00006 * 00007 * It is, however, a little space intensive, but you should statically 00008 * create them in your functions, and then they won't be so bad. 00009 */ 00010 #include "wvstringmask.h" 00011 00012 WvStringMask::WvStringMask(WvStringParm s) 00013 { 00014 zap(); 00015 set(s, true); 00016 } 00017 00018 WvStringMask::WvStringMask(char c) 00019 { 00020 zap(); 00021 set(c, true); 00022 } 00023 00024 bool WvStringMask::operator[](const char c) const 00025 { 00026 unsigned char uc = c; 00027 return _set[uc]; 00028 } 00029 00030 const char WvStringMask::first() const 00031 { 00032 return _first; 00033 } 00034 00035 void WvStringMask::zap() 00036 { 00037 memset(_set, 0, sizeof(bool) * sizeof(_set)); 00038 _first = '\0'; 00039 } 00040 00041 void WvStringMask::set(const char c, bool value) 00042 { 00043 if (!_first) 00044 _first = c; 00045 00046 _set[unsigned(c)] = value; 00047 } 00048 00049 void WvStringMask::set(WvStringParm s, bool value) 00050 { 00051 if (!s.isnull()) 00052 { 00053 const char *c = s.cstr(); 00054 00055 if (!_first) 00056 _first = *c; 00057 00058 while (*c) 00059 { 00060 _set[unsigned(*c)] = value; 00061 ++c; 00062 } 00063 } 00064 }