+ //
+
+ // no dash before space/dash
+ if ((i + 1) < line.length()) {
+ char car = line.charAt(i);
+ char nextCar = line.charAt(i + 1);
+ if (nextCar == ' ' || car == '-' || nextCar == '-') {
+ needDash = false;
+ }
+ }
+
+ // if the space freed by the removed dash allows it, or if
+ // it is the last char, add the next char
+ if (!needDash || i >= line.length() - 1) {
+ int checkI = Math.min(i + 1, line.length());
+ if (checkI == i || checkI <= width) {
+ needDash = false;
+ i = checkI;
+ }
+ }
+
+ // no dash before parenthesis (but cannot add one more
+ // after)
+ if ((i + 1) < line.length()) {
+ char car = line.charAt(i + 1);
+ if (car == '(' || car == ')') {
+ needDash = false;
+ }
+ }
+
+ if (needDash) {
+ lines.add(rightTrim(line.substring(0, i)) + "-");