utils.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package main
  2. import (
  3. "unicode"
  4. "github.com/leonelquinteros/gotext"
  5. "github.com/Jguer/yay/v9/pkg/text"
  6. )
  7. const gitEmptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
  8. func stringSliceEqual(a, b []string) bool {
  9. if a == nil && b == nil {
  10. return true
  11. }
  12. if a == nil || b == nil {
  13. return false
  14. }
  15. if len(a) != len(b) {
  16. return false
  17. }
  18. for i := 0; i < len(a); i++ {
  19. if a[i] != b[i] {
  20. return false
  21. }
  22. }
  23. return true
  24. }
  25. func removeInvalidTargets(targets []string) []string {
  26. filteredTargets := make([]string, 0)
  27. for _, target := range targets {
  28. db, _ := splitDBFromName(target)
  29. if db == "aur" && mode == modeRepo {
  30. text.Warnln(gotext.Get("%s: can't use target with option --repo -- skipping", cyan(target)))
  31. continue
  32. }
  33. if db != "aur" && db != "" && mode == modeAUR {
  34. text.Warnln(gotext.Get("%s: can't use target with option --aur -- skipping", cyan(target)))
  35. continue
  36. }
  37. filteredTargets = append(filteredTargets, target)
  38. }
  39. return filteredTargets
  40. }
  41. // LessRunes compares two rune values, and returns true if the first argument is lexicographicaly smaller.
  42. func LessRunes(iRunes, jRunes []rune) bool {
  43. max := len(iRunes)
  44. if max > len(jRunes) {
  45. max = len(jRunes)
  46. }
  47. for idx := 0; idx < max; idx++ {
  48. ir := iRunes[idx]
  49. jr := jRunes[idx]
  50. lir := unicode.ToLower(ir)
  51. ljr := unicode.ToLower(jr)
  52. if lir != ljr {
  53. return lir < ljr
  54. }
  55. // the lowercase runes are the same, so compare the original
  56. if ir != jr {
  57. return ir < jr
  58. }
  59. }
  60. return len(iRunes) < len(jRunes)
  61. }