fs_util.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <concepts>
  6. #include <span>
  7. #include <string>
  8. #include <string_view>
  9. #include "common/common_types.h"
  10. namespace Common::FS {
  11. template <typename T>
  12. concept IsChar = std::same_as<T, char>;
  13. /**
  14. * Converts a UTF-8 encoded std::string or std::string_view to a std::u8string.
  15. *
  16. * @param utf8_string UTF-8 encoded string
  17. *
  18. * @returns UTF-8 encoded std::u8string.
  19. */
  20. [[nodiscard]] std::u8string ToU8String(std::string_view utf8_string);
  21. /**
  22. * Converts a buffer of bytes to a UTF8-encoded std::u8string.
  23. * This converts from the start of the buffer until the first encountered null-terminator.
  24. * If no null-terminator is found, this converts the entire buffer instead.
  25. *
  26. * @param buffer Buffer of bytes
  27. *
  28. * @returns UTF-8 encoded std::u8string.
  29. */
  30. [[nodiscard]] std::u8string BufferToU8String(std::span<const u8> buffer);
  31. /**
  32. * Converts a std::u8string or std::u8string_view to a UTF-8 encoded std::string.
  33. *
  34. * @param u8_string UTF-8 encoded u8string
  35. *
  36. * @returns UTF-8 encoded std::string.
  37. */
  38. [[nodiscard]] std::string ToUTF8String(std::u8string_view u8_string);
  39. } // namespace Common::FS