forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/github.com/redis/go-redis/v9/internal/util.go

75 lines
665 B
Go
Raw Normal View History

2024-02-18 10:42:21 +00:00
package internal
import (
"context"
"time"
"github.com/redis/go-redis/v9/internal/util"
)
func Sleep(ctx context.Context, dur time.Duration) error {
2024-02-18 10:42:21 +00:00
t := time.NewTimer(dur)
2024-02-18 10:42:21 +00:00
defer t.Stop()
select {
2024-02-18 10:42:21 +00:00
case <-t.C:
2024-02-18 10:42:21 +00:00
return nil
2024-02-18 10:42:21 +00:00
case <-ctx.Done():
2024-02-18 10:42:21 +00:00
return ctx.Err()
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
}
func ToLower(s string) string {
2024-02-18 10:42:21 +00:00
if isLower(s) {
2024-02-18 10:42:21 +00:00
return s
2024-02-18 10:42:21 +00:00
}
b := make([]byte, len(s))
2024-02-18 10:42:21 +00:00
for i := range b {
2024-02-18 10:42:21 +00:00
c := s[i]
2024-02-18 10:42:21 +00:00
if c >= 'A' && c <= 'Z' {
2024-02-18 10:42:21 +00:00
c += 'a' - 'A'
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
b[i] = c
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
return util.BytesToString(b)
2024-02-18 10:42:21 +00:00
}
func isLower(s string) bool {
2024-02-18 10:42:21 +00:00
for i := 0; i < len(s); i++ {
2024-02-18 10:42:21 +00:00
c := s[i]
2024-02-18 10:42:21 +00:00
if c >= 'A' && c <= 'Z' {
2024-02-18 10:42:21 +00:00
return false
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
return true
2024-02-18 10:42:21 +00:00
}