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
|
#ifndef acommon_filter_char_hh
#define acommon_filter_char_hh
// This file is part of The New Aspell
// Copyright (C) 2002 by Kevin Atkinson under the GNU LGPL license
// version 2.0 or 2.1. You should have received a copy of the LGPL
// license along with this library if you did not you can find
// it at http://www.gnu.org/.
namespace acommon {
struct FilterChar {
unsigned int chr;
unsigned int width; // width must always be < 256
typedef unsigned int Chr;
typedef unsigned int Width;
explicit FilterChar(Chr c = 0, Width w = 1)
: chr(c), width(w) {}
FilterChar(Chr c, FilterChar o)
: chr(c), width(o.width) {}
static Width sum(const FilterChar * o, const FilterChar * stop) {
Width total = 0;
for (; o != stop; ++o)
total += o->width;
return total;
}
static Width sum(const FilterChar * o, unsigned int size) {
return sum(o, o+size);
}
FilterChar(Chr c, const FilterChar * o, unsigned int size)
: chr(c), width(sum(o,size)) {}
FilterChar(Chr c, const FilterChar * o, const FilterChar * stop)
: chr(c), width(sum(o,stop)) {}
operator Chr () const {return chr;}
FilterChar & operator= (Chr c) {chr = c; return *this;}
};
static inline bool operator==(FilterChar lhs, FilterChar rhs)
{
return lhs.chr == rhs.chr;
}
static inline bool operator!=(FilterChar lhs, FilterChar rhs)
{
return lhs.chr != rhs.chr;
}
}
#endif
|