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.

51 lines
1.7KB

  1. #pragma once
  2. #include "common.hpp"
  3. namespace rack {
  4. /** Supplemental `std::string` functions
  5. */
  6. namespace string {
  7. /** Converts a UTF-16/32 string (depending on the size of wchar_t) to a UTF-8 string. */
  8. std::string fromWstring(const std::wstring &s);
  9. std::wstring toWstring(const std::string &s);
  10. /** Converts a `printf()` format string and optional arguments into a std::string
  11. Remember that "%s" must reference a `char *`, so use `.c_str()` for `std::string`s.
  12. */
  13. std::string f(const char *format, ...);
  14. /** Replaces all characters to lowercase letters */
  15. std::string lowercase(const std::string &s);
  16. /** Replaces all characters to uppercase letters */
  17. std::string uppercase(const std::string &s);
  18. std::string trim(const std::string &s);
  19. /** Truncates and adds "..." to a string, not exceeding `len` characters */
  20. std::string ellipsize(const std::string &s, size_t len);
  21. bool startsWith(const std::string &str, const std::string &prefix);
  22. bool endsWith(const std::string &str, const std::string &suffix);
  23. /** Extracts portions of a path */
  24. std::string directory(const std::string &path);
  25. std::string filename(const std::string &path);
  26. /** Extracts the portion of a path without the extension */
  27. std::string basename(const std::string &path);
  28. /** Extracts the extension of a path */
  29. std::string extension(const std::string &path);
  30. /** Scores how well a query matches a string.
  31. A score of 0 means no match.
  32. The score is arbitrary and is only meaningful for sorting.
  33. */
  34. float fuzzyScore(const std::string &s, const std::string &query);
  35. struct CaseInsensitiveCompare {
  36. bool operator()(const std::string &a, const std::string &b) const {
  37. return lowercase(a) < lowercase(b);
  38. }
  39. };
  40. } // namespace string
  41. } // namespace rack