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;
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;
/**
* @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...)
* @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...)
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()) {
"\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");