@Test public void include_target_txt_new_line_headline1_new_line_include_target2_txt_found_2includes() throws Exception { String text = "include::label.txt\n= headline1\ninclude::target2.txt"; List<AsciiDoctorFileReference> result = includeParserToTest.parse(text); assertReferences(result). hasReferences(2). hasReference("include::label.txt"). withPosition(0). withEnd(17). and(). hasReference("include::target2.txt"). withPosition(31). withEnd(50); }
public List<AsciiDoctorFileReference> parse(String asciidoctorScript) { List<AsciiDoctorFileReference> list = new ArrayList<AsciiDoctorFileReference>(); if (noIdentifierFound(asciidoctorScript)) { return list; } StringBuilder current = new StringBuilder(); int start=0; int currentPos = -1; for (char c : asciidoctorScript.toCharArray()) { currentPos++; if (inline && c ==']') { int end = currentPos-1; addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, end); current = new StringBuilder(); start =currentPos+1; continue; }else if (c == '\n') { int end = currentPos-1; addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, end); current = new StringBuilder(); start =currentPos+1; continue; } if (current != null) { if (inline) { if (Character.isWhitespace(c) && ! Character.isSpaceChar(c)) { continue; } } current.append(c); if (current.length()==1 && current.charAt(0) != firstChar) { current = null; } if (current!=null && current.length()==identifier.length()){ if (current.indexOf(identifier)!=0){ current=null; } } } } addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, currentPos); return list; }
SimpleReferenceParser { public List<AsciiDoctorFileReference> parse(String asciidoctorScript) { List<AsciiDoctorFileReference> list = new ArrayList<AsciiDoctorFileReference>(); if (noIdentifierFound(asciidoctorScript)) { return list; } StringBuilder current = new StringBuilder(); int start=0; int currentPos = -1; for (char c : asciidoctorScript.toCharArray()) { currentPos++; if (inline && c ==']') { int end = currentPos-1; addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, end); current = new StringBuilder(); start =currentPos+1; continue; }else if (c == '\n') { int end = currentPos-1; addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, end); current = new StringBuilder(); start =currentPos+1; continue; } if (current != null) { if (inline) { if (Character.isWhitespace(c) && ! Character.isSpaceChar(c)) { continue; } } current.append(c); if (current.length()==1 && current.charAt(0) != firstChar) { current = null; } if (current!=null && current.length()==identifier.length()){ if (current.indexOf(identifier)!=0){ current=null; } } } } addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, currentPos); return list; } }
SimpleReferenceParser { public List<AsciiDoctorFileReference> parse(String asciidoctorScript) { List<AsciiDoctorFileReference> list = new ArrayList<AsciiDoctorFileReference>(); if (noIdentifierFound(asciidoctorScript)) { return list; } StringBuilder current = new StringBuilder(); int start=0; int currentPos = -1; for (char c : asciidoctorScript.toCharArray()) { currentPos++; if (inline && c ==']') { int end = currentPos-1; addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, end); current = new StringBuilder(); start =currentPos+1; continue; }else if (c == '\n') { int end = currentPos-1; addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, end); current = new StringBuilder(); start =currentPos+1; continue; } if (current != null) { if (inline) { if (Character.isWhitespace(c) && ! Character.isSpaceChar(c)) { continue; } } current.append(c); if (current.length()==1 && current.charAt(0) != firstChar) { current = null; } if (current!=null && current.length()==identifier.length()){ if (current.indexOf(identifier)!=0){ current=null; } } } } addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, currentPos); return list; } SimpleReferenceParser(String identifier, boolean inline); }
SimpleReferenceParser { public List<AsciiDoctorFileReference> parse(String asciidoctorScript) { List<AsciiDoctorFileReference> list = new ArrayList<AsciiDoctorFileReference>(); if (noIdentifierFound(asciidoctorScript)) { return list; } StringBuilder current = new StringBuilder(); int start=0; int currentPos = -1; for (char c : asciidoctorScript.toCharArray()) { currentPos++; if (inline && c ==']') { int end = currentPos-1; addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, end); current = new StringBuilder(); start =currentPos+1; continue; }else if (c == '\n') { int end = currentPos-1; addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, end); current = new StringBuilder(); start =currentPos+1; continue; } if (current != null) { if (inline) { if (Character.isWhitespace(c) && ! Character.isSpaceChar(c)) { continue; } } current.append(c); if (current.length()==1 && current.charAt(0) != firstChar) { current = null; } if (current!=null && current.length()==identifier.length()){ if (current.indexOf(identifier)!=0){ current=null; } } } } addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, currentPos); return list; } SimpleReferenceParser(String identifier, boolean inline); List<AsciiDoctorFileReference> parse(String asciidoctorScript); }
SimpleReferenceParser { public List<AsciiDoctorFileReference> parse(String asciidoctorScript) { List<AsciiDoctorFileReference> list = new ArrayList<AsciiDoctorFileReference>(); if (noIdentifierFound(asciidoctorScript)) { return list; } StringBuilder current = new StringBuilder(); int start=0; int currentPos = -1; for (char c : asciidoctorScript.toCharArray()) { currentPos++; if (inline && c ==']') { int end = currentPos-1; addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, end); current = new StringBuilder(); start =currentPos+1; continue; }else if (c == '\n') { int end = currentPos-1; addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, end); current = new StringBuilder(); start =currentPos+1; continue; } if (current != null) { if (inline) { if (Character.isWhitespace(c) && ! Character.isSpaceChar(c)) { continue; } } current.append(c); if (current.length()==1 && current.charAt(0) != firstChar) { current = null; } if (current!=null && current.length()==identifier.length()){ if (current.indexOf(identifier)!=0){ current=null; } } } } addWhenCurrentNotEmptyAndStartsWithIdentifier(asciidoctorScript, list, current, start, currentPos); return list; } SimpleReferenceParser(String identifier, boolean inline); List<AsciiDoctorFileReference> parse(String asciidoctorScript); static final SimpleReferenceParser INCLUDE_PARSER; static final SimpleReferenceParser PLANTUML_PARSER; static final SimpleReferenceParser DITAA_PARSER; static final SimpleReferenceParser IMAGE_PARSER; }