source: icGREP/icgrep-devel/icgrep/re/re_cc.cpp

Last change on this file was 5795, checked in by cameron, 4 weeks ago

Adding Alphabet to CCs: initial check-in

File size: 2.1 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include "re_cc.h"
8#include <llvm/Support/Compiler.h>
9#include <sstream>
10
11namespace re {
12
13std::string CC::canonicalName(const CC_type type) const {
14    std::stringstream name;
15    name << std::hex;
16    if ((type == CC_type::ByteClass) && (max_codepoint() >= 0x80)) {
17        name << "BC";
18    } else {
19        name << "CC";
20    }
21    char separator = '_';
22    for (const interval_t i : *this) {
23        name << separator;
24        if (lo_codepoint(i) == hi_codepoint(i)) {
25            name << lo_codepoint(i);
26        }
27        else {
28            name << lo_codepoint(i) << '_' << hi_codepoint(i);
29        }
30        separator = ',';
31    }
32    return name.str();
33}
34   
35CC::CC(const cc::Alphabet * alphabet)
36: RE(ClassTypeId::CC)
37, UnicodeSet()
38, mAlphabet(alphabet) {}
39
40
41CC::CC(const CC & cc)
42: RE(ClassTypeId::CC)
43, UCD::UnicodeSet(cc)
44, mAlphabet(cc.getAlphabet()) {}
45
46
47CC::CC(const codepoint_t codepoint, const cc::Alphabet * alphabet)
48: RE(ClassTypeId::CC)
49, UCD::UnicodeSet(codepoint)
50, mAlphabet(alphabet) {}
51
52
53CC::CC(const codepoint_t lo_codepoint, const codepoint_t hi_codepoint, const cc::Alphabet * alphabet)
54: RE(ClassTypeId::CC)
55, UCD::UnicodeSet(lo_codepoint, hi_codepoint)
56, mAlphabet(alphabet) {}
57
58
59CC::CC(const CC * cc1, const CC * cc2)
60: RE(ClassTypeId::CC)
61, UCD::UnicodeSet(std::move(*cc1 + *cc2))
62, mAlphabet(cc1->getAlphabet()) {
63    assert (cc1->getAlphabet() == cc2->getAlphabet());
64}
65
66
67CC::CC(const UCD::UnicodeSet && set, const cc::Alphabet * alphabet)
68: RE(ClassTypeId::CC)
69, UCD::UnicodeSet(std::move(set))
70, mAlphabet(alphabet) {}
71
72
73CC::CC(std::initializer_list<interval_t>::iterator begin, std::initializer_list<interval_t>::iterator end, const cc::Alphabet * alphabet)
74: RE(ClassTypeId::CC)
75, UCD::UnicodeSet(begin, end)
76, mAlphabet(alphabet) {}
77
78
79CC::CC(const std::vector<interval_t>::iterator begin, const std::vector<interval_t>::iterator end, const cc::Alphabet * alphabet)
80: RE(ClassTypeId::CC)
81, UCD::UnicodeSet(begin, end)
82, mAlphabet(alphabet) {}
83
84}
Note: See TracBrowser for help on using the repository browser.