Прогнал через разные html коды с разной степенью вложености , все четко выводит на консоль. Но валидатор принимать отказывается. Может кто шарит
package com.javarush.task.task19.task1918;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Знакомство с тегами
*/
public class Solution {
public static void main(String[] args) {
String teg = args[0];//"span";//
String startTeg = "<"+teg;
String fileName = "F:File1.txt";
String text = "";
try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))){
fileName = reader.readLine();
}catch (IOException ex){}
try(BufferedReader reader1 = new BufferedReader(new FileReader(fileName))){
while(reader1.ready()){
text+= reader1.readLine();
}
}catch(IOException exep){}
List<String>newList = tegParsers(text,teg);
for(String str: newList){
System.out.println(str);
}
}
public static List<String> tegParsers(String text,String teg){
List<String> tegess = new ArrayList<>();
List<Integer> startIndexInTeg = new ArrayList<>();
List<Integer> endIndexInTeg = new ArrayList<>();
int quantityStart = 0;
int quantityEnd = 0;
String endTeg = "</"+teg+">";
String starterTeg = "<"+teg;
int startIndex = 0;
int endIndex = text.length();
int secondStart = 0;
int secondEnd = 0;
for(int i = 0;i<text.length();i++){
char current = text.charAt(i);
if((current == '<') && text.charAt(i+1)!='/'&&text.substring(i,i+starterTeg.length()).equals(starterTeg) ) {
quantityStart++;
if(quantityStart<2){
startIndex = i;
}else{
startIndexInTeg.add(i);
}
}else if((current == '<') && text.charAt(i+1)=='/'&&text.substring(i,i+endTeg.length()).equals(endTeg)){
quantityEnd++;
if(quantityEnd==quantityStart){
endIndex = i+endTeg.length();
tegess.add(text.substring(startIndex,endIndex));
if(quantityStart>1&&quantityEnd>1){
for(int j = 0; j<startIndexInTeg.size();j++){
tegess.add(text.substring(startIndexInTeg.get(j),endIndexInTeg.get(j)));
}
startIndexInTeg.clear();
endIndexInTeg.clear();
}
quantityEnd=0;
quantityStart=0;
}else{
endIndexInTeg.add(i+endTeg.length());
}
}
}
return tegess;
}
}
Слушай, а ты вот так и отправляешь на проверку с "F:File1.txt" ? Там вроде имя надо было читать из консоли.А не, ложная тревога, написано так чудно, что хрен прочтёшь ) С виде действительно работает, хоть и совершенно не читаемо и есть не используемые куски кода... попробуй причесать может, вдруг чего и найдётся. Есть например удобные методы типа startsWith и indexOf