本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.3KB

  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package util
  5. import (
  6. "strings"
  7. )
  8. // OptionalBool a boolean that can be "null"
  9. type OptionalBool byte
  10. const (
  11. // OptionalBoolNone a "null" boolean value
  12. OptionalBoolNone = iota
  13. // OptionalBoolTrue a "true" boolean value
  14. OptionalBoolTrue
  15. // OptionalBoolFalse a "false" boolean value
  16. OptionalBoolFalse
  17. )
  18. // IsTrue return true if equal to OptionalBoolTrue
  19. func (o OptionalBool) IsTrue() bool {
  20. return o == OptionalBoolTrue
  21. }
  22. // IsFalse return true if equal to OptionalBoolFalse
  23. func (o OptionalBool) IsFalse() bool {
  24. return o == OptionalBoolFalse
  25. }
  26. // IsNone return true if equal to OptionalBoolNone
  27. func (o OptionalBool) IsNone() bool {
  28. return o == OptionalBoolNone
  29. }
  30. // OptionalBoolOf get the corresponding OptionalBool of a bool
  31. func OptionalBoolOf(b bool) OptionalBool {
  32. if b {
  33. return OptionalBoolTrue
  34. }
  35. return OptionalBoolFalse
  36. }
  37. // Max max of two ints
  38. func Max(a, b int) int {
  39. if a < b {
  40. return b
  41. }
  42. return a
  43. }
  44. // Min min of two ints
  45. func Min(a, b int) int {
  46. if a > b {
  47. return b
  48. }
  49. return a
  50. }
  51. // IsEmptyString checks if the provided string is empty
  52. func IsEmptyString(s string) bool {
  53. return len(strings.TrimSpace(s)) == 0
  54. }
上海开阖软件有限公司 沪ICP备12045867号-1