00001
00002
00004
00005
00006
00008
00009 #include "Alphabet.h"
00010 #include "AlphabetMap.h"
00011
00012
00013
00014
00015 using namespace Dasher;
00016 using namespace std;
00017
00018
00019 CAlphabet::CAlphabet() : m_DefaultEncoding(Opts::Western), m_Orientation(Opts::LeftToRight), m_Groups(0)
00020 {
00021 m_Characters.push_back("");
00022 m_Display.push_back("");
00023 m_Colours.push_back("");
00024 m_Foreground.push_back("");
00025 m_Group.push_back(0);
00026 }
00027
00028
00029 void CAlphabet::GetSymbols(vector<symbol>* Symbols, string* Input, bool IsMore)
00030 {
00031 string Tmp;
00032 symbol CurSymbol=0, TmpSymbol=0;
00033 bool KeyIsPrefix;
00034
00035 int extras;
00036 unsigned int bit;
00037
00038 for (unsigned int i=0; i<Input->size(); i++) {
00039
00040 Tmp = (*Input)[i];
00041
00042
00043
00044
00045
00046
00047 if ((*Input)[i] & 0x80) {
00048 extras = 1;
00049 for (bit = 0x20; ((*Input)[i] & bit) != 0; bit >>= 1)
00050 extras++;
00051 if (extras > 5) {
00052 }
00053 while (extras-->0) {
00054 Tmp += (*Input)[++i];
00055 }
00056 }
00057
00058 CurSymbol = TextMap.Get(Tmp, &KeyIsPrefix);
00059
00060 if (KeyIsPrefix) {
00061 CurSymbol = 0;
00062 for (; i<Input->size(); i++) {
00063
00064 Tmp += (*Input)[i];
00065
00066 TmpSymbol = TextMap.Get(Tmp, &KeyIsPrefix);
00067 if (TmpSymbol>0) {
00068 CurSymbol = TmpSymbol;
00069 }
00070 if (!KeyIsPrefix) {
00071 if (CurSymbol!=0) {
00072 Symbols->push_back(CurSymbol);
00073 } else {
00074 i -= Tmp.size()-1;
00075
00076 Tmp = "";
00077 }
00078 break;
00079 }
00080 }
00081 } else {
00082 if (CurSymbol!=0)
00083 Symbols->push_back(CurSymbol);
00084 }
00085 }
00086
00087 if (IsMore)
00088 if (KeyIsPrefix)
00089 *Input = Tmp;
00090 else
00091 *Input = "";
00092 else
00093 if (KeyIsPrefix)
00094 Symbols->push_back(CurSymbol);
00095 }
00096
00097
00098
00099 void CAlphabet::AddChar(const string NewCharacter, const string Display, const string Colour, const string Foreground)
00100 {
00101 m_Characters.push_back(NewCharacter);
00102 m_Display.push_back(Display);
00103 m_Colours.push_back(Colour);
00104 m_Foreground.push_back(Foreground);
00105 m_Group.push_back(m_Groups);
00106
00107 symbol ThisSymbol = m_Characters.size()-1;
00108 TextMap.Add(NewCharacter, ThisSymbol);
00109 }
00110
00111
00112 void CAlphabet::StartNewGroup()
00113 {
00114 m_Groups++;
00115 }
00116
00117
00118
00119 void CAlphabet::dump() const {
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 }
00131
00132 int CAlphabet::GetTextColour(symbol Symbol)
00133 {
00134 std::string TextColour=m_Foreground[Symbol];
00135 if (TextColour != "") {
00136 return atoi(TextColour.c_str());
00137 } else {
00138 return 0;
00139 }
00140 }