@@ -36,6 +36,7 @@ | ||
36 | 36 | IBOutlet NSTextField* version_; |
37 | 37 | IBOutlet NSTextField* copyright_; |
38 | 38 | IBOutlet NSArrayController* dictionaryTypes_; |
39 | + IBOutlet NSArrayController* subRuleController_; | |
39 | 40 | |
40 | 41 | NSMutableDictionary* preferences_; |
41 | 42 | NSMutableArray* dictionarySet_; |
@@ -0,0 +1,58 @@ | ||
1 | +/* -*- C++ -*- | |
2 | + | |
3 | + MacOS X implementation of the SKK input method. | |
4 | + | |
5 | + Copyright (C) 2009 Tomotaka SUWA <tomotaka.suwa@gmail.com> | |
6 | + | |
7 | + This program is free software; you can redistribute it and/or modify | |
8 | + it under the terms of the GNU General Public License as published by | |
9 | + the Free Software Foundation; either version 2 of the License, or | |
10 | + any later version. | |
11 | + | |
12 | + This program is distributed in the hope that it will be useful, | |
13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | + GNU General Public License for more details. | |
16 | + | |
17 | + You should have received a copy of the GNU General Public License | |
18 | + along with this program; if not, write to the Free Software | |
19 | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | + | |
21 | +*/ | |
22 | + | |
23 | +#include "SubRuleDescriptions.h" | |
24 | +#include <fstream> | |
25 | +#include <sstream> | |
26 | +#include <iostream> | |
27 | + | |
28 | +SubRuleDescriptions::SubRuleDescriptions(const char* folder) { | |
29 | + std::string path(std::string(folder) + "/sub-rule.desc"); | |
30 | + std::ifstream ifs(path.c_str()); | |
31 | + std::string line; | |
32 | + | |
33 | + while(std::getline(ifs, line)) { | |
34 | + add(line); | |
35 | + } | |
36 | +} | |
37 | + | |
38 | +const char* SubRuleDescriptions::Description(const char* rule_path) { | |
39 | + if(table_.find(rule_path) != table_.end()) { | |
40 | + return table_[rule_path].c_str(); | |
41 | + } | |
42 | + | |
43 | + return rule_path; | |
44 | +} | |
45 | + | |
46 | +// ---------------------------------------------------------------------- | |
47 | + | |
48 | +void SubRuleDescriptions::add(const std::string& line) { | |
49 | + if(line.empty() || line[0] == '#') return; | |
50 | + | |
51 | + std::istringstream buf(line); | |
52 | + std::string path; | |
53 | + std::string description; | |
54 | + | |
55 | + if(buf >> path >> description) { | |
56 | + table_[path] = description; | |
57 | + } | |
58 | +} |
@@ -0,0 +1,40 @@ | ||
1 | +/* -*- C++ -*- | |
2 | + | |
3 | + MacOS X implementation of the SKK input method. | |
4 | + | |
5 | + Copyright (C) 2009 Tomotaka SUWA <tomotaka.suwa@gmail.com> | |
6 | + | |
7 | + This program is free software; you can redistribute it and/or modify | |
8 | + it under the terms of the GNU General Public License as published by | |
9 | + the Free Software Foundation; either version 2 of the License, or | |
10 | + any later version. | |
11 | + | |
12 | + This program is distributed in the hope that it will be useful, | |
13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | + GNU General Public License for more details. | |
16 | + | |
17 | + You should have received a copy of the GNU General Public License | |
18 | + along with this program; if not, write to the Free Software | |
19 | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | + | |
21 | +*/ | |
22 | + | |
23 | +#ifndef SubRuleDescriptions_h | |
24 | +#define SubRuleDescriptions_h | |
25 | + | |
26 | +#include <string> | |
27 | +#include <map> | |
28 | + | |
29 | +class SubRuleDescriptions { | |
30 | + std::map<std::string, std::string> table_; | |
31 | + | |
32 | + void add(const std::string& line); | |
33 | + | |
34 | +public: | |
35 | + SubRuleDescriptions(const char* folder); | |
36 | + | |
37 | + const char* Description(const char* rule_path); | |
38 | +}; | |
39 | + | |
40 | +#endif |
@@ -35,6 +35,8 @@ | ||
35 | 35 | |
36 | 36 | extern NSString* keyboard_layout; |
37 | 37 | |
38 | + extern NSString* sub_rules; | |
39 | + | |
38 | 40 | extern NSString* enable_extended_completion; |
39 | 41 | extern NSString* enable_dynamic_completion; |
40 | 42 | extern NSString* dynamic_completion_range; |
@@ -72,6 +74,7 @@ | ||
72 | 74 | |
73 | 75 | // 重要なパス |
74 | 76 | namespace SKKFilePaths { |
77 | + extern NSString* SystemResourceFolder; | |
75 | 78 | extern NSString* ApplicationSupportFolder; |
76 | 79 | extern NSString* DictionarySet; |
77 | 80 | extern NSString* UserDefaults; |
@@ -84,4 +84,12 @@ | ||
84 | 84 | |
85 | 85 | result = conv.Convert(HirakanaInputMode, "z ", state); |
86 | 86 | assert(state.next == "" && state.output == " "); |
87 | + | |
88 | + result = conv.Convert(HirakanaInputMode, ".", state); | |
89 | + assert(state.output == "。"); | |
90 | + | |
91 | + conv.Patch("period.rule"); | |
92 | + | |
93 | + result = conv.Convert(HirakanaInputMode, ".", state); | |
94 | + assert(state.output == "."); | |
87 | 95 | } |
@@ -139,15 +139,55 @@ | ||
139 | 139 | } |
140 | 140 | |
141 | 141 | void SKKRomanKanaConverter::Initialize(const std::string& path) { |
142 | + load(path, true); | |
143 | +} | |
144 | + | |
145 | +void SKKRomanKanaConverter::Patch(const std::string& path) { | |
146 | + load(path, false); | |
147 | +} | |
148 | + | |
149 | +bool SKKRomanKanaConverter::Convert(SKKInputMode mode, const std::string& str, SKKRomanKanaConversionResult& result) { | |
150 | + bool converted = false; | |
151 | + std::string queue(str); | |
152 | + | |
153 | + result = SKKRomanKanaConversionResult(); | |
154 | + | |
155 | + while(!queue.empty()) { | |
156 | + ConversionHelper helper(mode, queue); | |
157 | + | |
158 | + root_.Traverse(helper); | |
159 | + | |
160 | + result.output += helper.Output(); | |
161 | + result.next = helper.Next(); | |
162 | + result.intermediate = helper.Intermediate(); | |
163 | + | |
164 | + converted = helper.IsConverted(); | |
165 | + | |
166 | + if(helper.IsShort()) { | |
167 | + result.next = helper.Queue(); | |
168 | + break; | |
169 | + } | |
170 | + | |
171 | + queue = helper.Queue(); | |
172 | + } | |
173 | + | |
174 | + return converted; | |
175 | +} | |
176 | + | |
177 | +// ---------------------------------------------------------------------- | |
178 | + | |
179 | +void SKKRomanKanaConverter::load(const std::string& path, bool initialize) { | |
142 | 180 | std::ifstream ifs(path.c_str()); |
143 | 181 | std::string str; |
144 | 182 | |
145 | 183 | if(!ifs) { |
146 | - std::cerr << "SKKRomanKanaConverter::Initialize(): can't open file [" << path << "]" << std::endl; | |
184 | + std::cerr << "SKKRomanKanaConverter::load(): can't open file [" << path << "]" << std::endl; | |
147 | 185 | return; |
148 | 186 | } |
149 | 187 | |
150 | - root_.Clear(); | |
188 | + if(initialize) { | |
189 | + root_.Clear(); | |
190 | + } | |
151 | 191 | |
152 | 192 | while(std::getline(ifs, str)) { |
153 | 193 | if(str.empty() || str[0] == '#') continue; |
@@ -177,35 +217,7 @@ | ||
177 | 217 | root_.Add(roman, SKKTrie(hirakana, katakana, jisx0201kana, next)); |
178 | 218 | } else { |
179 | 219 | // 不正な形式 |
180 | - std::cerr << "SKKRomanKanaConverter::Initialize(): invalid rule [" << utf8 << "]" << std::endl; | |
220 | + std::cerr << "SKKRomanKanaConverter::load(): invalid rule [" << utf8 << "]" << std::endl; | |
181 | 221 | } |
182 | 222 | } |
183 | 223 | } |
184 | - | |
185 | -bool SKKRomanKanaConverter::Convert(SKKInputMode mode, const std::string& str, SKKRomanKanaConversionResult& result) { | |
186 | - bool converted = false; | |
187 | - std::string queue(str); | |
188 | - | |
189 | - result = SKKRomanKanaConversionResult(); | |
190 | - | |
191 | - while(!queue.empty()) { | |
192 | - ConversionHelper helper(mode, queue); | |
193 | - | |
194 | - root_.Traverse(helper); | |
195 | - | |
196 | - result.output += helper.Output(); | |
197 | - result.next = helper.Next(); | |
198 | - result.intermediate = helper.Intermediate(); | |
199 | - | |
200 | - converted = helper.IsConverted(); | |
201 | - | |
202 | - if(helper.IsShort()) { | |
203 | - result.next = helper.Queue(); | |
204 | - break; | |
205 | - } | |
206 | - | |
207 | - queue = helper.Queue(); | |
208 | - } | |
209 | - | |
210 | - return converted; | |
211 | -} |
@@ -40,11 +40,15 @@ | ||
40 | 40 | SKKRomanKanaConverter(); |
41 | 41 | SKKRomanKanaConverter(const SKKRomanKanaConverter&); |
42 | 42 | |
43 | + void load(const std::string& path, bool initialize); | |
44 | + | |
43 | 45 | public: |
44 | 46 | static SKKRomanKanaConverter& theInstance(); |
45 | 47 | |
46 | 48 | void Initialize(const std::string& path); |
47 | 49 | |
50 | + void Patch(const std::string& path); | |
51 | + | |
48 | 52 | // ローマ字かな変換 |
49 | 53 | // |
50 | 54 | // 引数: |