wvstringmask.cc

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     return _set[unsigned(c)];
00027 }
00028 
00029 bool WvStringMask::operator[](const int i) const
00030 {
00031     return _set[int(i)];
00032 }
00033 
00034 const char WvStringMask::first() const
00035 {
00036     return _first;
00037 }
00038 
00039 void WvStringMask::zap()
00040 {
00041     memset(_set, 0, sizeof(bool) * sizeof(_set));
00042     _first = '\0';
00043 }
00044 
00045 void WvStringMask::set(const char c, bool value)
00046 {
00047     if (!_first)
00048         _first = c;
00049 
00050     _set[unsigned(c)] = value;
00051 }
00052 
00053 void WvStringMask::set(WvStringParm s, bool value)
00054 {
00055     if (!s.isnull())
00056     {
00057         const char *c = s.cstr();
00058 
00059         if (!_first)
00060             _first = *c;
00061 
00062         while (*c)
00063         {
00064             _set[unsigned(*c)] = value;
00065             ++c;
00066         }
00067     }
00068 }

Generated on Thu May 25 21:51:04 2006 for WvStreams by  doxygen 1.4.6