mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
fix issue in gstr.Chr
This commit is contained in:
@ -26,7 +26,7 @@ func (view *View) funcInclude(file string, data...map[string]interface{}) string
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return string(content)
|
||||
return content
|
||||
}
|
||||
|
||||
// Build-in template function: text
|
||||
|
||||
@ -332,14 +332,14 @@ func ContainsAny(s, chars string) bool {
|
||||
func CountWords(str string) map[string]int {
|
||||
m := make(map[string]int)
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
for _, rune := range []rune(str) {
|
||||
if unicode.IsSpace(rune) {
|
||||
for _, r := range []rune(str) {
|
||||
if unicode.IsSpace(r) {
|
||||
if buffer.Len() > 0 {
|
||||
m[buffer.String()]++
|
||||
buffer.Reset()
|
||||
}
|
||||
} else {
|
||||
buffer.WriteRune(rune)
|
||||
buffer.WriteRune(r)
|
||||
}
|
||||
}
|
||||
if buffer.Len() > 0 {
|
||||
@ -349,8 +349,6 @@ func CountWords(str string) map[string]int {
|
||||
}
|
||||
|
||||
// CountChars returns information about chars' count used in a string.
|
||||
//
|
||||
// 返回字符串中字符的使用情况。
|
||||
func CountChars(str string, noSpace...bool) map[string]int {
|
||||
m := make(map[string]int)
|
||||
countSpace := true
|
||||
@ -484,10 +482,7 @@ func Implode(glue string, pieces []string) string {
|
||||
|
||||
// Chr return the ascii string of a number(0-255).
|
||||
func Chr(ascii int) string {
|
||||
if ascii > 255 {
|
||||
return ""
|
||||
}
|
||||
return string([]byte{byte(ascii)})
|
||||
return string([]byte{byte(ascii%256)})
|
||||
}
|
||||
|
||||
// Ord converts the first byte of a string to a value between 0 and 255.
|
||||
|
||||
Reference in New Issue
Block a user