aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/tcime/3rdparty/tcime/cangjietable.h
blob: 54adced32e2dd1d5f1ad5a7d39aafc0cfea44a4c (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
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
/*
 * Qt implementation of TCIME library
 * This file is part of the Qt Virtual Keyboard module.
 * Contact: http://www.qt.io/licensing/
 *
 * Copyright (C) 2015  The Qt Company
 * Copyright 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef CANGJIETABLE_H
#define CANGJIETABLE_H

#include <QMap>
#include <QChar>
#include <QString>

namespace tcime {

/**
 * Defines cangjie letters and calculates the index of the given cangjie code.
 */
class CangjieTable
{
    Q_DISABLE_COPY(CangjieTable)
    CangjieTable() {}

    // Cangjie 25 letters with number-index starting from 1:
    // 日月金木水火土竹戈十大中一弓人心手口尸廿山女田難卜
    static const QMap<QChar, int> &letters();
    static const int BASE_NUMBER;

public:

    // Cangjie codes contain at most five letters. A cangjie code can be
    // converted to a numerical code by the number-index of each letter.
    // The absent letter will be indexed as 0 if the cangjie code contains less
    // than five-letters.
    static const int MAX_CODE_LENGTH;
    static const int MAX_SIMPLIFIED_CODE_LENGTH;

    /**
     * Returns {@code true} only if the given character is a valid cangjie letter.
     */
    static bool isLetter(const QChar &c);

    /**
     * Returns the primary index calculated by the first and last letter of
     * the given cangjie code.
     *
     * @param code should not be null.
     * @return -1 for invalid code.
     */
    static int getPrimaryIndex(const QString &code);

    /**
     * Returns the secondary index calculated by letters between the first and
     * last letter of the given cangjie code.
     *
     * @param code should not be null.
     * @return -1 for invalid code.
     */
    static int getSecondaryIndex(const QString &code);
};

}

#endif // CANGJIETABLE_H