summaryrefslogtreecommitdiffstats
path: root/tools/makedict/src
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2009-04-24 15:14:02 -0700
committerAmith Yamasani <yamasani@google.com>2009-04-24 15:51:15 -0700
commit6fdf92fb262863b901231bed5ef9aaf11eee69f2 (patch)
treef253cc64a3529574c0a9d59491131b63d4806c1f /tools/makedict/src
parentdb27a0ee0415fae34006e58537124e75e5550f3b (diff)
downloadandroid_development-6fdf92fb262863b901231bed5ef9aaf11eee69f2.tar.gz
android_development-6fdf92fb262863b901231bed5ef9aaf11eee69f2.tar.bz2
android_development-6fdf92fb262863b901231bed5ef9aaf11eee69f2.zip
Fixed a bug in XML parser handler where some words were being split in two. Fixes #1812655.
Properly concatenate characters to create a full word before adding the word to the tree.
Diffstat (limited to 'tools/makedict/src')
-rwxr-xr-xtools/makedict/src/com/android/tools/dict/MakeBinaryDictionary.java18
1 files changed, 10 insertions, 8 deletions
diff --git a/tools/makedict/src/com/android/tools/dict/MakeBinaryDictionary.java b/tools/makedict/src/com/android/tools/dict/MakeBinaryDictionary.java
index 8a8a677da..77a6401af 100755
--- a/tools/makedict/src/com/android/tools/dict/MakeBinaryDictionary.java
+++ b/tools/makedict/src/com/android/tools/dict/MakeBinaryDictionary.java
@@ -96,6 +96,7 @@ public class MakeBinaryDictionary {
parser.parse(new File(filename), new DefaultHandler() {
boolean inWord;
int freq;
+ StringBuilder wordBuilder = new StringBuilder(48);
@Override
public void startElement(String uri, String localName,
@@ -103,6 +104,7 @@ public class MakeBinaryDictionary {
if (qName.equals("w")) {
inWord = true;
freq = Integer.parseInt(attributes.getValue(0));
+ wordBuilder.setLength(0);
}
}
@@ -110,18 +112,19 @@ public class MakeBinaryDictionary {
public void characters(char[] data, int offset, int length) {
// Ignore other whitespace
if (!inWord) return;
-
- // Ignore one letter words
- if (length < 2) return;
- mWordCount++;
- String word = new String(data, offset, length);
- addWordTop(word, freq);
+ wordBuilder.append(data, offset, length);
}
@Override
public void endElement(String uri, String localName,
String qName) {
- if (qName.equals("w")) inWord = false;
+ if (qName.equals("w")) {
+ if (wordBuilder.length() > 1) {
+ addWordTop(wordBuilder.toString(), freq);
+ mWordCount++;
+ }
+ inWord = false;
+ }
}
});
} catch (Exception ioe) {
@@ -145,7 +148,6 @@ public class MakeBinaryDictionary {
private void addWordTop(String word, int occur) {
if (occur > 255) occur = 255;
-
char firstChar = word.charAt(0);
int index = indexOf(roots, firstChar);
if (index == -1) {