1 package org.feistymeow.textual;
3 import java.util.HashSet;
13 HashSet<String> toReturn =
new HashSet<String>();
14 int startingChunk = Math.min(orig.length(), _lookups.
longestWord());
15 for (
int i = startingChunk; i >= 1; i--) {
16 String first = orig.substring(0, i);
17 if (!_lookups.
lookup(first)) {
21 String second = orig.substring(i, orig.length());
23 if (second.length() == 0) {
28 if (matches !=
null) {
29 for (String matched : matches) {
30 toReturn.add(first +
" " + matched);
34 if (toReturn.isEmpty())
return null;
40 public static void main(String argv[]) {
41 String smallWordList[] = {
42 "hops",
"barley",
"malt",
"beer",
"turnip"
47 String toBreak =
"maltbeerbeerturniphops";
49 if (matches !=
null) {
50 System.out.println(
"matches found:");
51 for (String
match : matches) {
52 System.out.println(
match);
55 System.out.println(
"ERROR: failed to find matches!");
58 toBreak =
"maltbeerbeturniphops";
60 if (matches !=
null) {
61 System.out.println(
"ERROR: matches found:");
62 for (String
match : matches) {
63 System.out.println(
match);
66 System.out.println(
"found no matches, which is correct.");
boolean lookup(String toFind)
static void main(String argv[])
WordBreakFinder(SimpleDictionary lookups)
Set< String > findStringsWithGoodSpacing(String orig)
int match(register const char *str, register const char **list)