需求:
处理一段html代码中<p>标签,使其不嵌套,闭合,无内容暴露在标签之外
例如:
11111<p></p>22222<p>33333</p><p>44444</p>555555<p></p>66666
思维导图:
代码:
public static String checkpp(String content){
String Str;
int time =0;
int pos =0;
int path =0;
boolean flag =true;
int index1 =0;
int index2 =0;
//保证首尾位置分别为<p>和</p>
int firstindex = content.indexOf("<p>");
if(firstindex !=0){
content = "<p>"+content;
}
int lastindex = content.lastIndexOf("</p>");
if(lastindex != content.length()-4 || lastindex == -1){
content = content +"</p>";
}
StringBuffer sb = new StringBuffer(content);
do{
time++;
System.out.println("-------"+time+"----- path:"+path);
switch(path){
case 0:
index1 =sb.indexOf("<p>",pos+1);
index2 =sb.indexOf("</p>",pos+1);
System.out.println(sb.toString());
System.out.println("pos:"+pos);
System.out.println("index1:"+index1);
System.out.println("index2:"+index2);
if(index1 != -1){