1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 14:42:27 +08:00

Compare commits

..

4 Commits

Author SHA1 Message Date
dudaodong
24b8da360e release: v1.1.3, merge pr5 and pr6 2021-12-29 09:55:42 +08:00
donutloop
b106c428ae Every: use int counter (#6)
Use counter to verify all elements passed the perdicate func.
Replace slice of indexes with int counter.
2021-12-29 09:51:50 +08:00
dudaodong
8b1171d0cb fmt: go fmt for request_test.go 2021-12-28 19:28:55 +08:00
donutloop
ab012f2545 LowerFirst: use slicing and utf8 func tools (#5)
Replace looping with slicing and utf8 func tools operations.
2021-12-28 19:25:44 +08:00
6 changed files with 12 additions and 20 deletions

View File

@@ -6,7 +6,7 @@
<div align="center" style="text-align: center;"> <div align="center" style="text-align: center;">
![Go version](https://img.shields.io/badge/go-%3E%3D1.16<recommend>-9cf) ![Go version](https://img.shields.io/badge/go-%3E%3D1.16<recommend>-9cf)
[![Release](https://img.shields.io/badge/release-1.1.2-green.svg)](https://github.com/duke-git/lancet/releases) [![Release](https://img.shields.io/badge/release-1.1.3-green.svg)](https://github.com/duke-git/lancet/releases)
[![GoDoc](https://godoc.org/github.com//duke-git/lancet?status.svg)](https://pkg.go.dev/github.com/duke-git/lancet) [![GoDoc](https://godoc.org/github.com//duke-git/lancet?status.svg)](https://pkg.go.dev/github.com/duke-git/lancet)
[![Go Report Card](https://goreportcard.com/badge/github.com/duke-git/lancet)](https://goreportcard.com/report/github.com/duke-git/lancet) [![Go Report Card](https://goreportcard.com/badge/github.com/duke-git/lancet)](https://goreportcard.com/report/github.com/duke-git/lancet)
[![codecov](https://codecov.io/gh/duke-git/lancet/branch/main/graph/badge.svg?token=FC48T1F078)](https://codecov.io/gh/duke-git/lancet) [![codecov](https://codecov.io/gh/duke-git/lancet/branch/main/graph/badge.svg?token=FC48T1F078)](https://codecov.io/gh/duke-git/lancet)

View File

@@ -6,7 +6,7 @@
<div align="center" style="text-align: center;"> <div align="center" style="text-align: center;">
![Go version](https://img.shields.io/badge/go-%3E%3D1.16<recommend>-9cf) ![Go version](https://img.shields.io/badge/go-%3E%3D1.16<recommend>-9cf)
[![Release](https://img.shields.io/badge/release-1.1.2-green.svg)](https://github.com/duke-git/lancet/releases) [![Release](https://img.shields.io/badge/release-1.1.3-green.svg)](https://github.com/duke-git/lancet/releases)
[![GoDoc](https://godoc.org/github.com//duke-git/lancet?status.svg)](https://pkg.go.dev/github.com/duke-git/lancet) [![GoDoc](https://godoc.org/github.com//duke-git/lancet?status.svg)](https://pkg.go.dev/github.com/duke-git/lancet)
[![Go Report Card](https://goreportcard.com/badge/github.com/duke-git/lancet)](https://goreportcard.com/report/github.com/duke-git/lancet) [![Go Report Card](https://goreportcard.com/badge/github.com/duke-git/lancet)](https://goreportcard.com/report/github.com/duke-git/lancet)
[![codecov](https://codecov.io/gh/duke-git/lancet/branch/main/graph/badge.svg?token=FC48T1F078)](https://codecov.io/gh/duke-git/lancet) [![codecov](https://codecov.io/gh/duke-git/lancet/branch/main/graph/badge.svg?token=FC48T1F078)](https://codecov.io/gh/duke-git/lancet)

View File

@@ -34,7 +34,7 @@ func TestHttpGet(t *testing.T) {
func TestHttpPost(t *testing.T) { func TestHttpPost(t *testing.T) {
url := "http://api.postcodes.io/postcodes" url := "http://api.postcodes.io/postcodes"
type Postcode struct { type Postcode struct {
Postcodes []string `json:"postcodes"` Postcodes []string `json:"postcodes"`
} }
postcode := Postcode{[]string{"OX49 5NU"}} postcode := Postcode{[]string{"OX49 5NU"}}
bodyParams, _ := json.Marshal(postcode) bodyParams, _ := json.Marshal(postcode)

View File

@@ -100,15 +100,15 @@ func Every(slice, function interface{}) bool {
panic("function param should be of type func(int, " + elemType.String() + ")" + reflect.ValueOf(true).Type().String()) panic("function param should be of type func(int, " + elemType.String() + ")" + reflect.ValueOf(true).Type().String())
} }
var indexes []int var currentLength int
for i := 0; i < sv.Len(); i++ { for i := 0; i < sv.Len(); i++ {
flag := fn.Call([]reflect.Value{reflect.ValueOf(i), sv.Index(i)})[0] flag := fn.Call([]reflect.Value{reflect.ValueOf(i), sv.Index(i)})[0]
if flag.Bool() { if flag.Bool() {
indexes = append(indexes, i) currentLength++
} }
} }
return len(indexes) == sv.Len() return currentLength == sv.Len()
} }
// Some return true if any of the values in the list pass the predicate function. // Some return true if any of the values in the list pass the predicate function.

View File

@@ -8,6 +8,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"unicode" "unicode"
"unicode/utf8"
) )
// CamelCase covert string to camelCase string. // CamelCase covert string to camelCase string.
@@ -59,20 +60,10 @@ func LowerFirst(s string) string {
return "" return ""
} }
res := "" r, size := utf8.DecodeRuneInString(s)
for i, v := range []rune(s) { r = unicode.ToLower(r)
if i == 0 {
if v >= 65 && v <= 96 { return string(r) + s[size:]
v += 32
res += string(v)
} else {
return s
}
} else {
res += string(v)
}
}
return res
} }
// PadEnd pads string on the right side if it's shorter than size. // PadEnd pads string on the right side if it's shorter than size.

View File

@@ -70,6 +70,7 @@ func TestLowerFirst(t *testing.T) {
lowerFirst(t, "foo", "foo") lowerFirst(t, "foo", "foo")
lowerFirst(t, "BAR", "bAR") lowerFirst(t, "BAR", "bAR")
lowerFirst(t, "FOo", "fOo") lowerFirst(t, "FOo", "fOo")
lowerFirst(t, "FOo大", "fOo大")
} }
func lowerFirst(t *testing.T, test string, expected string) { func lowerFirst(t *testing.T, test string, expected string) {