C++ Portable Types Library (PTypes) Version 1.7

Top: Basic types: cset: Constructors

#include <ptypes.h>

cset::cset(const cset& s);
cset::cset(const char* setinit);

cset::cset() -- default constructor, initializes the set object to an empty set.

cset::cset(const cset& s) -- copy constructor.

cset::cset(const char* setinit) constructs a character set from a string. The setinit parameter is a sequence of characters, range specifiers and escape sequences. Range specifier consists of: lower boundary, dash "-" and higher boundary, e.g. "A-Z". Escape sequence begins with tilde "~" and can be followed by a two-digit hexadecimal number. Escape sequences are also used to include special characters tilde "~" and dash "-" (see examples below).

Constructing character sets using this interpreter can be a time-consuming operation. A better practice is to declare all constant character sets as static variables, so that the interpretation of all set constructing strings will be done only once during program startup.

An initializer string can also be passed to a cset object through assign() function.

Note: this constructor does not generate errors if the syntax is violated.


cset s1 = "135A-CZ";            // digits 1, 3, 5, letters A through C, and also Z
cset wspace1 = "~09~0d~0a ";    // tab, CR, LF and space
cset wspace2 = "~00-~20";       // all control and whitespace chars
cset s2 = ":@~~";               // colon, at and tilde (must be escaped with another tilde)

See also: Operators, Manipulation

PTypes home