Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1 | package internal |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "time" |
| 6 | |
| 7 | "github.com/go-redis/redis/v8/internal/util" |
| 8 | ) |
| 9 | |
| 10 | func Sleep(ctx context.Context, dur time.Duration) error { |
| 11 | t := time.NewTimer(dur) |
| 12 | defer t.Stop() |
| 13 | |
| 14 | select { |
| 15 | case <-t.C: |
| 16 | return nil |
| 17 | case <-ctx.Done(): |
| 18 | return ctx.Err() |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | func ToLower(s string) string { |
| 23 | if isLower(s) { |
| 24 | return s |
| 25 | } |
| 26 | |
| 27 | b := make([]byte, len(s)) |
| 28 | for i := range b { |
| 29 | c := s[i] |
| 30 | if c >= 'A' && c <= 'Z' { |
| 31 | c += 'a' - 'A' |
| 32 | } |
| 33 | b[i] = c |
| 34 | } |
| 35 | return util.BytesToString(b) |
| 36 | } |
| 37 | |
| 38 | func isLower(s string) bool { |
| 39 | for i := 0; i < len(s); i++ { |
| 40 | c := s[i] |
| 41 | if c >= 'A' && c <= 'Z' { |
| 42 | return false |
| 43 | } |
| 44 | } |
| 45 | return true |
| 46 | } |