Revision: 7473
Author: victormote
Date: 2006-06-08 17:48:13 -0700 (Thu, 08 Jun 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7473&view=rev
Log Message:
-----------
Extract some methods for simplicity and clarity.
Modified Paths:
--------------
trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java
Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java
===================================================================
--- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-06-08 23:53:02 UTC (rev 7472)
+++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-06-09 00:48:13 UTC (rev 7473)
@@ -292,45 +292,42 @@
return null;
}
+ String theWord = new String(w, offset, len);
+ Hyphenation hyphenation = checkExceptions(theWord, remainCharCount,
+ pushCharCount);
+ if (hyphenation != null) {
+ return hyphenation;
+ }
+
+
+ // use algorithm to get hyphenation points
int[] result = new int[len + 1];
int k = 0;
+ word[0] = '.'; // word start marker
+ word[len + 1] = '.'; // word end marker
+ word[len + 2] = 0; // null terminated
+ byte[] il = new byte[len + 3]; // initialized to zero
+ for (int i = 0; i < len + 1; i++) {
+ searchPatterns(word, i, il);
+ }
- // check exception list first
- String sw = new String(word, 1, len);
- if (stoplist.containsKey(sw)) {
- /* assume only simple hyphens (Hyphen.pre="-",
- * Hyphen.post = Hyphen.no = null) */
- ArrayList hw = (ArrayList)stoplist.get(sw);
- int j = 0;
- for (int i = 0; i < hw.size(); i++) {
- Object o = hw.get(i);
- if (o instanceof String) {
- j += ((String)o).length();
- if (j >= remainCharCount && j < (len - pushCharCount)) {
- result[k++] = j;
- }
- }
+ // hyphenation points are located where interletter value is odd
+ for (int i = 0; i < len; i++) {
+ if (((il[i + 1] & 1) == 1) && i >= remainCharCount
+ && i <= (len - pushCharCount)) {
+ result[k++] = i;
}
- } else {
- // use algorithm to get hyphenation points
- word[0] = '.'; // word start marker
- word[len + 1] = '.'; // word end marker
- word[len + 2] = 0; // null terminated
- byte[] il = new byte[len + 3]; // initialized to zero
- for (int i = 0; i < len + 1; i++) {
- searchPatterns(word, i, il);
- }
-
- // hyphenation points are located where interletter value is odd
- for (int i = 0; i < len; i++) {
- if (((il[i + 1] & 1) == 1) && i >= remainCharCount
- && i <= (len - pushCharCount)) {
- result[k++] = i;
- }
- }
}
+ return createHyphenation(theWord, result, k);
+ }
-
+ /**
+ * @param result
+ * @param k
+ * @return The new Hyphenation instance.
+ */
+ private Hyphenation createHyphenation(String theWord,
+ int[] result, int k) {
if (k > 0) {
// trim result array
int[] res = new int[k];
@@ -338,7 +335,7 @@
/* TODO: values needs to be populated. Also both positive and
* negative values should be returned. */
byte[] values = new byte[res.length];
- return new Hyphenation(new String(w, offset, len), res, values);
+ return new Hyphenation(theWord, res, values);
}
return null;
}
@@ -358,6 +355,32 @@
return word;
}
+ private Hyphenation checkExceptions(String sw, int remainCharCount,
+ int pushCharCount) {
+ // check exception list first
+ if (stoplist.containsKey(sw)) {
+ int length = sw.length();
+ int[] result = new int[length + 1];
+ int k = 0;
+ /* assume only simple hyphens (Hyphen.pre="-",
+ * Hyphen.post = Hyphen.no = null) */
+ ArrayList hw = (ArrayList)stoplist.get(sw);
+ int j = 0;
+ for (int i = 0; i < hw.size(); i++) {
+ Object o = hw.get(i);
+ if (o instanceof String) {
+ j += ((String)o).length();
+ if (j >= remainCharCount
+ && j < (length - pushCharCount)) {
+ result[k++] = j;
+ }
+ }
+ }
+ return createHyphenation(sw, result, k);
+ }
+ return null;
+ }
+
/**
* Add a character class to the tree. It is used by
* {@link PatternParser PatternParser} as callback to
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|