package com.yidian.shenghuoquan.buserorder.utils

import java.lang.StringBuilder
import java.util.regex.Pattern

object Utils {
  //域名后缀，需要可以添加
  private val come = arrayOf(
    "top", "com.cn", "com", "net", "cn", "cc", "gov", "cn", "hk"
  )
  fun isWebUrl(url: String?): Boolean {
    if (url == null) {
      return false
    }
    val sb = StringBuilder()
    sb.append("(")
    for (anExt in come) {
      sb.append(anExt)
      sb.append("|")
    }
    sb.deleteCharAt(sb.length - 1)
    sb.append(")")
    val pattern =
      "((https?|s?ftp|irc[6s]?|git|afp|telnet|smb)://)?((\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})|((www\\.|[a-zA-Z\\.\\-]+\\.)?[a-zA-Z0-9\\-]+\\.$sb(:[0-9]{1,5})?))((/[a-zA-Z0-9\\./,;\\?'\\+&%\\$#=~_\\-]*)|([^\\u4e00-\\u9fa5\\s0-9a-zA-Z\\./,;\\?'\\+&%\\$#=~_\\-]*))"
    return Pattern.compile(pattern).matcher(url).matches()
  }


}
