Collection of DPF-based plugins for packaging
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.

75 lines
2.9KB

  1. //
  2. // ██████ ██  ██  ██████  ██████
  3. // ██      ██  ██ ██    ██ ██       ** Classy Header-Only Classes **
  4. // ██  ███████ ██  ██ ██
  5. // ██  ██   ██ ██  ██ ██ https://github.com/Tracktion/choc
  6. //  ██████ ██  ██  ██████   ██████
  7. //
  8. // CHOC is (C)2022 Tracktion Corporation, and is offered under the terms of the ISC license:
  9. //
  10. // Permission to use, copy, modify, and/or distribute this software for any purpose with or
  11. // without fee is hereby granted, provided that the above copyright notice and this permission
  12. // notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. // WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  14. // AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
  15. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  16. // WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  17. // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. #ifndef CHOC_STRING_UTILS_HEADER_INCLUDED
  19. #define CHOC_STRING_UTILS_HEADER_INCLUDED
  20. #include <cctype>
  21. #include <string>
  22. #include <vector>
  23. #include <cmath>
  24. #include <chrono>
  25. #include <memory>
  26. #include <algorithm>
  27. #include <cwctype>
  28. START_NAMESPACE_DISTRHO
  29. //==============================================================================
  30. /// Returns a hex string for the given value.
  31. /// If the minimum number of digits is non-zero, it will be zero-padded to fill this length;
  32. template <typename IntegerType>
  33. std::string createHexString (IntegerType value);
  34. //==============================================================================
  35. // _ _ _ _
  36. // __| | ___ | |_ __ _ (_)| | ___
  37. // / _` | / _ \| __| / _` || || |/ __|
  38. // | (_| || __/| |_ | (_| || || |\__ \ _ _ _
  39. // \__,_| \___| \__| \__,_||_||_||___/(_)(_)(_)
  40. //
  41. // Code beyond this point is implementation detail...
  42. //
  43. //==============================================================================
  44. template <typename IntegerType>
  45. std::string createHexString (IntegerType v)
  46. {
  47. static_assert (std::is_integral<IntegerType>::value, "Need to pass integers into this method");
  48. auto value = static_cast<typename std::make_unsigned<IntegerType>::type> (v);
  49. char hex[40];
  50. const auto end = hex + sizeof (hex) - 1;
  51. auto d = end;
  52. *d = 0;
  53. for (;;)
  54. {
  55. *--d = "0123456789abcdef"[static_cast<uint32_t> (value) & 15u];
  56. value = static_cast<decltype (value)> (value >> 4);
  57. if (value == 0)
  58. return std::string (d, end);
  59. }
  60. }
  61. END_NAMESPACE_DISTRHO
  62. #endif