Fixed kana2romaji.
authorPhilipp Reh <sefi@s-e-f-i.de>
Sat, 1 Aug 2009 18:56:11 +0000 (20:56 +0200)
committerPhilipp Reh <sefi@s-e-f-i.de>
Sat, 1 Aug 2009 18:56:11 +0000 (20:56 +0200)
jmdict_import.cpp
kana2romaji.cpp

index 4e16deb5fe0a6d887b235e612fb1550c80175a48..326eca7b0c42ac9722e274be54c30669ba3b206f 100644 (file)
@@ -34,7 +34,7 @@ public:
     Dictionary(const string& name) : db(name) {
         db.exec("DROP TABLE kanji");
         db.exec("DROP TABLE reading");
-       db.exec("DROP TABLE gloss");
+        db.exec("DROP TABLE gloss");
         db.exec("CREATE TABLE kanji (entry INT NOT NULL, kanji TINYTEXT NOT NULL)");
         db.exec("CREATE TABLE reading (entry INT NOT NULL, kana TINYTEXT NOT NULL, romaji TINYTEXT NOT NULL)");
         db.exec("CREATE TABLE gloss (entry INT NOT NULL, sense INT NOT NULL, lang TINYTEXT NOT NULL, gloss TEXT NOT NULL)");
@@ -114,7 +114,7 @@ int main(int argc, char** argv)
 try {
     if(argc < 2 || argc > 3) {
         cerr << "Usage: jmdict_import <dictfile> [dest_dir]\n";
-       return EXIT_FAILURE;
+        return EXIT_FAILURE;
     }
     
     const string dict_file = argv[1],
index ac239f8c30a6b8084e477bdd7a4b0211089c8601..8508f764c1794ad46e27605236bac4f83427635d 100644 (file)
@@ -431,7 +431,7 @@ void kana2romaji(const string& kana, string& rom) {
                )
                {
                  rom[pos - 1] = 'w'; 
-                 rom.erase(pos);
+                 rom.erase(pos, 1);
                  --pos;
                  continue;
                }
@@ -441,7 +441,7 @@ void kana2romaji(const string& kana, string& rom) {
                )
                {
                  rom[pos - 1] = 'h';
-                 rom.erase(pos);
+                 rom.erase(pos, 1);
                  --pos;
                  continue;
                }
@@ -457,26 +457,27 @@ void kana2romaji(const string& kana, string& rom) {
               case 'u':
               case 'e':
               case 'o':
-                rom.erase(pos);
+                rom.erase(pos, 1);
                 --pos;
-                continue;
+                break;
               default:
                 cout << "Encountered a special character in " << kana << " but don't know what to do with it.\n";
               }
             }
             else
             {
-              rom.erase(pos);
+              rom.erase(pos, 1);
               --pos;
             }
         }
         else if (rom[pos] == '\2')
         {
-          if(pos + 1 < rom.size())
+         // two tsu may follow each other, so just remove them
+          if(pos + 1 < rom.size() && rom[pos + 1] != '\2')
             rom[pos] = rom[pos + 1];
           else
           {
-            rom.erase(pos);
+            rom.erase(pos, 1);
             --pos;
           }
         }
@@ -484,11 +485,26 @@ void kana2romaji(const string& kana, string& rom) {
         {
           if(pos == 0)
           {
-            cout << "ー is the first letter of " << kana << ". Don't know how to translate this.\n";
-            rom.erase(pos);
-            --pos;
+            if(rom.size() == 1)
+              rom = "chouon";
+            else
+            {
+              cout << "ー is the first letter of " << kana << ". Don't know how to translate this.\n";
+              rom.erase(pos, 1);
+              --pos;
+            }
           }
           else
             rom[pos] = rom[pos-1];
         }
+
+  for (string::size_type pos = 0; pos < rom.size(); ++pos)
+    switch(rom[pos])
+    {
+    case '\1':
+    case '\2':
+    case '\3':
+      cout << "Failed to translate " << kana << '\n';
+      return;
+    }
 }