source: icGREP/icgrep-devel/icgrep/cc/alphabet.cpp @ 5795

Last change on this file since 5795 was 5795, checked in by cameron, 13 months ago

Adding Alphabet to CCs: initial check-in

File size: 1.3 KB
Line 
1/*
2 *  Copyright (c) 2017 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
8#include "alphabet.h"
9#include <llvm/Support/ErrorHandling.h>
10
11namespace cc {
12   
13UnicodeMappableAlphabet::UnicodeMappableAlphabet(std::string alphabetName,
14                                                 unsigned unicodeCommon,
15                                                 std::vector <UCD::codepoint_t> aboveCommon) :
16    Alphabet(alphabetName), mUnicodeCommon(unicodeCommon), mAboveCommon(aboveCommon) {}
17
18UCD::codepoint_t UnicodeMappableAlphabet::toUnicode(const unsigned n) const {
19    UCD::codepoint_t cp = n;
20    if (n < mUnicodeCommon) return cp;
21    assert(n < mUnicodeCommon + mAboveCommon.size());
22    return mAboveCommon[n - mUnicodeCommon];
23}
24 
25unsigned UnicodeMappableAlphabet::fromUnicode(const UCD::codepoint_t codepoint) const {
26    unsigned n = codepoint;
27    if (n < mUnicodeCommon) return n;
28    for (unsigned i = 0; i < mAboveCommon.size(); i++) {
29        if (mAboveCommon[i] == codepoint) return mUnicodeCommon + i;
30    }
31    llvm::report_fatal_error("fromUnicode: codepoint not found in alphabet.");
32}
33
34CodeUnitAlphabet::CodeUnitAlphabet(std::string alphabetName, uint8_t bits) :
35    Alphabet(alphabetName), mCodeUnitBits(bits) {}
36
37}
Note: See TracBrowser for help on using the repository browser.