Library fixes + "make install" fix
[fanfix.git] / src / be / nikiroo / fanfix / supported / BasicSupport.java
index 74f11156e82c265a0eee1ddbd09b7c417a98ed12..b9517284318e30169f571109fb4611d789fa006d 100644 (file)
@@ -6,7 +6,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -20,8 +19,8 @@ import be.nikiroo.fanfix.bundles.StringId;
 import be.nikiroo.fanfix.data.Chapter;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Paragraph;
-import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
+import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.utils.StringUtils;
 
 /**
@@ -653,7 +652,9 @@ public abstract class BasicSupport {
         * @param in
         *            the input
         * @param needle
-        *            a string that must be found inside the target line
+        *            a string that must be found inside the target line (also
+        *            supports "^" at start to say "only if it starts with" the
+        *            needle)
         * @param relativeLine
         *            the line to return based upon the target line position (-1 =
         *            the line before, 0 = the target line...)
@@ -675,7 +676,9 @@ public abstract class BasicSupport {
         * @param in
         *            the input
         * @param needle
-        *            a string that must be found inside the target line
+        *            a string that must be found inside the target line (also
+        *            supports "^" at start to say "only if it starts with" the
+        *            needle)
         * @param relativeLine
         *            the line to return based upon the target line position (-1 =
         *            the line before, 0 = the target line...)
@@ -697,8 +700,18 @@ public abstract class BasicSupport {
                while (scan.hasNext()) {
                        lines.add(scan.next());
 
-                       if (index == -1 && lines.get(lines.size() - 1).contains(needle)) {
-                               index = lines.size() - 1;
+                       if (index == -1) {
+                               if (needle.startsWith("^")) {
+                                       if (lines.get(lines.size() - 1).startsWith(
+                                                       needle.substring(1))) {
+                                               index = lines.size() - 1;
+                                       }
+
+                               } else {
+                                       if (lines.get(lines.size() - 1).contains(needle)) {
+                                               index = lines.size() - 1;
+                                       }
+                               }
                        }
 
                        if (index >= 0 && index + relativeLine < lines.size()) {
@@ -785,8 +798,7 @@ public abstract class BasicSupport {
                                        "\n* * *\n");
                }
 
-               InputStream in = new ByteArrayInputStream(
-                               content.getBytes(StandardCharsets.UTF_8));
+               InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8"));
                try {
                        @SuppressWarnings("resource")
                        Scanner scan = new Scanner(in, "UTF-8");