aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cerence/xt9/xt9common/xt9jime.cpp
blob: aef4732959c331b3b0c2bdc7a60ed71d9b27abe0 (plain)
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
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include "xt9jime.h"

QT_BEGIN_NAMESPACE
namespace QtVirtualKeyboard {

class KanaConverter : public Xt9KeyboardGenerator::CodeConverter {
public:
    QString convertTo(const QString &codes) const override
    {
        QString buf(codes);
        for (int i = 0; i < buf.length(); ++i) {
            const ushort uc = buf.at(i).unicode();
            if ((uc >= 0x30a1 && uc <= 0x30f6) || uc == 0x30fd || uc == 0x30fe)
                buf.replace(i, 1, QChar(uc - 0x0060));
        }
        return buf;
    }

    QString convertFrom(const QString &codes) const override
    {
        QString buf(codes);
        for (int i = 0; i < buf.length(); ++i) {
            const ushort uc = buf.at(i).unicode();
            if ((uc >= 0x30a1 && uc <= 0x30f6) || uc == 0x30fd || uc == 0x30fe)
                buf.replace(i, 1, QChar(uc + 0x0060));
        }
        return buf;
    }
};

Q_GLOBAL_STATIC(KanaConverter, kanaConverter)

Xt9JIme::Xt9JIme(Xt9RequestCallback *requestCallback) :
    Xt9AwIme(requestCallback, kanaConverter)
{
}

} // namespace QtVirtualKeyboard
QT_END_NAMESPACE