Audio plugin host https://kx.studio/carla
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.

176 lines
5.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. namespace water {
  24. //==============================================================================
  25. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) noexcept
  26. {
  27. return (juce_wchar) towupper ((wint_t) character);
  28. }
  29. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) noexcept
  30. {
  31. return (juce_wchar) towlower ((wint_t) character);
  32. }
  33. bool CharacterFunctions::isUpperCase (const juce_wchar character) noexcept
  34. {
  35. #ifdef CARLA_OS_WIN
  36. return iswupper ((wint_t) character) != 0;
  37. #else
  38. return toLowerCase (character) != character;
  39. #endif
  40. }
  41. bool CharacterFunctions::isLowerCase (const juce_wchar character) noexcept
  42. {
  43. #ifdef CARLA_OS_WIN
  44. return iswlower ((wint_t) character) != 0;
  45. #else
  46. return toUpperCase (character) != character;
  47. #endif
  48. }
  49. //==============================================================================
  50. bool CharacterFunctions::isWhitespace (const char character) noexcept
  51. {
  52. return character == ' ' || (character <= 13 && character >= 9);
  53. }
  54. bool CharacterFunctions::isWhitespace (const juce_wchar character) noexcept
  55. {
  56. return iswspace ((wint_t) character) != 0;
  57. }
  58. bool CharacterFunctions::isDigit (const char character) noexcept
  59. {
  60. return (character >= '0' && character <= '9');
  61. }
  62. bool CharacterFunctions::isDigit (const juce_wchar character) noexcept
  63. {
  64. return iswdigit ((wint_t) character) != 0;
  65. }
  66. bool CharacterFunctions::isLetter (const char character) noexcept
  67. {
  68. return (character >= 'a' && character <= 'z')
  69. || (character >= 'A' && character <= 'Z');
  70. }
  71. bool CharacterFunctions::isLetter (const juce_wchar character) noexcept
  72. {
  73. return iswalpha ((wint_t) character) != 0;
  74. }
  75. bool CharacterFunctions::isLetterOrDigit (const char character) noexcept
  76. {
  77. return (character >= 'a' && character <= 'z')
  78. || (character >= 'A' && character <= 'Z')
  79. || (character >= '0' && character <= '9');
  80. }
  81. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) noexcept
  82. {
  83. return iswalnum ((wint_t) character) != 0;
  84. }
  85. bool CharacterFunctions::isPrintable (const char character) noexcept
  86. {
  87. return (character >= ' ' && character <= '~');
  88. }
  89. bool CharacterFunctions::isPrintable (const juce_wchar character) noexcept
  90. {
  91. return iswprint ((wint_t) character) != 0;
  92. }
  93. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) noexcept
  94. {
  95. unsigned int d = (unsigned int) digit - '0';
  96. if (d < (unsigned int) 10)
  97. return (int) d;
  98. d += (unsigned int) ('0' - 'a');
  99. if (d < (unsigned int) 6)
  100. return (int) d + 10;
  101. d += (unsigned int) ('a' - 'A');
  102. if (d < (unsigned int) 6)
  103. return (int) d + 10;
  104. return -1;
  105. }
  106. double CharacterFunctions::mulexp10 (const double value, int exponent) noexcept
  107. {
  108. if (exponent == 0)
  109. return value;
  110. if (value == 0)
  111. return 0;
  112. const bool negative = (exponent < 0);
  113. if (negative)
  114. exponent = -exponent;
  115. double result = 1.0, power = 10.0;
  116. for (int bit = 1; exponent != 0; bit <<= 1)
  117. {
  118. if ((exponent & bit) != 0)
  119. {
  120. exponent ^= bit;
  121. result *= power;
  122. if (exponent == 0)
  123. break;
  124. }
  125. power *= power;
  126. }
  127. return negative ? (value / result) : (value * result);
  128. }
  129. juce_wchar CharacterFunctions::getUnicodeCharFromWindows1252Codepage (const uint8 c) noexcept
  130. {
  131. if (c < 0x80 || c >= 0xa0)
  132. return (juce_wchar) c;
  133. static const uint16 lookup[] = { 0x20AC, 0x0007, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
  134. 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0007, 0x017D, 0x0007,
  135. 0x0007, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  136. 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0007, 0x017E, 0x0178 };
  137. return (juce_wchar) lookup[c - 0x80];
  138. }
  139. }