File: wvstringmask.cc

package info (click to toggle)
wvstreams 4.6.1-19
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,420 kB
  • sloc: cpp: 64,196; ansic: 4,154; sh: 4,025; makefile: 546; perl: 402
file content (64 lines) | stat: -rw-r--r-- 1,085 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* -*- Mode: C++ -*-
 * Worldvisions Weaver Software:
 *   Copyright (C) 2005 Net Integration Technologies, Inc.
 *
 * Implementation of an efficient lookup for a set characters.
 *
 * It is, however, a little space intensive, but you should statically
 * create them in your functions, and then they won't be so bad.
 */
#include "wvstringmask.h"

WvStringMask::WvStringMask(WvStringParm s)
{
    zap();
    set(s, true);
}

WvStringMask::WvStringMask(char c)
{
    zap();
    set(c, true);
}

bool WvStringMask::operator[](const char c) const
{
    unsigned char uc = c;
    return _set[uc];
}

const char WvStringMask::first() const
{
    return _first;
}

void WvStringMask::zap()
{
    memset(_set, 0, sizeof(bool) * sizeof(_set));
    _first = '\0';
}

void WvStringMask::set(const char c, bool value)
{
    if (!_first)
	_first = c;

    _set[unsigned(c)] = value;
}

void WvStringMask::set(WvStringParm s, bool value)
{
    if (!s.isnull())
    {
	const char *c = s.cstr();

	if (!_first)
	    _first = *c;

	while (*c)
	{
	    _set[unsigned(*c)] = value;
	    ++c;
	}
    }
}