WvStreams
wvstringmask.cc
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 2005 Net Integration Technologies, Inc.
4  *
5  * Implementation of an efficient lookup for a set characters.
6  *
7  * It is, however, a little space intensive, but you should statically
8  * create them in your functions, and then they won't be so bad.
9  */
10 #include "wvstringmask.h"
11 
13 {
14  zap();
15  set(s, true);
16 }
17 
19 {
20  zap();
21  set(c, true);
22 }
23 
24 bool WvStringMask::operator[](const char c) const
25 {
26  unsigned char uc = c;
27  return _set[uc];
28 }
29 
30 const char WvStringMask::first() const
31 {
32  return _first;
33 }
34 
36 {
37  memset(_set, 0, sizeof(bool) * sizeof(_set));
38  _first = '\0';
39 }
40 
41 void WvStringMask::set(const char c, bool value)
42 {
43  if (!_first)
44  _first = c;
45 
46  _set[unsigned(c)] = value;
47 }
48 
49 void WvStringMask::set(WvStringParm s, bool value)
50 {
51  if (!s.isnull())
52  {
53  const char *c = s.cstr();
54 
55  if (!_first)
56  _first = *c;
57 
58  while (*c)
59  {
60  _set[unsigned(*c)] = value;
61  ++c;
62  }
63  }
64 }
WvStringMask::WvStringMask
WvStringMask(WvStringParm s=WvString::null)
Create a WvStringMask out of a WvString.
Definition: wvstringmask.cc:12
WvStringMask::zap
void zap()
Clear the WvStringMask, so that all lookups return false.
Definition: wvstringmask.cc:35
WvStringMask::first
const char first() const
Get the first character set into the mask.
Definition: wvstringmask.cc:30
WvStringMask::operator[]
bool operator[](const char c) const
Look up a character.
Definition: wvstringmask.cc:24
WvStringMask::set
void set(const char c, bool value)
Set a character 'c' to a particular truth value.
Definition: wvstringmask.cc:41