Browse files

First case processKeyUTF8

  • Loading branch information...
1 parent c505ae3 commit 44b28d8ac5316767611f01c59b15c50b1bb5bbfd @cmpitg committed Jun 2, 2012
Showing with 38 additions and 10 deletions.
  1. +34 −8 src/utils.cpp
  2. +4 −2 src/utils.hpp
View
42 src/utils.cpp
@@ -625,9 +625,9 @@ namespace BoGo {
}
ustring addAccentToWord (ustring word, Accents accent) {
- // Case: removing accent
- if (accent == NO_ACCENT)
- return removeAccentFromWord (word);
+ // // Case: removing accent
+ // if (accent == NO_ACCENT)
+ // return removeAccentFromWord (word);
// Analyzing the word into 3 components
// comp[0] = consonantPiece #1
@@ -758,8 +758,8 @@ namespace BoGo {
}
ustring addMarkToWord (ustring word, Marks mark, gchar letter) {
- if (mark == NO_MARK)
- return removeAllMarksFromWord (word);
+ // if (mark == NO_MARK)
+ // return removeAllMarksFromWord (word);
_size_t_ pos = ustring::npos;
@@ -891,12 +891,38 @@ namespace BoGo {
// return ADD_CHAR;
// }
- ustring processKeyUTF8 (ustring text, char key, InputMethodT im) {
+ Accents getAccentFromWord (ustring word) {
+ for (_size_t_ i = 0; i < word.size (); i++) {
+ Accents c = getAccentFromChar (__(word[i]));
+ if (c != NO_ACCENT)
+ return c;
+ }
+ return NO_ACCENT;
+ }
+
+ ustring processKeyUTF8 (ustring text, char key, InputMethodT im,
+ guint BackspaceChar) {
+ // Case: Backspace character
+ if (key == BackspaceChar) {
+ _size_t_ pos = getLastPseudoWordPos (text);
+
+ // Case: no word inside text
+ if (pos == ustring::npos)
+ return text.substr (0, text.size () - 1);
+
+ ustring firstPart = text.substr (0, pos);
+ ustring lastWord = text.substr (pos);
+ Accents accent = getAccentFromWord (lastWord);
+ lastWord.replace (lastWord.size () - 1, 1, "");
+ return firstPart + addAccentToWord (lastWord, accent);
+ }
+
return "";
}
- ustring processKey (ustring text, char key, InputMethodT im) {
- return processKeyUTF8 (text, key, im);
+ ustring processKey (ustring text, char key, InputMethodT im,
+ guint BackspaceChar) {
+ return processKeyUTF8 (text, key, im, BackspaceChar);
}
// ustring processKey (gchar key, ustring text, InputMethodT im) {
View
6 src/utils.hpp
@@ -283,11 +283,13 @@ namespace BoGo {
ustring processKeyUTF8 (ustring text,
char key,
- InputMethodT im = makeStandardIM (IM_SIMPLETELEX));
+ InputMethodT im = makeStandardIM (IM_SIMPLETELEX),
+ guint BackspaceChar = BACKSPACE_CODE);
ustring processKey (ustring text,
char key,
- InputMethodT im = makeStandardIM (IM_SIMPLETELEX));
+ InputMethodT im = makeStandardIM (IM_SIMPLETELEX),
+ guint BackspaceChar = BACKSPACE_CODE);
void processKey (const char *text,
char key,

0 comments on commit 44b28d8

Please sign in to comment.