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.

178 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. #include "CharacterFunctions.h"
  24. namespace water {
  25. //==============================================================================
  26. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) noexcept
  27. {
  28. return (juce_wchar) towupper ((wint_t) character);
  29. }
  30. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) noexcept
  31. {
  32. return (juce_wchar) towlower ((wint_t) character);
  33. }
  34. bool CharacterFunctions::isUpperCase (const juce_wchar character) noexcept
  35. {
  36. #ifdef CARLA_OS_WIN
  37. return iswupper ((wint_t) character) != 0;
  38. #else
  39. return toLowerCase (character) != character;
  40. #endif
  41. }
  42. bool CharacterFunctions::isLowerCase (const juce_wchar character) noexcept
  43. {
  44. #ifdef CARLA_OS_WIN
  45. return iswlower ((wint_t) character) != 0;
  46. #else
  47. return toUpperCase (character) != character;
  48. #endif
  49. }
  50. //==============================================================================
  51. bool CharacterFunctions::isWhitespace (const char character) noexcept
  52. {
  53. return character == ' ' || (character <= 13 && character >= 9);
  54. }
  55. bool CharacterFunctions::isWhitespace (const juce_wchar character) noexcept
  56. {
  57. return iswspace ((wint_t) character) != 0;
  58. }
  59. bool CharacterFunctions::isDigit (const char character) noexcept
  60. {
  61. return (character >= '0' && character <= '9');
  62. }
  63. bool CharacterFunctions::isDigit (const juce_wchar character) noexcept
  64. {
  65. return iswdigit ((wint_t) character) != 0;
  66. }
  67. bool CharacterFunctions::isLetter (const char character) noexcept
  68. {
  69. return (character >= 'a' && character <= 'z')
  70. || (character >= 'A' && character <= 'Z');
  71. }
  72. bool CharacterFunctions::isLetter (const juce_wchar character) noexcept
  73. {
  74. return iswalpha ((wint_t) character) != 0;
  75. }
  76. bool CharacterFunctions::isLetterOrDigit (const char character) noexcept
  77. {
  78. return (character >= 'a' && character <= 'z')
  79. || (character >= 'A' && character <= 'Z')
  80. || (character >= '0' && character <= '9');
  81. }
  82. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) noexcept
  83. {
  84. return iswalnum ((wint_t) character) != 0;
  85. }
  86. bool CharacterFunctions::isPrintable (const char character) noexcept
  87. {
  88. return (character >= ' ' && character <= '~');
  89. }
  90. bool CharacterFunctions::isPrintable (const juce_wchar character) noexcept
  91. {
  92. return iswprint ((wint_t) character) != 0;
  93. }
  94. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) noexcept
  95. {
  96. unsigned int d = (unsigned int) digit - '0';
  97. if (d < (unsigned int) 10)
  98. return (int) d;
  99. d += (unsigned int) ('0' - 'a');
  100. if (d < (unsigned int) 6)
  101. return (int) d + 10;
  102. d += (unsigned int) ('a' - 'A');
  103. if (d < (unsigned int) 6)
  104. return (int) d + 10;
  105. return -1;
  106. }
  107. double CharacterFunctions::mulexp10 (const double value, int exponent) noexcept
  108. {
  109. if (exponent == 0)
  110. return value;
  111. if (value == 0)
  112. return 0;
  113. const bool negative = (exponent < 0);
  114. if (negative)
  115. exponent = -exponent;
  116. double result = 1.0, power = 10.0;
  117. for (int bit = 1; exponent != 0; bit <<= 1)
  118. {
  119. if ((exponent & bit) != 0)
  120. {
  121. exponent ^= bit;
  122. result *= power;
  123. if (exponent == 0)
  124. break;
  125. }
  126. power *= power;
  127. }
  128. return negative ? (value / result) : (value * result);
  129. }
  130. juce_wchar CharacterFunctions::getUnicodeCharFromWindows1252Codepage (const uint8 c) noexcept
  131. {
  132. if (c < 0x80 || c >= 0xa0)
  133. return (juce_wchar) c;
  134. static const uint16 lookup[] = { 0x20AC, 0x0007, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
  135. 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0007, 0x017D, 0x0007,
  136. 0x0007, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  137. 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0007, 0x017E, 0x0178 };
  138. return (juce_wchar) lookup[c - 0x80];
  139. }
  140. }