X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FBasicSupport.java;h=b9517284318e30169f571109fb4611d789fa006d;hp=74f11156e82c265a0eee1ddbd09b7c417a98ed12;hb=fe999aa400c2627291325558f1ae8c734da7900c;hpb=08fe2e33007063e30fe22dc1d290f8afaa18eb1d diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport.java b/src/be/nikiroo/fanfix/supported/BasicSupport.java index 74f1115..b951728 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport.java @@ -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");