mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-04 22:51:47 +01:00
♻️ 一些工具函数移动到 gulu 项目中
This commit is contained in:
parent
afbe434239
commit
705f34ccd1
10 changed files with 20 additions and 65 deletions
|
|
@ -21,6 +21,7 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/ConradIrwin/font/sfnt"
|
||||
"github.com/flopp/go-findfont"
|
||||
ttc "golang.org/x/image/font/sfnt"
|
||||
|
|
@ -30,7 +31,7 @@ import (
|
|||
|
||||
func GetSysFonts(currentLanguage string) (ret []string) {
|
||||
fonts := loadFonts(currentLanguage)
|
||||
ret = RemoveDuplicatedElem(fonts)
|
||||
ret = gulu.Str.RemoveDuplicatedElem(fonts)
|
||||
ret = removeUnusedFonts(ret)
|
||||
sort.Strings(ret)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import (
|
|||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -87,7 +89,7 @@ func GetLocalIPs() (ret []string) {
|
|||
if "android" == Container {
|
||||
// Android 上用不了 net.InterfaceAddrs() https://github.com/golang/go/issues/40569,所以前面使用启动内核传入的参数 localIPs
|
||||
LocalIPs = append(LocalIPs, "127.0.0.1")
|
||||
LocalIPs = RemoveDuplicatedElem(LocalIPs)
|
||||
LocalIPs = gulu.Str.RemoveDuplicatedElem(LocalIPs)
|
||||
return LocalIPs
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +106,7 @@ func GetLocalIPs() (ret []string) {
|
|||
}
|
||||
}
|
||||
ret = append(ret, "127.0.0.1")
|
||||
ret = RemoveDuplicatedElem(ret)
|
||||
ret = gulu.Str.RemoveDuplicatedElem(ret)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
// SiYuan - Build Your Eternal Digital Garden
|
||||
// Copyright (c) 2020-present, b3log.org
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package util
|
||||
|
||||
import "github.com/88250/gulu"
|
||||
|
||||
func RemoveElem(slice []string, elem string) (ret []string) {
|
||||
for _, e := range slice {
|
||||
if e != elem {
|
||||
ret = append(ret, e)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func ExcludeElem(slice, excludes []string) (ret []string) {
|
||||
ret = []string{}
|
||||
for _, e := range slice {
|
||||
if !gulu.Str.Contains(e, excludes) {
|
||||
ret = append(ret, e)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func RemoveDuplicatedElem(slice []string) (ret []string) {
|
||||
allKeys := make(map[string]bool)
|
||||
for _, item := range slice {
|
||||
if _, value := allKeys[item]; !value {
|
||||
allKeys[item] = true
|
||||
ret = append(ret, item)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue