Debian Codegraph @

src/varnam_utils.h

raw
1 #ifndef _FCITX_VARNAM_UTILS_H_
2 #define _FCITX_VARNAM_UTILS_H_
3
4 #include <fcitx-utils/key.h>
5 #include <fcitx-utils/log.h>
6 #include <string>
7
8 namespace fcitx {
9
10 typedef struct varnam_word_t {
11 const char *text;
12 int confidence;
13 } vword;
14
15 enum PageAction { PREV_PAGE, NEXT_PAGE, PREV_CANDIDATE, NEXT_CANDIDATE };
16
17 // LOGGERS
18 const ::fcitx ::LogCategory &VARNAM();
19 #define VARNAM_INFO() FCITX_LOGC(VARNAM, Info)
20 #define VARNAM_WARN() FCITX_LOGC(VARNAM, Warn)
21
22 const static char INSCRIPT[] = "inscript";
23
24 static KeyList selectionKeys = {
25 Key{FcitxKey_1}, Key{FcitxKey_2}, Key{FcitxKey_3}, Key{FcitxKey_4},
26 Key{FcitxKey_5}, Key{FcitxKey_6}, Key{FcitxKey_7}, Key{FcitxKey_8},
27 Key{FcitxKey_9}, Key{FcitxKey_0},
28 };
29
30 static KeyList keyListToFilter = {
31 Key{FcitxKey_Shift_L}, Key{FcitxKey_Shift_R}, Key{FcitxKey_Control_L},
32 Key{FcitxKey_Control_R}, Key{FcitxKey_Alt_L}, Key{FcitxKey_Alt_R},
33 Key{FcitxKey_Super_L}, Key{FcitxKey_Super_R}};
34
35 // check if the input is a word break character
36 bool isWordBreak(FcitxKeySym keyVal, bool inscriptMode = false);
37
38 // get the word break character
39 const std::string getWordBreakChar(FcitxKeySym keyVal,
40 bool inscriptMode = false);
41
42 // get the number of unicode character units in a code point
43 int getNumOfUTFCharUnits(char32_t code_point);
44
45 // varnam learn function, to run on a separate thread
46 void varnam_learn_word(int varnam_handle_id, const std::string &word_,
47 int weight);
48
49 // varnam unlearn function, to run on a separate thread
50 void varnam_unlearn_word(int varnam_handle_id, const std::string &word_);
51
52 // check the current key and states against a key list and return the index
53 template <typename Container>
54 int keyListIndexWithState(const fcitx::Key key, const Container &c,
55 const fcitx::KeyStates states) {
56 size_t idx = 0;
57 for (const fcitx::Key &toCheck : c) {
58 if (key.check(toCheck.sym(), states)) {
59 break;
60 }
61 idx++;
62 }
63 if (idx == c.size()) {
64 return -1;
65 }
66 return idx;
67 }
68
69 } // namespace fcitx
70
71 #endif