From ec37e3a3ff38adbee17d4c8aeeec94fbbc033264 Mon Sep 17 00:00:00 2001 From: zouap Date: Mon, 14 Mar 2022 11:40:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/search.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/routers/search.go b/routers/search.go index 32e82f9ac..a743867c3 100644 --- a/routers/search.go +++ b/routers/search.go @@ -355,29 +355,27 @@ func makePrivateRepo(repos models.RepositoryList, res *SearchRes, keyword 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 } -func replaceIngoreUpperOrLower(dest string, destLower string, keyword string, replace string) string { +func replaceIngoreUpperOrLower(dest string, destLower string, keywordLower string) string { re := "" last := 0 for i := 0; i < len(destLower); i++ { - if destLower[i] == keyword[0] { + if destLower[i] == keywordLower[0] { 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 break } } 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 } }