34 #ifndef _moot_FLAVOR_H 35 #define _moot_FLAVOR_H 94 Rule(
const mootFlavorStr &label=
"",
const std::string ®ex=
"")
95 : lab(label), id(0), re_s(regex), re_t(NULL)
100 : lab(r.
lab), id(r.
id), re_s(r.
re_s), re_t(NULL)
114 inline bool operator==(
const Rule &r2)
const 115 {
return lab==r2.
lab && re_s==r2.
re_s; };
118 inline Rule& operator=(
const Rule &r2)
119 { lab=r2.
lab;
id=r2.
id; re_s=r2.
re_s; compile();
return *
this; };
126 inline bool match(
const char *s)
const 128 if (!re_t)
return false;
129 return regexec(re_t, s, 0, NULL, 0)==0;
133 inline bool match(
const std::string &s)
const 134 {
return match(s.c_str()); };
153 mootTaster(
const mootFlavorStr &default_label=
"", mootFlavorID default_id=0)
154 : nolabel(default_label), noid(default_id)
155 { set_default_rules(); };
170 {
return rules.size(); };
174 {
return rules.empty(); };
182 {
return operator==(builtinTaster); };
196 labels.insert(r.
lab);
200 inline void append_rule(
const mootFlavorStr &label,
const std::string ®ex)
201 { append_rule(
Rule(label,regex)); };
204 void set_default_label(
const mootFlavorStr &label,
bool update_rules=
true);
212 {
return labels.find(l) != labels.end(); };
220 Rules::const_iterator find(
const char *s)
const;
223 inline Rules::const_iterator
find(
const std::string &s)
const 224 {
return find(s.c_str()); };
228 inline const mootFlavorStr&
flavor(
const char *s)
const 230 Rules::const_iterator ri = find(s);
231 return (ri == rules.end()) ? nolabel : ri->lab;
235 inline const mootFlavorStr&
flavor(
const string &s)
const 236 {
return flavor(s.c_str()); };
242 Rules::const_iterator ri = find(s);
243 return (ri == rules.end()) ? noid : ri->id;
248 {
return flavor_id(s.c_str()); };
269 bool load(
const char *filename,
const std::string &prefix=
"");
272 bool load(
const std::string &filename,
const std::string &prefix=
"")
273 {
return load(filename.c_str(), prefix); };
276 void set_default_rules(
void);
287 bool save(
const char *filename,
const std::string &prefix=
"")
const;
290 bool save(
const std::string &filename,
const std::string &prefix=
"")
const 291 {
return save(filename.c_str(), prefix); };
294 bool save(FILE *f,
const std::string &prefix=
"")
const Definition: mootAssocVector.h:39
~mootTaster()
Definition: mootFlavor.h:158
size_t size() const
Definition: mootFlavor.h:169
UInt mootFlavorID
Definition: mootFlavor.h:45
High-level heuristic token classifier .
Definition: mootFlavor.h:62
mootio abstraction layer for C FILE*s
void append_rule(const Rule &r)
Definition: mootFlavor.h:193
void append_rule(const mootFlavorStr &label, const std::string ®ex)
Definition: mootFlavor.h:200
mootTaster(const mootFlavorStr &default_label="", mootFlavorID default_id=0)
Definition: mootFlavor.h:153
string mootFlavorStr
Definition: mootFlavor.h:44
Rules::const_iterator find(const std::string &s) const
Definition: mootFlavor.h:223
Abstract base class for output stream wrappers.
Definition: mootIO.h:194
bool save(const std::string &filename, const std::string &prefix="") const
Definition: mootFlavor.h:290
mootFlavorID flavor_id(const string &s) const
Definition: mootFlavor.h:247
vector< Rule > Rules
Definition: mootFlavor.h:141
const mootFlavorStr & flavor(const string &s) const
Definition: mootFlavor.h:235
mootFlavorID flavor_id(const char *s) const
Definition: mootFlavor.h:240
bool save(FILE *f, const std::string &prefix="") const
Definition: mootFlavor.h:294
mootFlavorID noid
id to return if no rule matches (default: empty)
Definition: mootFlavor.h:145
bool has_label(const mootFlavorStr &l) const
Definition: mootFlavor.h:211
BinUInt UInt
Definition: mootTypes.h:86
const mootTaster builtinTaster
Rules rules
matching heuristics in order of decreasing priority
Definition: mootFlavor.h:143
const mootFlavorStr & flavor(const char *s) const
Definition: mootFlavor.h:228
type for a single regex-based token classification heuristic
Definition: mootFlavor.h:74
bool empty() const
Definition: mootFlavor.h:173
mootFlavorID id
numeric id (zero by default)
Definition: mootFlavor.h:79
bool operator==(const mootTaster &t2) const
Definition: mootFlavor.h:177
generic I/O abstraction layer
bool is_builtin(void) const
Definition: mootFlavor.h:181
string re_s
POSIX.2 regex to match ("extended" regex string; see regex(7) manpage)
Definition: mootFlavor.h:80
Common typedefs and constants.
Wrapper class for C FILE* streams.
Definition: mootCIO.h:54
mootFlavorStr lab
symbolic label
Definition: mootFlavor.h:78
bool match(const std::string &s) const
Definition: mootFlavor.h:133
set< mootFlavorStr > labels
set of all flavor labels
Definition: mootFlavor.h:146
bool load(const std::string &filename, const std::string &prefix="")
Definition: mootFlavor.h:272
mootFlavorStr nolabel
label to return if no rule matches (default: empty)
Definition: mootFlavor.h:144
Abstract base class for input stream wrappers.
Definition: mootIO.h:129
mootTaster & operator=(const mootTaster &t2)
Definition: mootFlavor.h:185