1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
/**
\mainpage libpyzy - The Chinese PinYin and Bopomofo conversion library.
Sample code
\code
#include <PyZy/InputContext.h>
#include <PyZy/Variant.h>
#include <iostream>
// observer class to get a notification from |InputContext|.
class SampleObserver : public PyZy::InputContext::Observer {
public:
void commitText (PyZy::InputContext *context,
const std::string &commit_text) {
std::cout << "text is commited. [" << commit_text << "]" << std::endl;
}
void inputTextChanged (PyZy::InputContext *context) {
std::cout << "input text is changed. [" << context->inputText() << "]"
<< std::endl;
}
void preeditTextChanged (PyZy::InputContext *context) {
std::cout << "selected text is changed. [" << context->selectedText()
<< "]" << std::endl;
}
void auxiliaryTextChanged (PyZy::InputContext *context) {
std::cout << "conversion text is changed. ["
<< context->conversionText() << "]" << std::endl;
}
void candidatesChanged (PyZy::InputContext *context) {
std::cout << "candidates are changed." << std::endl;
// output first 5 candidates.
for (size_t i = 0; i < 5; ++i) {
PyZy::Candidate candidate;
if (!context->getCandidate(i, candidate)) {
break;
}
std::cout << " [" << i << "]: " << candidate.text << std::endl;
}
}
void cursorChanged (PyZy::InputContext *context) {
std::cout << "cursor position is commited. [" << context->cursor()
<< "]" << std::endl;
}
};
int main() {
PyZy::InputContext::init();
SampleObserver observer;
PyZy::InputContext *context = PyZy::InputContext::create(
PyZy::InputContext::FULL_PINYIN, &observer);
context->setProperty(PyZy::InputContext::PROPERTY_MODE_SIMP,
PyZy::Variant::fromBool (true));
context->insert('n');
context->insert('i');
context->insert('h');
context->insert('a');
context->insert('o');
if (context->hasCandidate(4)) {
context->selectCandidate(4);
}
context->commit(PyZy::InputContext::TYPE_CONVERTED);
PyZy::InputContext::finalize();
return 0;
}
\endcode
*/
|