MCPcopy Create free account
hub / github.com/diyhi/bbs / urlToHyperlink

Method urlToHyperlink

src/main/java/cms/utils/WebUtil.java:429–443  ·  view source on GitHub ↗

文本中的URL转超链接 @param text 文本 @return

(String text)

Source from the content-addressed store, hash-verified

427 * @return
428 */
429 public static String urlToHyperlink(String text){
430 // url的正则表达式
431 Matcher matcher = pattern.matcher(text);
432
433 String resultText = "";// (临时变量,保存转换后的文本)
434 int lastEnd = 0;// 保存每个链接最后一行的下标
435
436 while(matcher.find()){
437 resultText += text.substring(lastEnd, matcher.start());
438 resultText += "<a target=\"_blank\" href=\"" + matcher.group() + "\">" + matcher.group() + "</a>";
439 lastEnd = matcher.end();
440 }
441 resultText += text.substring(lastEnd);
442 return resultText;
443 }
444
445 /**
446 * 是否为微信浏览器

Callers 3

addPrivateMessageMethod · 0.95
addSystemNotifyMethod · 0.95
editSystemNotifyMethod · 0.95

Calls 1

findMethod · 0.65

Tested by

no test coverage detected