| OLD | NEW |
| 1 package util | 1 package util |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "crypto/rand" | 4 "crypto/rand" |
| 5 "crypto/sha256" | 5 "crypto/sha256" |
| 6 "fmt" | 6 "fmt" |
| 7 "io" | 7 "io" |
| 8 mathrand "math/rand" | 8 mathrand "math/rand" |
| 9 "os" | 9 "os" |
| 10 "reflect" |
| 10 "regexp" | 11 "regexp" |
| 11 "runtime" | 12 "runtime" |
| 12 "sort" | 13 "sort" |
| 13 "strings" | 14 "strings" |
| 14 "time" | 15 "time" |
| 15 | 16 |
| 16 "github.com/skia-dev/glog" | 17 "github.com/skia-dev/glog" |
| 17 ) | 18 ) |
| 18 | 19 |
| 19 const ( | 20 const ( |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 | 439 |
| 439 // AnyMatch returns true iff the given string matches any regexp in the slice. | 440 // AnyMatch returns true iff the given string matches any regexp in the slice. |
| 440 func AnyMatch(re []*regexp.Regexp, s string) bool { | 441 func AnyMatch(re []*regexp.Regexp, s string) bool { |
| 441 for _, r := range re { | 442 for _, r := range re { |
| 442 if r.MatchString(s) { | 443 if r.MatchString(s) { |
| 443 return true | 444 return true |
| 444 } | 445 } |
| 445 } | 446 } |
| 446 return false | 447 return false |
| 447 } | 448 } |
| 449 |
| 450 // Returns true if i is nil or is an interface containing a nil or invalid value
. |
| 451 func IsNil(i interface{}) bool { |
| 452 if i == nil { |
| 453 return true |
| 454 } |
| 455 v := reflect.ValueOf(i) |
| 456 if !v.IsValid() { |
| 457 return true |
| 458 } |
| 459 switch v.Kind() { |
| 460 case reflect.Chan, reflect.Func, reflect.Map, reflect.Slice: |
| 461 return v.IsNil() |
| 462 case reflect.Interface, reflect.Ptr: |
| 463 if v.IsNil() { |
| 464 return true |
| 465 } |
| 466 inner := v.Elem() |
| 467 if !inner.IsValid() { |
| 468 return true |
| 469 } |
| 470 if inner.CanInterface() { |
| 471 return IsNil(inner.Interface()) |
| 472 } |
| 473 return false |
| 474 default: |
| 475 return false |
| 476 } |
| 477 } |
| OLD | NEW |