1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| nt positiontitre=-1; // on utilise -1 pour indiquer qu'on n'a pas de titre
for(int i=0; i<lignes.size(); i++) {
if ( pattern.matcher(ligne).matches() && !ligne.contains("(Scored)") && !ligne.contains("(Not Scored)") ) {
positiontitre = i; // on a détecter un titre incomplet, donc on stocke sa position
}
else if ( positiontitre!=-1 ) { // on sait qu'on a un titre incomplet à complèter...
if ( ligne.contains("(Scored)") || ligne.contains("(Not Scored)") ) { // on détecte si on a la fin du titre
// ici on a la fin du titre, et on sait qu'il est en i
// donc maintenant on va regrouper toutes les lignes entre positiontitre et i, et on passera au titres suivants
StringBuilder sb = new StringBuilder();
for(int j=positiontitre; j<=i; j++) {
if ( sb.length()>0 ) { // si on a déjà quelque chose dans le StringBuilder, on ajouter un retour chariot pour passer à la ligne
sb.append("\n");
}
sb.append(lignes.get(j));
}
String titrecomplet = sb.toString();
lignes.set(positionTitre, titreComplet);
for(int j=i; j>positionTitre; j--) {
lignes.remove(j);
}
i=positionTitre;
positionTitre = -1;
}
}
} |