mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
(refs #34)Link conversion checks existence of accounts and issues.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package util
|
||||
|
||||
import twirl.api.Html
|
||||
import scala.slick.driver.H2Driver.simple._
|
||||
import scala.util.matching.Regex
|
||||
|
||||
/**
|
||||
* Provides some usable implicit conversions.
|
||||
@@ -30,4 +30,23 @@ object Implicits {
|
||||
def &&(c2: => Column[Boolean], guard: => Boolean): Column[Boolean] = if(guard) c1 && c2 else c1
|
||||
}
|
||||
|
||||
implicit class RichString(value: String){
|
||||
def replaceBy(regex: Regex)(replace: Regex.MatchData => Option[String]): String = {
|
||||
val sb = new StringBuilder()
|
||||
var i = 0
|
||||
regex.findAllIn(value).matchData.foreach { m =>
|
||||
sb.append(value.substring(i, m.start))
|
||||
i = m.end
|
||||
replace(m) match {
|
||||
case Some(s) => sb.append(s)
|
||||
case None => sb.append(m.matched)
|
||||
}
|
||||
}
|
||||
if(i < value.length){
|
||||
sb.append(value.substring(i))
|
||||
}
|
||||
sb.toString
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user