source: icGREP/icgrep-devel/icgrep/re/re_grapheme_boundary.hpp @ 5033

Last change on this file since 5033 was 4841, checked in by nmedfort, 4 years ago

Update for grapheme cluster mode and boundaries.

File size: 1.9 KB
Line 
1#ifndef RE_GRAPHEME_BOUNDARY_HPP
2#define RE_GRAPHEME_BOUNDARY_HPP
3
4#include <re/re_re.h>
5
6namespace re {
7
8class GraphemeBoundary : public RE {
9public:
10    static inline bool classof(const RE * re) {
11        return re->getClassTypeId() == ClassTypeId::GraphemeBoundary;
12    }
13    static inline bool classof(const void *) {
14        return false;
15    }
16
17    enum class Type {
18        ClusterBoundary = 0     // g
19        , WordBoundary = 1      // w
20        , LineBreakBoundary = 2 // l
21        , SentenceBoundary = 3  // s
22    };
23
24    enum class Sense {Positive, Negative};
25
26    inline Type getType() const { return mType; }
27    GraphemeBoundary::Sense getSense() const {return mSense;}
28    inline RE * getExpression() const {return mExpression;}
29    inline void setExpression(RE * const r) { mExpression = r; }
30    inline Name * getBoundaryRule() const {return mBoundaryRule;}
31    inline void setBoundaryRule(Name * const r) { mBoundaryRule = r; }
32
33protected:
34    friend GraphemeBoundary * makeGraphemeBoundary(const Type type, const Sense sense, RE * expression);
35    GraphemeBoundary(const Type type, const Sense sense, RE * expression) : RE(ClassTypeId::GraphemeBoundary), mType(type), mSense(sense), mExpression(expression), mBoundaryRule(nullptr) {}
36    virtual ~GraphemeBoundary() {}
37
38private:
39    const Type      mType;
40    const Sense     mSense;
41    RE *            mExpression;
42    Name *          mBoundaryRule;
43};
44
45inline GraphemeBoundary * makeGraphemeBoundary(const GraphemeBoundary::Type type, const GraphemeBoundary::Sense sense, RE * expression) {
46    return new GraphemeBoundary(type, sense, expression);
47}
48
49inline GraphemeBoundary * makeGraphemeClusterBoundary(const GraphemeBoundary::Sense sense = GraphemeBoundary::Sense::Positive, RE * expression = nullptr) {
50    return makeGraphemeBoundary(GraphemeBoundary::Type::ClusterBoundary, sense, expression);
51}
52
53}
54
55#endif // RE_GRAPHEME_BOUNDARY_HPP
Note: See TracBrowser for help on using the repository browser.