utils.go 1.5 KB

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