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

Last change on this file since 5742 was 5742, checked in by nmedfort, 19 months ago

Improvements to memory usage of CCs

File size: 2.0 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 <UCD/CaseFolding.h>
10#include <sstream>
11
12namespace re {
13
14std::string CC::canonicalName(const CC_type type) const {
15    std::stringstream name;
16    name << std::hex;
17    if ((type == ByteClass) && (max_codepoint() >= 0x80)) {
18        name << "BC";
19    } else {
20        name << "CC";
21    }
22    char separator = '_';
23    for (const interval_t i : *this) {
24        name << separator;
25        if (lo_codepoint(i) == hi_codepoint(i)) {
26            name << lo_codepoint(i);
27        }
28        else {
29            name << lo_codepoint(i) << '_' << hi_codepoint(i);
30        }
31        separator = ',';
32    }
33    return name.str();
34}
35   
36CC * caseInsensitize(const CC * cc) {
37    CC * cci = makeCC();
38    for (const interval_t i : *cc) {
39        caseInsensitiveInsertRange(cci, lo_codepoint(i), hi_codepoint(i));
40    }
41    return cci;
42}
43
44CC::CC()
45: RE(ClassTypeId::CC), UnicodeSet() {
46
47}
48
49CC::CC(const CC & cc)
50: RE(ClassTypeId::CC)
51, UCD::UnicodeSet(cc) {
52
53}
54
55CC::CC(const codepoint_t codepoint)
56: RE(ClassTypeId::CC)
57, UCD::UnicodeSet(codepoint, mAllocator) {
58
59}
60
61CC::CC(const codepoint_t lo_codepoint, const codepoint_t hi_codepoint)
62: RE(ClassTypeId::CC)
63, UCD::UnicodeSet(lo_codepoint, hi_codepoint, mAllocator) {
64
65}
66
67CC::CC(const CC * cc1, const CC * cc2)
68: RE(ClassTypeId::CC)
69, UCD::UnicodeSet(std::move(*cc1 + *cc2)) {
70
71}
72
73CC::CC(UCD::UnicodeSet && set)
74: RE(ClassTypeId::CC)
75, UCD::UnicodeSet(std::move(set), mAllocator) {
76
77}
78
79CC::CC(std::initializer_list<interval_t>::iterator begin, std::initializer_list<interval_t>::iterator end)
80: RE(ClassTypeId::CC)
81, UCD::UnicodeSet(begin, end, mAllocator)
82{
83
84}
85
86CC::CC(const std::vector<interval_t>::iterator begin, const std::vector<interval_t>::iterator end)
87: RE(ClassTypeId::CC)
88, UCD::UnicodeSet(begin, end, mAllocator)
89{
90
91}
92
93}
Note: See TracBrowser for help on using the repository browser.