Revision: 7476
Author: victormote
Date: 2006-06-08 18:18:03 -0700 (Thu, 08 Jun 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7476&view=rev
Log Message:
-----------
Extract method for clarity and consistency.
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-09 01:10:55 UTC (rev 7475)
+++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-06-09 01:18:03 UTC (rev 7476)
@@ -298,33 +298,9 @@
if (hyphenation != null) {
return hyphenation;
}
-
-
- // use algorithm to get hyphenation points
- int[] result = new int[len + 1];
- byte[] values = new byte[result.length];
- 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);
- }
-
- // hyphenation points are located where interletter value is odd
- for (int i = 0; i < len; i++) {
- int interletterValue = il[i + 1];
- if (interletterValue != 0
- && i >= remainCharCount
- && i <= (len - pushCharCount)) {
- k++;
- result[k] = i;
- byte weight = convertLiangToWeight(interletterValue);
- values[k] = weight;
- }
- }
- return createHyphenation(theWord, result, values, k);
+ hyphenation = checkAlgorithm(theWord, remainCharCount, pushCharCount,
+ word);
+ return hyphenation;
}
/**
@@ -416,6 +392,36 @@
return createHyphenation(sw, result, values, k);
}
+ private Hyphenation checkAlgorithm(String theWord, int remainCharCount,
+ int pushCharCount, char[] word) {
+ int len = theWord.length();
+ // use algorithm to get hyphenation points
+ int[] result = new int[len + 1];
+ byte[] values = new byte[result.length];
+ 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);
+ }
+
+ /* We report all of the non-zero values. */
+ for (int i = 0; i < len; i++) {
+ int interletterValue = il[i + 1];
+ if (interletterValue != 0
+ && i >= remainCharCount
+ && i <= (len - pushCharCount)) {
+ k++;
+ result[k] = i;
+ byte weight = convertLiangToWeight(interletterValue);
+ values[k] = weight;
+ }
+ }
+ return createHyphenation(theWord, result, values, k);
+ }
+
/**
* 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.
|