X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=supported%2FText.java;h=232eab6ec4f7736b6b470011f51d09548fe733e8;hb=75a6a3eadc87e42bb0c9808e359d23d03801a9a2;hp=e082a737f2a7be9c11b9fc133bea0c96f108ae55;hpb=31e27ee3108543141f9bfd2efce8c0fa024460a1;p=nikiroo-utils.git diff --git a/supported/Text.java b/supported/Text.java index e082a73..232eab6 100644 --- a/supported/Text.java +++ b/supported/Text.java @@ -85,7 +85,7 @@ class Text extends BasicSupport { meta.setTitle(getTitle()); meta.setAuthor(getAuthor()); - meta.setDate(getDate()); + meta.setDate(bsHelper.formatDate(getDate())); meta.setTags(new ArrayList()); meta.setSource(getType().getSourceName()); meta.setUrl(getSourceFile().toURI().toURL().toString()); @@ -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"); }