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.

column_map.go 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2019 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package statements
  5. import (
  6. "strings"
  7. "xorm.io/xorm/schemas"
  8. )
  9. type columnMap []string
  10. func (m columnMap) Contain(colName string) bool {
  11. if len(m) == 0 {
  12. return false
  13. }
  14. n := len(colName)
  15. for _, mk := range m {
  16. if len(mk) != n {
  17. continue
  18. }
  19. if strings.EqualFold(mk, colName) {
  20. return true
  21. }
  22. }
  23. return false
  24. }
  25. func (m columnMap) Len() int {
  26. return len(m)
  27. }
  28. func (m columnMap) IsEmpty() bool {
  29. return len(m) == 0
  30. }
  31. func (m *columnMap) Add(colName string) bool {
  32. if m.Contain(colName) {
  33. return false
  34. }
  35. *m = append(*m, colName)
  36. return true
  37. }
  38. func getFlagForColumn(m map[string]bool, col *schemas.Column) (val bool, has bool) {
  39. if len(m) == 0 {
  40. return false, false
  41. }
  42. n := len(col.Name)
  43. for mk := range m {
  44. if len(mk) != n {
  45. continue
  46. }
  47. if strings.EqualFold(mk, col.Name) {
  48. return m[mk], true
  49. }
  50. }
  51. return false, false
  52. }