strings.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // ⚡️ Fiber is an Express inspired web framework written in Go with ☕️
  2. // 🤖 Github Repository: https://github.com/gofiber/fiber
  3. // 📌 API Documentation: https://docs.gofiber.io
  4. package utils
  5. import (
  6. casestrings "github.com/gofiber/utils/v2/strings"
  7. )
  8. // ToLower converts ascii string to lower-case.
  9. //
  10. // Deprecated: use package "github.com/gofiber/utils/v2/strings" and call strings.ToLower.
  11. func ToLower(b string) string {
  12. return casestrings.ToLower(b)
  13. }
  14. // ToUpper converts ascii string to upper-case.
  15. //
  16. // Deprecated: use package "github.com/gofiber/utils/v2/strings" and call strings.ToUpper.
  17. func ToUpper(b string) string {
  18. return casestrings.ToUpper(b)
  19. }
  20. // AddTrailingSlashString appends a trailing '/' to s if it does not already end with one.
  21. // If the input already ends with '/', the original string is returned.
  22. // A new string is returned only when a '/' needs to be appended.
  23. func AddTrailingSlashString(s string) string {
  24. n := len(s)
  25. if n == 0 {
  26. return "/"
  27. }
  28. if s[n-1] == '/' {
  29. return s
  30. }
  31. buf := make([]byte, n+1)
  32. copy(buf, s)
  33. buf[n] = '/'
  34. return UnsafeString(buf)
  35. }