Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.3.2^2
zouap 4 years ago
parent
commit
ec37e3a3ff
1 changed files with 9 additions and 11 deletions
  1. +9
    -11
      routers/search.go

+ 9
- 11
routers/search.go View File

@@ -355,29 +355,27 @@ func makePrivateRepo(repos models.RepositoryList, res *SearchRes, keyword string
} }


func makeHighLight(keyword string, dest string) string { func makeHighLight(keyword string, dest string) string {
textRune := []rune(strings.ToLower(dest))
index := findFont(textRune, 0, []rune(strings.ToLower(keyword)))
if index >= 0 {
dest = replaceIngoreUpperOrLower(dest, strings.ToLower(dest), strings.ToLower(keyword), "\u003cfont color='red'\u003e"+keyword+"\u003c/font\u003e")
}

dest = replaceIngoreUpperOrLower(dest, strings.ToLower(dest), strings.ToLower(keyword))

return dest return dest
} }


func replaceIngoreUpperOrLower(dest string, destLower string, keyword string, replace string) string {
func replaceIngoreUpperOrLower(dest string, destLower string, keywordLower string) string {
re := "" re := ""
last := 0 last := 0
for i := 0; i < len(destLower); i++ { for i := 0; i < len(destLower); i++ {
if destLower[i] == keyword[0] {
if destLower[i] == keywordLower[0] {
isFind := true isFind := true
for j := 1; j < len(keyword); j++ {
if keyword[j] != destLower[i+j] {
for j := 1; j < len(keywordLower); j++ {
if keywordLower[j] != destLower[i+j] {
isFind = false isFind = false
break break
} }
} }
if isFind { if isFind {
re += dest[last:i] + replace
i = i + len(keyword)
re += dest[last:i] + "\u003cfont color='red'\u003e" + dest[i:(i+len(keywordLower))] + "\u003c/font\u003e"
i = i + len(keywordLower)
last = i last = i
} }
} }


Loading…
Cancel
Save