mirror of
https://gitee.com/johng/gf.git
synced 2024-12-01 19:57:40 +08:00
fix issue in gstr.RepliaceI; add command gen service for cli
This commit is contained in:
parent
215a50675e
commit
c256d2d4af
@ -3,6 +3,7 @@ package utils
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||
"github.com/gogf/gf/v2/os/gproc"
|
||||
)
|
||||
|
||||
@ -13,14 +14,17 @@ var (
|
||||
|
||||
// GoFmt formats the source file using command `gofmt -w -s PATH`.
|
||||
func GoFmt(path string) {
|
||||
if gofmtPath != "" {
|
||||
gproc.ShellExec(fmt.Sprintf(`%s -w -s %s`, gofmtPath, path))
|
||||
if gofmtPath == "" {
|
||||
mlog.Debug(`command "gofmt" not found`)
|
||||
return
|
||||
}
|
||||
gproc.ShellExec(fmt.Sprintf(`%s -w -s %s`, gofmtPath, path))
|
||||
}
|
||||
|
||||
// GoImports formats the source file using command `goimports -w PATH`.
|
||||
func GoImports(path string) {
|
||||
if goimportsPath != "" {
|
||||
gproc.ShellExec(fmt.Sprintf(`%s -w %s`, goimportsPath, path))
|
||||
if goimportsPath == "" {
|
||||
mlog.Debug(`command "goimports" not found`)
|
||||
}
|
||||
gproc.ShellExec(fmt.Sprintf(`%s -w %s`, goimportsPath, path))
|
||||
}
|
||||
|
@ -33,21 +33,17 @@ func ReplaceI(origin, search, replace string, count ...int) string {
|
||||
return origin
|
||||
}
|
||||
var (
|
||||
searchLength = len(search)
|
||||
searchLower = strings.ToLower(search)
|
||||
originLower string
|
||||
pos int
|
||||
diff = len(replace) - searchLength
|
||||
searchLength = len(search)
|
||||
replaceLength = len(replace)
|
||||
searchLower = strings.ToLower(search)
|
||||
originLower string
|
||||
pos int
|
||||
)
|
||||
for {
|
||||
originLower = strings.ToLower(origin)
|
||||
if pos = Pos(originLower, searchLower, pos); pos != -1 {
|
||||
origin = origin[:pos] + replace + origin[pos+searchLength:]
|
||||
if diff < 0 {
|
||||
pos += -diff
|
||||
} else {
|
||||
pos += diff + 1
|
||||
}
|
||||
pos += replaceLength
|
||||
if n--; n == 0 {
|
||||
break
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user