Diffstat (limited to 'inputmethods/dasher/Alphabet.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/dasher/Alphabet.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/inputmethods/dasher/Alphabet.cpp b/inputmethods/dasher/Alphabet.cpp index dc58b35..6327d8a 100644 --- a/inputmethods/dasher/Alphabet.cpp +++ b/inputmethods/dasher/Alphabet.cpp | |||
@@ -1,140 +1,140 @@ | |||
1 | // Alphabet.cpp | 1 | // Alphabet.cpp |
2 | // | 2 | // |
3 | ///////////////////////////////////////////////////////////////////////////// | 3 | ///////////////////////////////////////////////////////////////////////////// |
4 | // | 4 | // |
5 | // Copyright (c) 2001-2002 David Ward | 5 | // Copyright (c) 2001-2002 David Ward |
6 | // | 6 | // |
7 | ///////////////////////////////////////////////////////////////////////////// | 7 | ///////////////////////////////////////////////////////////////////////////// |
8 | 8 | ||
9 | #include "Alphabet.h" | 9 | #include "Alphabet.h" |
10 | #include "AlphabetMap.h" | 10 | #include "AlphabetMap.h" |
11 | 11 | ||
12 | //#include <iostream> | 12 | //#include <iostream> |
13 | //WinCE doesn't have iostream! | 13 | //WinCE doesn't have iostream! |
14 | 14 | ||
15 | using namespace Dasher; | 15 | using namespace Dasher; |
16 | using namespace std; | 16 | using namespace std; |
17 | 17 | ||
18 | 18 | ||
19 | CAlphabet::CAlphabet() : m_Groups(0), m_DefaultEncoding(Opts::Western), m_Orientation(Opts::LeftToRight) | 19 | CAlphabet::CAlphabet() : m_DefaultEncoding(Opts::Western), m_Orientation(Opts::LeftToRight), m_Groups(0) |
20 | { | 20 | { |
21 | m_Characters.push_back(""); | 21 | m_Characters.push_back(""); |
22 | m_Display.push_back(""); | 22 | m_Display.push_back(""); |
23 | m_Colours.push_back(""); | 23 | m_Colours.push_back(""); |
24 | m_Foreground.push_back(""); | 24 | m_Foreground.push_back(""); |
25 | m_Group.push_back(0); | 25 | m_Group.push_back(0); |
26 | } | 26 | } |
27 | 27 | ||
28 | 28 | ||
29 | void CAlphabet::GetSymbols(vector<symbol>* Symbols, string* Input, bool IsMore) | 29 | void CAlphabet::GetSymbols(vector<symbol>* Symbols, string* Input, bool IsMore) |
30 | { | 30 | { |
31 | string Tmp; | 31 | string Tmp; |
32 | symbol CurSymbol=0, TmpSymbol=0; | 32 | symbol CurSymbol=0, TmpSymbol=0; |
33 | bool KeyIsPrefix; | 33 | bool KeyIsPrefix; |
34 | int z= Input->size(); | 34 | // int z= Input->size(); |
35 | int extras; | 35 | int extras; |
36 | unsigned int bit; | 36 | unsigned int bit; |
37 | 37 | ||
38 | for (unsigned int i=0; i<Input->size(); i++) { | 38 | for (unsigned int i=0; i<Input->size(); i++) { |
39 | 39 | ||
40 | Tmp = (*Input)[i]; | 40 | Tmp = (*Input)[i]; |
41 | 41 | ||
42 | /* The string we've been given is in UTF-8. The symbols are | 42 | /* The string we've been given is in UTF-8. The symbols are |
43 | also in UTF-8, so we need to pass the entire UTF-8 character | 43 | also in UTF-8, so we need to pass the entire UTF-8 character |
44 | which may be several bytes long. RFC 2279 describes this | 44 | which may be several bytes long. RFC 2279 describes this |
45 | encoding */ | 45 | encoding */ |
46 | 46 | ||
47 | if ((*Input)[i] & 0x80) { // Character is more than 1 byte long | 47 | if ((*Input)[i] & 0x80) { // Character is more than 1 byte long |
48 | extras = 1; | 48 | extras = 1; |
49 | for (bit = 0x20; ((*Input)[i] & bit) != 0; bit >>= 1) | 49 | for (bit = 0x20; ((*Input)[i] & bit) != 0; bit >>= 1) |
50 | extras++; | 50 | extras++; |
51 | if (extras > 5) { | 51 | if (extras > 5) { |
52 | } // Malformed character | 52 | } // Malformed character |
53 | while (extras-->0) { | 53 | while (extras-->0) { |
54 | Tmp += (*Input)[++i]; | 54 | Tmp += (*Input)[++i]; |
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | CurSymbol = TextMap.Get(Tmp, &KeyIsPrefix); | 58 | CurSymbol = TextMap.Get(Tmp, &KeyIsPrefix); |
59 | 59 | ||
60 | if (KeyIsPrefix) { | 60 | if (KeyIsPrefix) { |
61 | CurSymbol = 0; | 61 | CurSymbol = 0; |
62 | for (; i<Input->size(); i++) { | 62 | for (; i<Input->size(); i++) { |
63 | 63 | ||
64 | Tmp += (*Input)[i]; | 64 | Tmp += (*Input)[i]; |
65 | 65 | ||
66 | TmpSymbol = TextMap.Get(Tmp, &KeyIsPrefix); | 66 | TmpSymbol = TextMap.Get(Tmp, &KeyIsPrefix); |
67 | if (TmpSymbol>0) { | 67 | if (TmpSymbol>0) { |
68 | CurSymbol = TmpSymbol; | 68 | CurSymbol = TmpSymbol; |
69 | } | 69 | } |
70 | if (!KeyIsPrefix) { | 70 | if (!KeyIsPrefix) { |
71 | if (CurSymbol!=0) { | 71 | if (CurSymbol!=0) { |
72 | Symbols->push_back(CurSymbol); | 72 | Symbols->push_back(CurSymbol); |
73 | } else { | 73 | } else { |
74 | i -= Tmp.size()-1; | 74 | i -= Tmp.size()-1; |
75 | //Tmp.erase(Tmp.begin(), Tmp.end()); | 75 | //Tmp.erase(Tmp.begin(), Tmp.end()); |
76 | Tmp = ""; | 76 | Tmp = ""; |
77 | } | 77 | } |
78 | break; | 78 | break; |
79 | } | 79 | } |
80 | } | 80 | } |
81 | } else { | 81 | } else { |
82 | if (CurSymbol!=0) | 82 | if (CurSymbol!=0) |
83 | Symbols->push_back(CurSymbol); | 83 | Symbols->push_back(CurSymbol); |
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | if (IsMore) | 87 | if (IsMore) |
88 | if (KeyIsPrefix) | 88 | if (KeyIsPrefix) |
89 | *Input = Tmp; | 89 | *Input = Tmp; |
90 | else | 90 | else |
91 | *Input = ""; | 91 | *Input = ""; |
92 | else | 92 | else |
93 | if (KeyIsPrefix) | 93 | if (KeyIsPrefix) |
94 | Symbols->push_back(CurSymbol); | 94 | Symbols->push_back(CurSymbol); |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | // add single char to the character set | 98 | // add single char to the character set |
99 | void CAlphabet::AddChar(const string NewCharacter, const string Display, const string Colour, const string Foreground) | 99 | void CAlphabet::AddChar(const string NewCharacter, const string Display, const string Colour, const string Foreground) |
100 | { | 100 | { |
101 | m_Characters.push_back(NewCharacter); | 101 | m_Characters.push_back(NewCharacter); |
102 | m_Display.push_back(Display); | 102 | m_Display.push_back(Display); |
103 | m_Colours.push_back(Colour); | 103 | m_Colours.push_back(Colour); |
104 | m_Foreground.push_back(Foreground); | 104 | m_Foreground.push_back(Foreground); |
105 | m_Group.push_back(m_Groups); | 105 | m_Group.push_back(m_Groups); |
106 | 106 | ||
107 | symbol ThisSymbol = m_Characters.size()-1; | 107 | symbol ThisSymbol = m_Characters.size()-1; |
108 | TextMap.Add(NewCharacter, ThisSymbol); | 108 | TextMap.Add(NewCharacter, ThisSymbol); |
109 | } | 109 | } |
110 | 110 | ||
111 | 111 | ||
112 | void CAlphabet::StartNewGroup() | 112 | void CAlphabet::StartNewGroup() |
113 | { | 113 | { |
114 | m_Groups++; | 114 | m_Groups++; |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | // diagnostic dump of character set | 118 | // diagnostic dump of character set |
119 | void CAlphabet::dump() const { | 119 | void CAlphabet::dump() const { |
120 | // TODO | 120 | // TODO |
121 | /* | 121 | /* |
122 | dchar deb[256]; | 122 | dchar deb[256]; |
123 | unsigned int i; | 123 | unsigned int i; |
124 | for (i=1;i<m_vtCharacters.size();i++) { | 124 | for (i=1;i<m_vtCharacters.size();i++) { |
125 | //wsprintf(deb,TEXT("%d %c %d\n"),i,m_vtCharacters[i],m_viGroup[i]); // Windows specific | 125 | //wsprintf(deb,TEXT("%d %c %d\n"),i,m_vtCharacters[i],m_viGroup[i]); // Windows specific |
126 | Usprintf(deb,TEXT("%d %c %d\n"),i,m_vtCharacters[i],m_viGroup[i]); | 126 | Usprintf(deb,TEXT("%d %c %d\n"),i,m_vtCharacters[i],m_viGroup[i]); |
127 | DebugOutput(deb); | 127 | DebugOutput(deb); |
128 | } | 128 | } |
129 | */ | 129 | */ |
130 | } | 130 | } |
131 | 131 | ||
132 | int CAlphabet::GetTextColour(symbol Symbol) | 132 | int CAlphabet::GetTextColour(symbol Symbol) |
133 | { | 133 | { |
134 | std::string TextColour=m_Foreground[Symbol]; | 134 | std::string TextColour=m_Foreground[Symbol]; |
135 | if (TextColour != "") { | 135 | if (TextColour != "") { |
136 | return atoi(TextColour.c_str()); | 136 | return atoi(TextColour.c_str()); |
137 | } else { | 137 | } else { |
138 | return 0; | 138 | return 0; |
139 | } | 139 | } |
140 | } | 140 | } |