source: icGREP/icgrep-devel/icgrep/cc/alphabet.h @ 5797

Last change on this file since 5797 was 5797, checked in by cameron, 16 months ago

makeByte uses the Byte alphabet

File size: 2.5 KB
RevLine 
[5279]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#ifndef ALPHABET_H
8#define ALPHABET_H
9
10#include <string>
11#include <UCD/unicode_set.h>
[5795]12#include <vector>
[5279]13
[5795]14namespace cc {
[5279]15//
16// An Alphabet is the universe of characters used to form strings in
17// a given language, together with a mapping of those characters to
18// numerical character codes.
19//
20
21class Alphabet {
22public:
[5795]23    const std::string & getName() const { return mAlphabetName;}
24protected:
25    Alphabet(std::string alphabetName) : mAlphabetName(alphabetName) {}
26private:
27    std::string mAlphabetName;
28};
[5279]29
[5795]30class UnicodeMappableAlphabet : public Alphabet {
31public:
32    //  Alphabets may be formed by some subset of Unicode characters, together
[5797]33    //  with a mapping to and from Unicode.  The mapping is defined in terms of unicodeCommon:
34    //  the number of character codes (if any) such that all character codes in the range
[5795]35    //  0..unicodeCommon - 1 map to the same numeric value as the corresponding Unicode
36    //  codepoint, together with a vector defining the Unicode codepoints for consecutive
37    //  character codes (if any) above unicodeCommon - 1.
[5279]38   
[5795]39    UnicodeMappableAlphabet(std::string alphabetName,
40                            unsigned unicodeCommon,
41                            std::vector <UCD::codepoint_t> aboveCommon);
[5279]42   
43    //  The Unicode codepoint of the nth character (the character whose alphabet code is n).
[5795]44    UCD::codepoint_t toUnicode(const unsigned n) const;
[5279]45   
46    //  The ordinal position of the character whose Unicode codepoint value is ucp.
[5795]47    unsigned fromUnicode(const UCD::codepoint_t ucp) const;
[5279]48
[5281]49protected:
[5795]50    UCD::codepoint_t mCharSet;
51    UCD::codepoint_t mUnicodeCommon;
52    std::vector <UCD::codepoint_t> mAboveCommon;
[5279]53};
54
[5795]55class CodeUnitAlphabet : public Alphabet {
56public:
57    CodeUnitAlphabet(std::string alphabetName, uint8_t codeUnitBits);
58    uint8_t getCodeUnitBitWidth() { return mCodeUnitBits;}
59   
60private:
61    uint8_t mCodeUnitBits;
62};
[5279]63
[5795]64//  Some important alphabets are predefined.
[5279]65
[5797]66const extern UnicodeMappableAlphabet Unicode; // Unicode("Unicode", UCD::UNICODE_MAX, {})
[5279]67
[5797]68const extern UnicodeMappableAlphabet ASCII;  // ASCII("ASCII", 0x7F, {});
[5279]69
[5797]70const extern UnicodeMappableAlphabet ISO_Latin1; // ISO_Latin1("ISO_Latin1", 0xFF, {});
[5279]71
[5797]72const extern CodeUnitAlphabet Byte; // Byte("Byte", 8);
73   
74const extern CodeUnitAlphabet UTF16; // UTF16("UTF16", 16);
75   
[5795]76}
[5279]77
78#endif // ALPHABET_H
79
80
Note: See TracBrowser for help on using the repository browser.