public static String unwebMessageTextPoint(String text) { text = Utils.replace(text, "<br/>", "\n"); text = Utils.replace(text, "<br />", "\n"); text = Utils.replace(text, "<b>", "*"); text = Utils.replace(text, "</b>", "*"); text = Utils.replace(text, "<p>", ""); text = Utils.replace(text, "</p>", "\n"); text = Utils.replace(text, "<x>", ""); text = Utils.replace(text, "</x>", ""); text = Utils.replace(text, ">", ">"); text = Utils.replace(text, "<", "<"); text = Utils.replace(text, "«", "«"); text = Utils.replace(text, """, "\""); text = Utils.replace(text, "©", "©"); text = Utils.replace(text, "»", "»"); text = Utils.replace(text, "—", "-"); text = Utils.replace(text, " ", " "); text = Utils.replace(text, "<div class=\"text-content\">", ""); text = Utils.replace(text, "<div class=\"text\">", ""); text = Utils.replace(text, "</div>", ""); text = Utils.replace(text, " \n", "\n"); while (text.startsWith("\n") || text.startsWith(" ")) { text = text.substring(1); } String[] texts = StringSplitter.split(text, "\n"); StringBuilder sb = new StringBuilder(); for (String s : texts) { sb.append(s.trim()); // trim all sb.append("\n"); } while (sb.length() > 0 && sb.charAt(sb.length() - 1) == '\n') sb.setLength(sb.length() - 1); // remove last \n String beforeYoutube = sb.toString(); int ix = 0; while (ix != -1) { ix = beforeYoutube.indexOf(HTTPS_IMG_YOUTUBE_COM_VI, ix); if (ix >= 0) { ix += HTTPS_IMG_YOUTUBE_COM_VI.length(); int ix2 = beforeYoutube.indexOf("/", ix); String key = beforeYoutube.substring(ix, ix2); ix2 = beforeYoutube.indexOf(" ", ix); if (ix2 == -1) ix2 = beforeYoutube.length(); beforeYoutube = beforeYoutube.substring(0, ix2) + " https://www.youtube.com/watch?v=" + key + beforeYoutube.substring(ix2); ix = ix2; } } return beforeYoutube; }
public URLParser(final String url) { final int ix = url.indexOf("//"); if (ix == -1) throw new IllegalArgumentException("Invalid full url: " + url); protocol = url.substring(0, ix - 1); int ix2 = url.indexOf('/', ix + 2); if (ix2 == -1) throw new IllegalArgumentException("Invalid full url: " + url); String hostport = url.substring(ix + 2, ix2); path = url.substring(ix2 + 1); int portIx = hostport.indexOf(":"); if (portIx == -1) { host = hostport; } else { host = hostport.substring(0, portIx); port = hostport.substring(portIx + 1); } int paramsIx = path.indexOf("?"); if (paramsIx != -1) { String[] args = StringSplitter.split(StringSplitter.split(path.substring(paramsIx + 1), "#")[0], "&"); path = path.substring(0, paramsIx); for (int i = 0; i < args.length; i++) { String arg = args[i]; paramsIx = arg.indexOf("="); if (paramsIx == -1) { argsMap.put(arg, ""); } else { argsMap.put(arg.substring(0, paramsIx), arg.substring(paramsIx + 1)); } } } else { path = StringSplitter.split(path, "#")[0]; } int hashIx = url.indexOf("#"); if (hashIx != -1) { hash = url.substring(hashIx + 1); } }