# HG changeset patch
# User Marko Njezic
# Date 1341910409 -7200
# Node ID 5289c46f7a2573c4ac1a5605fc9eee002dff5aeb
# Parent 28f80b03c96c0a06b575257a4bcd21ab351a2d48
Add removal methods to ease manipulation.
diff -r 28f80b03c96c -r 5289c46f7a25 lexlib/CharacterSet.h
--- a/lexlib/CharacterSet.h Tue Jul 10 16:58:14 2012 +1000
+++ b/lexlib/CharacterSet.h Tue Jul 10 10:53:29 2012 +0200
@@ -16,6 +16,19 @@
int size;
bool valueAfter;
bool *bset;
+ void Change(int val, bool inSet) {
+ assert(val >= 0);
+ assert(val < size);
+ bset[val] = inSet;
+ }
+ void ChangeString(const char *setToChange, bool inSet) {
+ for (const char *cp=setToChange; *cp; cp++) {
+ int val = static_cast<unsigned char>(*cp);
+ assert(val >= 0);
+ assert(val < size);
+ bset[val] = inSet;
+ }
+ }
public:
enum setBase {
setNone=0,
@@ -67,17 +80,16 @@
return *this;
}
void Add(int val) {
- assert(val >= 0);
- assert(val < size);
- bset[val] = true;
+ Change(val, true);
}
void AddString(const char *setToAdd) {
- for (const char *cp=setToAdd; *cp; cp++) {
- int val = static_cast<unsigned char>(*cp);
- assert(val >= 0);
- assert(val < size);
- bset[val] = true;
- }
+ ChangeString(setToAdd, true);
+ }
+ void Remove(int val) {
+ Change(val, false);
+ }
+ void RemoveString(const char *setToRemove) {
+ ChangeString(setToRemove, false);
}
bool Contains(int val) const {
assert(val >= 0);