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
24bool WvStringMask::operator[](const char c) const
25{
26 unsigned char uc = c;
27 return _set[uc];
28}
29
30const char WvStringMask::first() const
31{
32 return _first;
33}
34
36{
37 memset(_set, 0, sizeof(bool) * sizeof(_set));
38 _first = '\0';
39}
40
41void WvStringMask::set(const char c, bool value)
42{
43 if (!_first)
44 _first = c;
45
46 _set[unsigned(c)] = value;
47}
48
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}
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition wvstring.h:94
bool isnull() const
returns true if this string is null
Definition wvstring.h:290
const char * cstr() const
return a (const char *) for this string.
Definition wvstring.h:267
WvStringMask(WvStringParm s=WvString::null)
Create a WvStringMask out of a WvString.
void set(const char c, bool value)
Set a character 'c' to a particular truth value.
bool operator[](const char c) const
Look up a character.
void zap()
Clear the WvStringMask, so that all lookups return false.
const char first() const
Get the first character set into the mask.