Fix StringJustifier error with dashes (-)
authorNiki Roo <niki@nikiroo.be>
Thu, 12 Apr 2018 11:05:22 +0000 (13:05 +0200)
committerNiki Roo <niki@nikiroo.be>
Thu, 12 Apr 2018 11:05:22 +0000 (13:05 +0200)
src/be/nikiroo/utils/StringJustifier.java

index 9ea0b7259282f6f4d8ab7a934fe039970aa47daf..ed202911e1f755d2e547bea905d5333e24a5e4e8 100644 (file)
@@ -26,6 +26,9 @@
  *
  * @author Kevin Lamonte [kevin.lamonte@gmail.com]
  * @version 1
+ * 
+ * I added some changes to integrate it here.
+ * @author Niki
  */
 package be.nikiroo.utils;
 
@@ -220,8 +223,14 @@ class StringJustifier {
                                        if ((i + 1) < line.length()) {
                                                char car = line.charAt(i);
                                                char nextCar = line.charAt(i + 1);
-                                               if (nextCar == ' ' || car == '-' || nextCar == '-') {
+                                               if (car == ' ' || car == '-' || nextCar == ' ') {
                                                        needDash = false;
+                                               } else if (i > 0) {
+                                                       char prevCar = line.charAt(i - 1);
+                                                       if (prevCar == ' ' || prevCar == '-') {
+                                                               needDash = false;
+                                                               i--;
+                                                       }
                                                }
                                        }
 
@@ -238,8 +247,8 @@ class StringJustifier {
                                        // no dash before parenthesis (but cannot add one more
                                        // after)
                                        if ((i + 1) < line.length()) {
-                                               char car = line.charAt(i + 1);
-                                               if (car == '(' || car == ')') {
+                                               char nextCar = line.charAt(i + 1);
+                                               if (nextCar == '(' || nextCar == ')') {
                                                        needDash = false;
                                                }
                                        }