Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Alphabet.cpp

Go to the documentation of this file.
00001 // Alphabet.cpp
00002 //
00004 //
00005 // Copyright (c) 2001-2002 David Ward
00006 //
00008 
00009 #include "Alphabet.h"
00010 #include "AlphabetMap.h"
00011 
00012 //#include <iostream>
00013 //WinCE doesn't have iostream!
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         // int z= Input->size();
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                 /* The string we've been given is in UTF-8. The symbols are
00043                    also in UTF-8, so we need to pass the entire UTF-8 character
00044                    which may be several bytes long. RFC 2279 describes this
00045                    encoding */
00046 
00047                 if ((*Input)[i] & 0x80) { // Character is more than 1 byte long
00048                   extras = 1;
00049                   for (bit = 0x20; ((*Input)[i] & bit) != 0; bit >>= 1)
00050                     extras++;
00051                   if (extras > 5) {
00052                   } // Malformed character
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                                                 //Tmp.erase(Tmp.begin(), Tmp.end());
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 // add single char to the character set
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 // diagnostic dump of character set
00119 void CAlphabet::dump() const {
00120 // TODO
00121 /*
00122         dchar deb[256];
00123         unsigned int i;
00124         for (i=1;i<m_vtCharacters.size();i++) {
00125                 //wsprintf(deb,TEXT("%d %c %d\n"),i,m_vtCharacters[i],m_viGroup[i]); // Windows specific
00126                 Usprintf(deb,TEXT("%d %c %d\n"),i,m_vtCharacters[i],m_viGroup[i]);
00127                 DebugOutput(deb);
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 }

Generated on Sat Nov 5 16:15:59 2005 for OPIE by  doxygen 1.4.2