package de.justiz.fxeditor.controller;
import java.text.BreakIterator;
import java.util.Locale;
/**
* Created by dzhurko on 21.11.2017.
*/
public class TestBreakOperator {
wordIterator.setText(target);
int start = wordIterator.first();
int end = wordIterator.next();
String word
= target.
substring(start, end
);
if (Character.
isLetterOrDigit(word.
charAt(0))) {
}
start = end;
end = wordIterator.next();
}
}
wordIterator.setText(target);
int end = wordIterator.last();
int start = wordIterator.previous();
String word
= target.
substring(start, end
);
if (Character.
isLetterOrDigit(word.
charAt(0)))
end = start;
start = wordIterator.previous();
}
}
markers.setLength(target.length() + 1);
for (int k = 0; k < markers.length(); k++) {
markers.setCharAt(k, ' ');
}
iterator.setText(target);
int boundary = iterator.first();
markers.setCharAt(boundary, '^');
boundary = iterator.next();
}
}
static void formatLines
(String target,
int maxLength,
Locale currentLocale
) {
boundary.setText(target);
int start = boundary.first();
int end = boundary.next();
int lineLength = 0;
String word
= target.
substring(start, end
);
lineLength = lineLength + word.length();
if (lineLength >= maxLength) {
lineLength = word.length();
}
start = end;
end = boundary.next();
}
}
iterator.setText(target);
int boundary = iterator.first();
boundary = iterator.next();
}
}
static void characterExamples() {
.
getCharacterInstance(new Locale("ar",
"SA"));
// Arabic word for "house"
String house
= "\u0628" + "\u064e" + "\u064a" + "\u0652" + "\u067a"
+ "\u064f";
listPositions(house, arCharIterator);
}
static void wordExamples() {
String someText
= "She stopped. "
+ "She said, \"Hello there3,\" and then went on.";
markBoundaries(someText, wordIterator);
extractWords(someText, wordIterator);
}
static void sentenceExamples() {
.getSentenceInstance(currentLocale);
String someText
= "She stopped. "
+ "She said, \"Hello there2,\" and then went on.";
markBoundaries(someText, sentenceIterator);
String variousText
= "He's vanished! "
+ "What will we do? It's up to us.";
markBoundaries(variousText, sentenceIterator);
String decimalText
= "Please add 1.5 liters to the tank.";
markBoundaries(decimalText, sentenceIterator);
String donneText
= "\"No man is an island . . . " + "every man . . . \"";
markBoundaries(donneText, sentenceIterator);
String dogText
= "My friend, Mr. Jones, has a new dog. "
+ "The dog's name is Spot.";
markBoundaries(dogText, sentenceIterator);
}
static void lineExamples() {
String someText
= "She stopped. "
+ "She said, \"Hello there,\" and then went on.";
markBoundaries(someText, lineIterator);
String hardHyphen
= "There are twenty-four hours in a day.";
markBoundaries(hardHyphen, lineIterator);
String moreText
= "She said, \"Hello there,\" and then "
+ "went on down the street. When she stopped "
+ "to look at the fur coats in a shop window, "
+ "her dog growled. \"Sorry Jake,\" she said. "
+ " \"I didn't know you would take it personally.\"";
formatLines(moreText, 30, currentLocale);
}
static public void main
(String[] args
) {
System.
out.
println("characterExamples();");
characterExamples();
System.
out.
println("wordExamples();");
wordExamples();
System.
out.
println("sentenceExamples();");
sentenceExamples();
System.
out.
println("lineExamples();");
lineExamples();
}
}