summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Reh <sefi@s-e-f-i.de>2009-08-01 20:56:11 +0200
committerPhilipp Reh <sefi@s-e-f-i.de>2009-08-01 20:56:11 +0200
commitde18a3851deac5baddce2fd1c758b9c5f625abee (patch)
tree4c91f1cd5fd4f1c9640c201ebabdabcb009a8d6e
parentc66ff2b0bb4204841a553f47da0db513422df51f (diff)
Fixed kana2romaji.
-rw-r--r--jmdict_import.cpp4
-rw-r--r--kana2romaji.cpp36
2 files changed, 28 insertions, 12 deletions
diff --git a/jmdict_import.cpp b/jmdict_import.cpp
index 4e16deb..326eca7 100644
--- a/jmdict_import.cpp
+++ b/jmdict_import.cpp
@@ -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],
diff --git a/kana2romaji.cpp b/kana2romaji.cpp
index ac239f8..8508f76 100644
--- a/kana2romaji.cpp
+++ b/kana2romaji.cpp
@@ -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;
+ }
}