Force replace html dirty text from biography

This commit is contained in:
CappielloAntonio 2021-08-11 16:08:53 +02:00
parent 522323073a
commit 0edd09569e
4 changed files with 38 additions and 20 deletions

View file

@ -9,6 +9,7 @@ import com.cappielloantonio.play.model.Song;
import com.google.android.exoplayer2.MediaItem;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -61,6 +62,17 @@ public class MusicUtil {
return "";
}
public static String forceReadableString(String string) {
if (string != null) {
return getReadableString(string)
.replaceAll(""", "\"")
.replaceAll("'", "'")
.replaceAll("<a[\\s]+([^>]+)>((?:.(?!</a>))*.)</a>", "");
}
return "";
}
public static List<String> getReadableStrings(List<String> strings) {
List<String> readableStrings = new ArrayList<>();
@ -93,21 +105,4 @@ public class MusicUtil {
String uri = MusicUtil.getSongFileUri(song);
return MediaItem.fromUri(uri);
}
public static CharSequence HTMLParser(String toParse) {
if (toParse != null && containsHTML(toParse)) {
return Html.fromHtml(toParse, Html.FROM_HTML_MODE_LEGACY);
}
else {
return toParse;
}
}
private static boolean containsHTML(String toParse) {
String HTML_PATTERN = "<(\"[^\"]*\"|'[^']*'|[^'\">])*>";
Pattern pattern = Pattern.compile(HTML_PATTERN);
Matcher matcher = pattern.matcher(toParse);
return matcher.find();
}
}