File: template.vala

package info (click to toggle)
libkkc 0.3.5-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,784 kB
  • sloc: ansic: 7,099; makefile: 919; cpp: 435; python: 233; sh: 124
file content (63 lines) | stat: -rw-r--r-- 2,194 bytes parent folder | download | duplicates (4)
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
/*
 * Copyright (C) 2011-2014 Daiki Ueno <ueno@gnu.org>
 * Copyright (C) 2011-2014 Red Hat, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
namespace Kkc {
    internal interface Template : Object {
        public abstract string source { get; construct set; }
        public abstract bool okuri { get; construct set; }
        public abstract string expand (string text);
    }

    class SimpleTemplate : Object, Template {
        public string source { get; construct set; }
        public bool okuri { get; construct set; }

        public SimpleTemplate (string source) {
            this.source = source;
            this.okuri = false;
        }

        public string expand (string text) {
            return text;
        }
    }

    class OkuriganaTemplate : Object, Template {
        public string source { get; construct set; }
        public bool okuri { get; construct set; }

        string? okurigana = null;

        public OkuriganaTemplate (string source, int pos) {
            assert (source.char_count () > 1);
            assert (0 < pos && pos < source.char_count ());

            var last_char_index = source.index_of_nth_char (pos);
            this.okurigana = source[last_char_index:source.length];
            string? prefix = RomKanaUtils.get_okurigana_prefix (this.okurigana);
            this.source = source[0:last_char_index] + prefix;
            this.okuri = true;
        }

        public string expand (string text) {
            if (okuri) {
                return text + okurigana;
            }
            return text;
        }
    }
}