X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FText.java;h=232eab6ec4f7736b6b470011f51d09548fe733e8;hp=ade797fbf71ae3182a05ced4a6f0fdbb74b1f118;hb=1387a30ab59dbf4071f2c5e5e0e08ca98c75b726;hpb=fccaa18aed16a157e07769e407a4cc42925661fb diff --git a/src/be/nikiroo/fanfix/supported/Text.java b/src/be/nikiroo/fanfix/supported/Text.java index ade797f..232eab6 100644 --- a/src/be/nikiroo/fanfix/supported/Text.java +++ b/src/be/nikiroo/fanfix/supported/Text.java @@ -102,7 +102,7 @@ class Text extends BasicSupport { } private String getLang() { - @SuppressWarnings("resource") + @SuppressWarnings("resource") // cannot close, or we loose getInput()! Scanner scan = new Scanner(getInput(), "UTF-8"); scan.useDelimiter("\\n"); scan.next(); // Title @@ -128,14 +128,14 @@ class Text extends BasicSupport { } private String getTitle() { - @SuppressWarnings("resource") + @SuppressWarnings("resource") // cannot close, or we loose getInput()! Scanner scan = new Scanner(getInput(), "UTF-8"); scan.useDelimiter("\\n"); return scan.next(); } private String getAuthor() { - @SuppressWarnings("resource") + @SuppressWarnings("resource") // cannot close, or we loose getInput()! Scanner scan = new Scanner(getInput(), "UTF-8"); scan.useDelimiter("\\n"); scan.next(); @@ -151,7 +151,7 @@ class Text extends BasicSupport { } private String getDate() { - @SuppressWarnings("resource") + @SuppressWarnings("resource") // cannot close, or we loose getInput()! Scanner scan = new Scanner(getInput(), "UTF-8"); scan.useDelimiter("\\n"); scan.next(); @@ -215,12 +215,13 @@ class Text extends BasicSupport { protected List> getChapters(Progress pg) throws IOException { List> chaps = new ArrayList>(); - @SuppressWarnings("resource") + @SuppressWarnings("resource") // cannot close, or we loose getInput()! Scanner scan = new Scanner(getInput(), "UTF-8"); scan.useDelimiter("\\n"); - boolean prevLineEmpty = false; + String line = "first is not empty"; while (scan.hasNext()) { - String line = scan.next(); + boolean prevLineEmpty = line.trim().isEmpty(); + line = scan.next(); if (prevLineEmpty && detectChapter(line, chaps.size() + 1) != null) { String chapName = Integer.toString(chaps.size() + 1); int pos = line.indexOf(':'); @@ -232,10 +233,8 @@ class Text extends BasicSupport { chapName, // getSourceFile().toURI().toURL())); } - - prevLineEmpty = line.trim().isEmpty(); } - + return chaps; } @@ -243,17 +242,27 @@ class Text extends BasicSupport { protected String getChapterContent(URL source, int number, Progress pg) throws IOException { StringBuilder builder = new StringBuilder(); - @SuppressWarnings("resource") + @SuppressWarnings("resource") // cannot close, or we loose getInput()! Scanner scan = new Scanner(getInput(), "UTF-8"); scan.useDelimiter("\\n"); - boolean inChap = false; + scan.next(); // title + scan.next(); // author + scan.next(); // date or empty + Boolean inChap = null; + String line = ""; while (scan.hasNext()) { - String line = scan.next(); - if (!inChap && detectChapter(line, number) != null) { + if (number == 0 && !line.trim().isEmpty()) { + // We found pre-chapter content, we are checking for + // Chapter 0 (fake chapter) --> keep the content + if (inChap == null) + inChap = true; + } + line = scan.next(); + if ((inChap == null || !inChap) && detectChapter(line, number) != null) { inChap = true; } else if (detectChapter(line, number + 1) != null) { break; - } else if (inChap) { + } else if (inChap != null && inChap) { builder.append(line); builder.append("\n"); }