1 package be
.nikiroo
.fanfix
.supported
;
3 import java
.awt
.image
.BufferedImage
;
4 import java
.io
.BufferedReader
;
5 import java
.io
.ByteArrayInputStream
;
7 import java
.io
.IOException
;
8 import java
.io
.InputStream
;
9 import java
.io
.InputStreamReader
;
10 import java
.net
.MalformedURLException
;
12 import java
.util
.ArrayList
;
13 import java
.util
.HashMap
;
14 import java
.util
.List
;
16 import java
.util
.Map
.Entry
;
17 import java
.util
.Scanner
;
19 import be
.nikiroo
.fanfix
.Instance
;
20 import be
.nikiroo
.fanfix
.bundles
.Config
;
21 import be
.nikiroo
.fanfix
.bundles
.StringId
;
22 import be
.nikiroo
.fanfix
.data
.Chapter
;
23 import be
.nikiroo
.fanfix
.data
.MetaData
;
24 import be
.nikiroo
.fanfix
.data
.Paragraph
;
25 import be
.nikiroo
.fanfix
.data
.Paragraph
.ParagraphType
;
26 import be
.nikiroo
.fanfix
.data
.Story
;
27 import be
.nikiroo
.utils
.IOUtils
;
28 import be
.nikiroo
.utils
.Progress
;
29 import be
.nikiroo
.utils
.StringUtils
;
32 * This class is the base class used by the other support classes. It can be
33 * used outside of this package, and have static method that you can use to get
34 * access to the correct support class.
36 * It will be used with 'resources' (usually web pages or files).
40 public abstract class BasicSupport
{
42 * The supported input types for which we can get a {@link BasicSupport}
47 public enum SupportType
{
48 /** EPUB files created with this program */
50 /** Pure text file with some rules */
52 /** TEXT but with associated .info file */
54 /** My Little Pony fanfictions */
56 /** Fanfictions from a lot of different universes */
58 /** Website with lots of Mangas */
60 /** Furry website with comics support */
62 /** Furry website with stories */
70 * A description of this support type (more information than the
71 * {@link BasicSupport#getSourceName()}).
73 * @return the description
75 public String
getDesc() {
76 String desc
= Instance
.getTrans().getStringX(StringId
.INPUT_DESC
,
80 desc
= Instance
.getTrans().getString(StringId
.INPUT_DESC
, this);
87 * The name of this support type (a short version).
91 public String
getSourceName() {
92 BasicSupport support
= BasicSupport
.getSupport(this);
93 if (support
!= null) {
94 return support
.getSourceName();
101 public String
toString() {
102 return super.toString().toLowerCase();
106 * Call {@link SupportType#valueOf(String.toUpperCase())}.
109 * the possible type name
111 * @return NULL or the type
113 public static SupportType
valueOfUC(String typeName
) {
114 return SupportType
.valueOf(typeName
== null ?
null : typeName
119 * Call {@link SupportType#valueOf(String.toUpperCase())} but return
120 * NULL for NULL instead of raising exception.
123 * the possible type name
125 * @return NULL or the type
127 public static SupportType
valueOfNullOkUC(String typeName
) {
128 if (typeName
== null) {
132 return SupportType
.valueOfUC(typeName
);
136 * Call {@link SupportType#valueOf(String.toUpperCase())} but return
137 * NULL in case of error instead of raising an exception.
140 * the possible type name
142 * @return NULL or the type
144 public static SupportType
valueOfAllOkUC(String typeName
) {
146 return SupportType
.valueOfUC(typeName
);
147 } catch (Exception e
) {
153 private InputStream in
;
154 private SupportType type
;
155 private URL currentReferer
; // with only one 'r', as in 'HTTP'...
158 private char openQuote
= Instance
.getTrans().getChar(
159 StringId
.OPEN_SINGLE_QUOTE
);
160 private char closeQuote
= Instance
.getTrans().getChar(
161 StringId
.CLOSE_SINGLE_QUOTE
);
162 private char openDoubleQuote
= Instance
.getTrans().getChar(
163 StringId
.OPEN_DOUBLE_QUOTE
);
164 private char closeDoubleQuote
= Instance
.getTrans().getChar(
165 StringId
.CLOSE_DOUBLE_QUOTE
);
168 * The name of this support class.
172 protected abstract String
getSourceName();
175 * Check if the given resource is supported by this {@link BasicSupport}.
178 * the resource to check for
180 * @return TRUE if it is
182 protected abstract boolean supports(URL url
);
185 * Return TRUE if the support will return HTML encoded content values for
186 * the chapters content.
188 * @return TRUE for HTML
190 protected abstract boolean isHtml();
192 protected abstract MetaData
getMeta(URL source
, InputStream in
)
196 * Return the story description.
199 * the source of the story
201 * the input (the main resource)
203 * @return the description
205 * @throws IOException
206 * in case of I/O error
208 protected abstract String
getDesc(URL source
, InputStream in
)
212 * Return the list of chapters (name and resource).
215 * the source of the story
217 * the input (the main resource)
219 * @return the chapters
221 * @throws IOException
222 * in case of I/O error
224 protected abstract List
<Entry
<String
, URL
>> getChapters(URL source
,
225 InputStream in
) throws IOException
;
228 * Return the content of the chapter (possibly HTML encoded, if
229 * {@link BasicSupport#isHtml()} is TRUE).
232 * the source of the story
234 * the input (the main resource)
238 * @return the content
240 * @throws IOException
241 * in case of I/O error
243 protected abstract String
getChapterContent(URL source
, InputStream in
,
244 int number
) throws IOException
;
247 * Return the list of cookies (values included) that must be used to
248 * correctly fetch the resources.
250 * You are expected to call the super method implementation if you override
253 * @return the cookies
255 public Map
<String
, String
> getCookies() {
256 return new HashMap
<String
, String
>();
260 * Return the canonical form of the main {@link URL}.
263 * the source {@link URL}
265 * @return the canonical form of this {@link URL}
267 * @throws IOException
268 * in case of I/O error
270 public URL
getCanonicalUrl(URL source
) throws IOException
{
275 * Process the given story resource into a partially filled {@link Story}
276 * object containing the name and metadata, except for the description.
281 * @return the {@link Story}
283 * @throws IOException
284 * in case of I/O error
286 public Story
processMeta(URL url
) throws IOException
{
287 return processMeta(url
, true, false);
291 * Process the given story resource into a partially filled {@link Story}
292 * object containing the name and metadata.
298 * close "this" and "in" when done
300 * @return the {@link Story}
302 * @throws IOException
303 * in case of I/O error
305 protected Story
processMeta(URL url
, boolean close
, boolean getDesc
)
307 url
= getCanonicalUrl(url
);
309 setCurrentReferer(url
);
317 preprocess(url
, getInput());
319 Story story
= new Story();
320 MetaData meta
= getMeta(url
, getInput());
323 if (meta
!= null && meta
.getCover() == null) {
324 meta
.setCover(getDefaultCover(meta
.getSubject()));
328 String descChapterName
= Instance
.getTrans().getString(
329 StringId
.DESCRIPTION
);
330 story
.getMeta().setResume(
331 makeChapter(url
, 0, descChapterName
,
332 getDesc(url
, getInput())));
340 } catch (IOException e
) {
349 setCurrentReferer(null);
354 * Process the given story resource into a fully filled {@link Story}
360 * the optional progress reporter
362 * @return the {@link Story}
364 * @throws IOException
365 * in case of I/O error
367 public Story
process(URL url
, Progress pg
) throws IOException
{
371 pg
.setMinMax(0, 100);
374 url
= getCanonicalUrl(url
);
377 Story story
= processMeta(url
, false, true);
384 setCurrentReferer(url
);
386 story
.setChapters(new ArrayList
<Chapter
>());
388 List
<Entry
<String
, URL
>> chapters
= getChapters(url
, getInput());
392 if (chapters
!= null) {
393 Progress pgChaps
= new Progress(0, chapters
.size());
394 pg
.addProgress(pgChaps
, 80);
396 for (Entry
<String
, URL
> chap
: chapters
) {
397 setCurrentReferer(chap
.getValue());
398 InputStream chapIn
= Instance
.getCache().open(
399 chap
.getValue(), this, true);
401 story
.getChapters().add(
402 makeChapter(url
, i
, chap
.getKey(),
403 getChapterContent(url
, chapIn
, i
)));
408 pgChaps
.setProgress(i
++);
419 } catch (IOException e
) {
427 setCurrentReferer(null);
436 public SupportType
getType() {
441 * The current referer {@link URL} (only one 'r', as in 'HTML'...), i.e.,
442 * the current {@link URL} we work on.
444 * @return the referer
446 public URL
getCurrentReferer() {
447 return currentReferer
;
451 * The current referer {@link URL} (only one 'r', as in 'HTML'...), i.e.,
452 * the current {@link URL} we work on.
454 * @param currentReferer
457 protected void setCurrentReferer(URL currentReferer
) {
458 this.currentReferer
= currentReferer
;
469 protected BasicSupport
setType(SupportType type
) {
475 * Prepare the support if needed before processing.
478 * the source of the story
480 * the input (the main resource)
482 * @throws IOException
485 protected void preprocess(URL source
, InputStream in
) throws IOException
{
489 * Now that we have processed the {@link Story}, close the resources if any.
491 * @throws IOException
494 protected void close() throws IOException
{
498 * Create a {@link Chapter} object from the given information, formatting
499 * the content as it should be.
506 * the chapter content
508 * @return the {@link Chapter}
510 * @throws IOException
511 * in case of I/O error
513 protected Chapter
makeChapter(URL source
, int number
, String name
,
514 String content
) throws IOException
{
515 // Chapter name: process it correctly, then remove the possible
516 // redundant "Chapter x: " in front of it
517 String chapterName
= processPara(name
).getContent().trim();
518 for (String lang
: Instance
.getConfig().getString(Config
.CHAPTER
)
520 String chapterWord
= Instance
.getConfig().getStringX(
521 Config
.CHAPTER
, lang
);
522 if (chapterName
.startsWith(chapterWord
)) {
523 chapterName
= chapterName
.substring(chapterWord
.length())
529 if (chapterName
.startsWith(Integer
.toString(number
))) {
530 chapterName
= chapterName
.substring(
531 Integer
.toString(number
).length()).trim();
534 if (chapterName
.startsWith(":")) {
535 chapterName
= chapterName
.substring(1).trim();
539 Chapter chap
= new Chapter(number
, chapterName
);
541 if (content
!= null) {
542 chap
.setParagraphs(makeParagraphs(source
, content
));
550 * Convert the given content into {@link Paragraph}s.
553 * the source URL of the story
555 * the textual content
557 * @return the {@link Paragraph}s
559 * @throws IOException
560 * in case of I/O error
562 protected List
<Paragraph
> makeParagraphs(URL source
, String content
)
565 // Special <HR> processing:
566 content
= content
.replaceAll("(<hr [^>]*>)|(<hr/>)|(<hr>)",
570 List
<Paragraph
> paras
= new ArrayList
<Paragraph
>();
571 InputStream in
= new ByteArrayInputStream(content
.getBytes("UTF-8"));
573 BufferedReader buff
= new BufferedReader(new InputStreamReader(in
,
576 for (String encodedLine
= buff
.readLine(); encodedLine
!= null; encodedLine
= buff
580 lines
= encodedLine
.split("(<p>|</p>|<br>|<br/>|\\n)");
582 lines
= new String
[] { encodedLine
};
585 for (String aline
: lines
) {
586 String line
= aline
.trim();
589 if (line
.startsWith("[") && line
.endsWith("]")) {
590 image
= getImageUrl(this, source
,
591 line
.substring(1, line
.length() - 1).trim());
595 paras
.add(new Paragraph(image
));
597 paras
.add(processPara(line
));
605 // Check quotes for "bad" format
606 List
<Paragraph
> newParas
= new ArrayList
<Paragraph
>();
607 for (Paragraph para
: paras
) {
608 newParas
.addAll(requotify(para
));
612 // Remove double blanks/brks
613 fixBlanksBreaks(paras
);
619 * Fix the {@link ParagraphType#BLANK}s and {@link ParagraphType#BREAK}s of
620 * those {@link Paragraph}s.
622 * The resulting list will not contain a starting or trailing blank/break
623 * nor 2 blanks or breaks following each other.
626 * the list of {@link Paragraph}s to fix
628 protected void fixBlanksBreaks(List
<Paragraph
> paras
) {
629 boolean space
= false;
631 for (int i
= 0; i
< paras
.size(); i
++) {
632 Paragraph para
= paras
.get(i
);
633 boolean thisSpace
= para
.getType() == ParagraphType
.BLANK
;
634 boolean thisBrk
= para
.getType() == ParagraphType
.BREAK
;
636 if (i
> 0 && space
&& thisBrk
) {
639 } else if ((space
|| brk
) && (thisSpace
|| thisBrk
)) {
648 // Remove blank/brk at start
650 && (paras
.get(0).getType() == ParagraphType
.BLANK
|| paras
.get(
651 0).getType() == ParagraphType
.BREAK
)) {
655 // Remove blank/brk at end
656 int last
= paras
.size() - 1;
658 && (paras
.get(last
).getType() == ParagraphType
.BLANK
|| paras
659 .get(last
).getType() == ParagraphType
.BREAK
)) {
665 * Get the default cover related to this subject (see <tt>.info</tt> files).
670 * @return the cover if any, or NULL
672 static BufferedImage
getDefaultCover(String subject
) {
673 if (subject
!= null && !subject
.isEmpty()
674 && Instance
.getCoverDir() != null) {
676 File fileCover
= new File(Instance
.getCoverDir(), subject
);
677 return getImage(null, fileCover
.toURI().toURL(), subject
);
678 } catch (MalformedURLException e
) {
686 * Return the list of supported image extensions.
688 * @param emptyAllowed
689 * TRUE to allow an empty extension on first place, which can be
690 * used when you may already have an extension in your input but
691 * are not sure about it
693 * @return the extensions
695 static String
[] getImageExt(boolean emptyAllowed
) {
697 return new String
[] { "", ".png", ".jpg", ".jpeg", ".gif", ".bmp" };
699 return new String
[] { ".png", ".jpg", ".jpeg", ".gif", ".bmp" };
704 * Check if the given resource can be a local image or a remote image, then
705 * refresh the cache with it if it is.
710 * the resource to check
712 * @return the image if found, or NULL
715 static BufferedImage
getImage(BasicSupport support
, URL source
, String line
) {
716 URL url
= getImageUrl(support
, source
, line
);
718 InputStream in
= null;
720 in
= Instance
.getCache().open(url
, getSupport(url
), true);
721 return IOUtils
.toImage(in
);
722 } catch (IOException e
) {
727 } catch (IOException e
) {
737 * Check if the given resource can be a local image or a remote image, then
738 * refresh the cache with it if it is.
743 * the resource to check
745 * @return the image URL if found, or NULL
748 static URL
getImageUrl(BasicSupport support
, URL source
, String line
) {
754 if (source
!= null) {
755 path
= new File(source
.getFile()).getParent();
757 String basePath
= new File(new File(path
), line
.trim())
759 for (String ext
: getImageExt(true)) {
760 if (new File(basePath
+ ext
).exists()) {
761 url
= new File(basePath
+ ext
).toURI().toURL();
764 } catch (Exception e
) {
765 // Nothing to do here
772 for (String ext
: getImageExt(true)) {
773 if (Instance
.getCache().check(new URL(line
+ ext
))) {
774 url
= new URL(line
+ ext
);
781 for (String ext
: getImageExt(true)) {
783 url
= new URL(line
+ ext
);
784 Instance
.getCache().refresh(url
, support
, true);
786 } catch (IOException e
) {
787 // no image with this ext
792 } catch (MalformedURLException e
) {
797 // refresh the cached file
800 Instance
.getCache().refresh(url
, support
, true);
801 } catch (IOException e
) {
802 // woops, broken image
812 * Open the input file that will be used through the support.
815 * the source {@link URL}
817 * @return the {@link InputStream}
819 * @throws IOException
820 * in case of I/O error
822 protected InputStream
openInput(URL source
) throws IOException
{
823 return Instance
.getCache().open(source
, this, false);
827 * Reset the given {@link InputStream} and return it.
830 * the {@link InputStream} to reset
832 * @return the same {@link InputStream} after reset
834 protected InputStream
reset(InputStream in
) {
837 } catch (IOException e
) {
843 * Reset then return {@link BasicSupport#in}.
845 * @return {@link BasicSupport#in}
847 protected InputStream
getInput() {
852 * Fix the author name if it is prefixed with some "by" {@link String}.
855 * the author with a possible prefix
857 * @return the author without prefixes
859 protected String
fixAuthor(String author
) {
860 if (author
!= null) {
861 for (String suffix
: new String
[] { " ", ":" }) {
862 for (String byString
: Instance
.getConfig()
863 .getString(Config
.BYS
).split(",")) {
865 if (author
.toUpperCase().startsWith(byString
.toUpperCase())) {
866 author
= author
.substring(byString
.length()).trim();
871 // Special case (without suffix):
872 if (author
.startsWith("©")) {
873 author
= author
.substring(1);
881 * Check quotes for bad format (i.e., quotes with normal paragraphs inside)
882 * and requotify them (i.e., separate them into QUOTE paragraphs and other
883 * paragraphs (quotes or not)).
886 * the paragraph to requotify (not necessarily a quote)
888 * @return the correctly (or so we hope) quotified paragraphs
890 protected List
<Paragraph
> requotify(Paragraph para
) {
891 List
<Paragraph
> newParas
= new ArrayList
<Paragraph
>();
893 if (para
.getType() == ParagraphType
.QUOTE
894 && para
.getContent().length() > 2) {
895 String line
= para
.getContent();
896 boolean singleQ
= line
.startsWith("" + openQuote
);
897 boolean doubleQ
= line
.startsWith("" + openDoubleQuote
);
899 // Do not try when more than one quote at a time
900 // (some stories are not easily readable if we do)
902 && line
.indexOf(closeQuote
, 1) < line
903 .lastIndexOf(closeQuote
)) {
908 && line
.indexOf(closeDoubleQuote
, 1) < line
909 .lastIndexOf(closeDoubleQuote
)) {
915 if (!singleQ
&& !doubleQ
) {
916 line
= openDoubleQuote
+ line
+ closeDoubleQuote
;
917 newParas
.add(new Paragraph(ParagraphType
.QUOTE
, line
));
919 char open
= singleQ ? openQuote
: openDoubleQuote
;
920 char close
= singleQ ? closeQuote
: closeDoubleQuote
;
923 boolean inQuote
= false;
925 for (char car
: line
.toCharArray()) {
928 } else if (car
== close
) {
930 } else if (car
== '.' && !inQuote
) {
938 String rest
= line
.substring(posDot
+ 1).trim();
939 line
= line
.substring(0, posDot
+ 1).trim();
940 newParas
.add(new Paragraph(ParagraphType
.QUOTE
, line
));
941 if (!rest
.isEmpty()) {
942 newParas
.addAll(requotify(processPara(rest
)));
956 * Process a {@link Paragraph} from a raw line of text.
958 * Will also fix quotes and HTML encoding if needed.
963 * @return the processed {@link Paragraph}
965 protected Paragraph
processPara(String line
) {
966 line
= ifUnhtml(line
).trim();
968 boolean space
= true;
970 boolean quote
= false;
971 boolean tentativeCloseQuote
= false;
975 StringBuilder builder
= new StringBuilder();
976 for (char car
: line
.toCharArray()) {
979 // dash, ndash and mdash: - – —
980 // currently: always use mdash
981 builder
.append(dashCount
== 1 ?
'-' : '—');
986 if (tentativeCloseQuote
) {
987 tentativeCloseQuote
= false;
988 if (Character
.isLetterOrDigit(car
)) {
991 // handle double-single quotes as double quotes
993 builder
.append(closeDoubleQuote
);
996 builder
.append(closeQuote
);
1002 case ' ': // note: unbreakable space
1005 case '\n': // just in case
1006 case '\r': // just in case
1007 builder
.append(' ');
1011 if (space
|| (brk
&& quote
)) {
1013 // handle double-single quotes as double quotes
1015 builder
.deleteCharAt(builder
.length() - 1);
1016 builder
.append(openDoubleQuote
);
1018 builder
.append(openQuote
);
1020 } else if (prev
== ' ' || prev
== car
) {
1021 // handle double-single quotes as double quotes
1023 builder
.deleteCharAt(builder
.length() - 1);
1024 builder
.append(openDoubleQuote
);
1026 builder
.append(openQuote
);
1029 // it is a quote ("I'm off") or a 'quote' ("This
1030 // 'good' restaurant"...)
1031 tentativeCloseQuote
= true;
1036 if (space
|| (brk
&& quote
)) {
1038 builder
.append(openDoubleQuote
);
1039 } else if (prev
== ' ') {
1040 builder
.append(openDoubleQuote
);
1042 builder
.append(closeDoubleQuote
);
1067 builder
.append(car
);
1076 if (space
|| (brk
&& quote
)) {
1078 builder
.append(openQuote
);
1080 // handle double-single quotes as double quotes
1082 builder
.deleteCharAt(builder
.length() - 1);
1083 builder
.append(openDoubleQuote
);
1085 builder
.append(openQuote
);
1099 // handle double-single quotes as double quotes
1101 builder
.deleteCharAt(builder
.length() - 1);
1102 builder
.append(closeDoubleQuote
);
1104 builder
.append(closeQuote
);
1113 if (space
|| (brk
&& quote
)) {
1115 builder
.append(openDoubleQuote
);
1117 builder
.append(openDoubleQuote
);
1130 builder
.append(closeDoubleQuote
);
1136 builder
.append(car
);
1143 if (tentativeCloseQuote
) {
1144 tentativeCloseQuote
= false;
1145 builder
.append(closeQuote
);
1148 line
= builder
.toString().trim();
1150 ParagraphType type
= ParagraphType
.NORMAL
;
1152 type
= ParagraphType
.BLANK
;
1154 type
= ParagraphType
.BREAK
;
1156 type
= ParagraphType
.QUOTE
;
1159 return new Paragraph(type
, line
);
1163 * Remove the HTML from the input <b>if</b> {@link BasicSupport#isHtml()} is
1169 * @return the no html version if needed
1171 private String
ifUnhtml(String input
) {
1172 if (isHtml() && input
!= null) {
1173 return StringUtils
.unhtml(input
);
1180 * Return a {@link BasicSupport} implementation supporting the given
1181 * resource if possible.
1184 * the story resource
1186 * @return an implementation that supports it, or NULL
1188 public static BasicSupport
getSupport(URL url
) {
1193 // TEXT and INFO_TEXT always support files (not URLs though)
1194 for (SupportType type
: SupportType
.values()) {
1195 if (type
!= SupportType
.TEXT
&& type
!= SupportType
.INFO_TEXT
) {
1196 BasicSupport support
= getSupport(type
);
1197 if (support
!= null && support
.supports(url
)) {
1203 for (SupportType type
: new SupportType
[] { SupportType
.INFO_TEXT
,
1204 SupportType
.TEXT
}) {
1205 BasicSupport support
= getSupport(type
);
1206 if (support
!= null && support
.supports(url
)) {
1215 * Return a {@link BasicSupport} implementation supporting the given type.
1220 * @return an implementation that supports it, or NULL
1222 public static BasicSupport
getSupport(SupportType type
) {
1225 return new Epub().setType(type
);
1227 return new InfoText().setType(type
);
1229 return new Fimfiction().setType(type
);
1231 return new Fanfiction().setType(type
);
1233 return new Text().setType(type
);
1235 return new MangaFox().setType(type
);
1237 return new E621().setType(type
);
1239 return new YiffStar().setType(type
);
1241 return new Cbz().setType(type
);
1243 return new Html().setType(type
);
1250 * Return the first line from the given input which correspond to the given
1256 * a string that must be found inside the target line (also
1257 * supports "^" at start to say "only if it starts with" the
1259 * @param relativeLine
1260 * the line to return based upon the target line position (-1 =
1261 * the line before, 0 = the target line...)
1265 static String
getLine(InputStream in
, String needle
, int relativeLine
) {
1266 return getLine(in
, needle
, relativeLine
, true);
1270 * Return a line from the given input which correspond to the given
1276 * a string that must be found inside the target line (also
1277 * supports "^" at start to say "only if it starts with" the
1279 * @param relativeLine
1280 * the line to return based upon the target line position (-1 =
1281 * the line before, 0 = the target line...)
1283 * takes the first result (as opposed to the last one, which will
1284 * also always spend the input)
1288 static String
getLine(InputStream in
, String needle
, int relativeLine
,
1294 } catch (IOException e
) {
1298 List
<String
> lines
= new ArrayList
<String
>();
1299 @SuppressWarnings("resource")
1300 Scanner scan
= new Scanner(in
, "UTF-8");
1302 scan
.useDelimiter("\\n");
1303 while (scan
.hasNext()) {
1304 lines
.add(scan
.next());
1307 if (needle
.startsWith("^")) {
1308 if (lines
.get(lines
.size() - 1).startsWith(
1309 needle
.substring(1))) {
1310 index
= lines
.size() - 1;
1314 if (lines
.get(lines
.size() - 1).contains(needle
)) {
1315 index
= lines
.size() - 1;
1320 if (index
>= 0 && index
+ relativeLine
< lines
.size()) {
1321 rep
= lines
.get(index
+ relativeLine
);