t-suw****@users*****
t-suw****@users*****
2007年 9月 11日 (火) 23:08:20 JST
Index: AquaSKK/jconv.cpp
diff -u AquaSKK/jconv.cpp:1.1.2.1 AquaSKK/jconv.cpp:1.1.2.2
--- AquaSKK/jconv.cpp:1.1.2.1 Mon Nov 27 15:16:27 2006
+++ AquaSKK/jconv.cpp Tue Sep 11 23:08:19 2007
@@ -46,4 +46,152 @@
void convert_eucj_to_utf8(const std::string& from, std::string& to) {
std::for_each(from.begin(), from.end(), eucj_to_utf8(to));
}
+
+ struct kana {
+ const char* hirakana;
+ const char* katakana;
+ const char* jisx0201_kana;
+ };
+
+ // data member pointer
+ typedef const char* kana::*kana_member;
+
+ static kana primary_kana_table[] = {
+ { "ã", "ã¬", "ï½¶ï¾" }, { "ã", "ã®", "ï½·ï¾" }, { "ã", "ã°", "クï¾" }, { "ã", "ã²", "ï½¹ï¾" }, { "ã", "ã´", "コï¾" },
+ { "ã", "ã¶", "ï½»ï¾" }, { "ã", "ã¸", "ï½¼ï¾" }, { "ã", "ãº", "ï½½ï¾" }, { "ã", "ã¼", "ï½¾ï¾" }, { "ã", "ã¾", "ソï¾" },
+ { "ã ", "ã", "ï¾ï¾" }, { "ã¢", "ã", "ï¾ï¾" }, { "ã¥", "ã
", "ï¾ï¾" }, { "ã§", "ã", "ï¾ï¾" }, { "ã©", "ã", "ï¾ï¾" },
+ { "ã°", "ã", "ï¾ï¾" }, { "ã³", "ã", "ï¾ï¾" }, { "ã¶", "ã", "ï¾ï¾" }, { "ã¹", "ã", "ï¾ï¾" }, { "ã¼", "ã", "ï¾ï¾" },
+ { "ã±", "ã", "ï¾ï¾" }, { "ã´", "ã", "ï¾ï¾" }, { "ã·", "ã", "ï¾ï¾" }, { "ãº", "ã", "ï¾ï¾" }, { "ã½", "ã", "ï¾ï¾" },
+ { "ãã", "ã´", "ï½³ï¾" }, { 0, 0, 0 }
+ };
+
+ static kana secondary_kana_table[] = {
+ { "ã", "ã¢", "ï½±" }, { "ã", "ã¤", "ï½²" }, { "ã", "ã¦", "ï½³" }, { "ã", "ã¨", "ï½´" }, { "ã", "ãª", "ï½µ" },
+ { "ã", "ã«", "ï½¶" }, { "ã", "ã", "ï½·" }, { "ã", "ã¯", "ク" }, { "ã", "ã±", "ï½¹" }, { "ã", "ã³", "コ" },
+ { "ã", "ãµ", "ï½»" }, { "ã", "ã·", "ï½¼" }, { "ã", "ã¹", "ï½½" }, { "ã", "ã»", "ï½¾" }, { "ã", "ã½", "ソ" },
+ { "ã", "ã¿", "ï¾" }, { "ã¡", "ã", "ï¾" }, { "ã¤", "ã", "ï¾" }, { "ã¦", "ã", "ï¾" }, { "ã¨", "ã", "ï¾" },
+ { "ãª", "ã", "ï¾
" }, { "ã«", "ã", "ï¾" }, { "ã¬", "ã", "ï¾" }, { "ã", "ã", "ï¾" }, { "ã®", "ã", "ï¾" },
+ { "ã¯", "ã", "ï¾" }, { "ã²", "ã", "ï¾" }, { "ãµ", "ã", "ï¾" }, { "ã¸", "ã", "ï¾" }, { "ã»", "ã", "ï¾" },
+ { "ã¾", "ã", "ï¾" }, { "ã¿", "ã", "ï¾" }, { "ã", "ã ", "ï¾" }, { "ã", "ã¡", "ï¾" }, { "ã", "ã¢", "ï¾" },
+ { "ã", "ã¤", "ï¾" }, { "ã", "ã°", "ï½²" }, { "ã", "ã¦", "ï¾" }, { "ã", "ã±", "ï½´" }, { "ã", "ã¨", "ï¾" },
+ { "ã", "ã©", "ï¾" }, { "ã", "ãª", "ï¾" }, { "ã", "ã«", "ï¾" }, { "ã", "ã¬", "ï¾" }, { "ã", "ã", "ï¾" },
+ { "ã", "ã¯", "ï¾" }, { "ã", "ã²", "ヲ" }, { "ã", "ã³", "ï¾" },
+ { "ã", "ã¡", "ï½§" }, { "ã", "ã£", "ィ" }, { "ã
", "ã¥", "ゥ" }, { "ã", "ã§", "ェ" }, { "ã", "ã©", "ォ" },
+ { "ã£", "ã", "ッ" }, { "ã", "ã£", "ャ" }, { "ã
", "ã¥", "ï½" }, { "ã", "ã§", "ï½®" }, { "ã", "ã", " " },
+ { "ã", "ã", "。" }, { "ã", "ã", "、" }, { "ã¼", "ã¼", "ï½°" }, { "ã", "ã", "ï½¢" }, { "ã", "ã", "ï½£" },
+ { "ã", "ã", "ï¾" }, { "ã", "ã", "ï¾" }, { 0, 0, 0 }
+ };
+
+ static kana* kana_tables[] = { primary_kana_table, secondary_kana_table, 0 };
+
+ class translate {
+ std::string from_;
+ std::string to_;
+
+ public:
+ translate(const char* from, const char* to) : from_(from), to_(to) {}
+
+ unsigned operator()(std::string& str, unsigned remain, unsigned offset = 0) {
+ if(!remain) return 0;
+
+ unsigned pos = str.find(from_, offset);
+ if(pos == std::string::npos) return remain;
+
+ str.replace(pos, from_.size(), to_);
+
+ return this->operator()(str, remain - from_.size(), pos + to_.size());
+ }
+ };
+
+ static void kana_convert(kana_member target, kana_member replacement, std::string& str) {
+ unsigned remain = str.size();
+
+ for(kana** tbl = kana_tables; *tbl != 0; ++ tbl) {
+ for(kana* ptr = *tbl; remain && ptr->hirakana; ++ ptr) {
+ remain = translate(ptr->*target, ptr->*replacement)(str, remain);
+ }
+ }
+ }
+
+ void hirakana_to_katakana(const std::string& from, std::string& to) {
+ to = from;
+ kana_convert(&kana::hirakana, &kana::katakana, to);
+ }
+
+ void hirakana_to_jisx0201_kana(const std::string& from, std::string& to) {
+ to = from;
+ kana_convert(&kana::hirakana, &kana::jisx0201_kana, to);
+ }
+
+ void katakana_to_hirakana(const std::string& from, std::string& to) {
+ to = from;
+ kana_convert(&kana::katakana, &kana::hirakana, to);
+ }
+
+ void katakana_to_jisx0201_kana(const std::string& from, std::string& to) {
+ to = from;
+ kana_convert(&kana::katakana, &kana::jisx0201_kana, to);
+ }
+
+ void jisx0201_kana_to_hirakana(const std::string& from, std::string& to) {
+ to = from;
+ kana_convert(&kana::jisx0201_kana, &kana::hirakana, to);
+ }
+
+ void jisx0201_kana_to_katakana(const std::string& from, std::string& to) {
+ to = from;
+ kana_convert(&kana::jisx0201_kana, &kana::katakana, to);
+ }
+
+ // latin record
+ struct latin {
+ const char* ascii;
+ const char* jisx0208_latin;
+ };
+
+ static latin latin_table[] = {
+ { " ", "ã" }, { "!", "ï¼" }, { "\"", "â" }, { "#", "ï¼" },
+ { "$", "ï¼" }, { "%", "ï¼
" }, { "&", "ï¼" }, { "'", "â" },
+ { "(", "ï¼" }, { ")", "ï¼" }, { "*", "ï¼" }, { "+", "ï¼" },
+ { ",", "ï¼" }, { "-", "â" }, { ".", "ï¼" }, { "/", "ï¼" },
+ { "0", "ï¼" }, { "1", "ï¼" }, { "2", "ï¼" }, { "3", "ï¼" },
+ { "4", "ï¼" }, { "5", "ï¼" }, { "6", "ï¼" }, { "7", "ï¼" },
+ { "8", "ï¼" }, { "9", "ï¼" }, { ":", "ï¼" }, { ";", "ï¼" },
+ { "<", "ï¼" }, { "=", "ï¼" }, { ">", "ï¼" }, { "?", "ï¼" },
+ { "@", "ï¼ " }, { "A", "A" }, { "B", "ï¼¢" }, { "C", "ï¼£" },
+ { "D", "D" }, { "E", "E" }, { "F", "F" }, { "G", "G" },
+ { "H", "H" }, { "I", "I" }, { "J", "J" }, { "K", "K" },
+ { "L", "L" }, { "M", "ï¼" }, { "N", "ï¼®" }, { "O", "O" },
+ { "P", "ï¼°" }, { "Q", "ï¼±" }, { "R", "ï¼²" }, { "S", "ï¼³" },
+ { "T", "ï¼´" }, { "U", "ï¼µ" }, { "V", "ï¼¶" }, { "W", "ï¼·" },
+ { "X", "X" }, { "Y", "Y" }, { "Z", "Z" }, { "[", "[" },
+ { "\\", "\" }, { "]", "]" }, { "^", "^" }, { "_", "_" },
+ { "`", "â" }, { "a", "ï½" }, { "b", "ï½" }, { "c", "ï½" },
+ { "d", "ï½" }, { "e", "ï½
" }, { "f", "ï½" }, { "g", "ï½" },
+ { "h", "ï½" }, { "i", "ï½" }, { "j", "ï½" }, { "k", "ï½" },
+ { "l", "ï½" }, { "m", "ï½" }, { "n", "ï½" }, { "o", "ï½" },
+ { "p", "ï½" }, { "q", "ï½" }, { "r", "ï½" }, { "s", "ï½" },
+ { "t", "ï½" }, { "u", "ï½" }, { "v", "ï½" }, { "w", "ï½" },
+ { "x", "ï½" }, { "y", "ï½" }, { "z", "ï½" }, { "{", "ï½" },
+ { "|", "ï½" }, { "}", "ï½" }, { "~", "ã" }, { 0, 0 }
+ };
+
+ void ascii_to_jisx0208_latin(const std::string& from, std::string& to) {
+ to.clear();
+ for(unsigned i = 0; i < from.size(); ++ i) {
+ if(from[i] < 0x20 || 0x7e < from[i]) {
+ to += from[i];
+ } else {
+ to += latin_table[from[i] - 0x20].jisx0208_latin;
+ }
+ }
+ }
+
+ void jisx0208_latin_to_ascii(const std::string& from, std::string& to) {
+ to = from;
+ unsigned remain = to.size();
+ for(latin* ptr = latin_table; remain && ptr->ascii; ++ ptr) {
+ remain = translate(ptr->jisx0208_latin, ptr->ascii)(to, remain);
+ }
+ }
}
Index: AquaSKK/jconv.h
diff -u AquaSKK/jconv.h:1.1.2.1 AquaSKK/jconv.h:1.1.2.2
--- AquaSKK/jconv.h:1.1.2.1 Mon Nov 27 15:16:27 2006
+++ AquaSKK/jconv.h Tue Sep 11 23:08:19 2007
@@ -355,6 +355,18 @@
void convert_utf8_to_eucj(const std::string& from, std::string& to);
void convert_eucj_to_utf8(const std::string& from, std::string& to);
+ // translator(UTF-8 only)
+ void hirakana_to_katakana(const std::string& from, std::string& to);
+ void hirakana_to_jisx0201_kana(const std::string& from, std::string& to);
+
+ void katakana_to_hirakana(const std::string& from, std::string& to);
+ void katakana_to_jisx0201_kana(const std::string& from, std::string& to);
+
+ void jisx0201_kana_to_hirakana(const std::string& from, std::string& to);
+ void jisx0201_kana_to_katakana(const std::string& from, std::string& to);
+
+ void ascii_to_jisx0208_latin(const std::string& from, std::string& to);
+ void jisx0208_latin_to_ascii(const std::string& from, std::string& to);
} // namespace jconv
#endif // INC__jconv__